english/libraries/joomla/installer/installer.php
/**
	 * Method to process the updates for an item
	 *
	 * @param   JXMLElement	 $schema  The XML node to process
	 * @param   integer  	 $eid     Extension Identifier
	 *
	 * @return  boolean	Result of the operations
	 * @since   11.1
	 */
Method to process the updates for an item
@param   JXMLElement  $schema  The XML node to process
@param   integer      $eid     Extension Identifier

@return  boolean     Result of the operations
@since   11.1
Method to process the updates for an item @param JXMLElement $schema The XML node to process @param integer $eid Extension Identifier @return boolean Result of the operations @since 11 . 1
public function parseSchemaUpdates($schema, $eid)
	{
		$files = Array();
		$update_count = 0;
		if ($eid && $schema) {
			$db = JFactory::getDBO();
			$schemapaths = $schema->children();
			if (count($schemapaths)) {
				$dbDriver = strtolower($db->name);
				if ($dbDriver == 'mysqli') {
					$dbDriver = 'mysql';
				}
				$schemapath = '';
				foreach($schemapaths as $entry)
				{
					$attrs = $entry->attributes();
					if ($attrs['type'] == $dbDriver) {
						$schemapath = $entry;
						break;
					}
				}
				if (strlen($schemapath)) {
					$files = str_replace('.sql','', JFolder::files($this->getPath('extension_root') . '/' . $schemapath,'\.sql$'));
					usort($files,'version_compare');
					if (!count($files)) {
						return false;
					}
					$query = $db->getQuery(true);
					$query->select('version_id')->from('#__schemas')->where('extension_id = ' . $eid);
					$db->setQuery($query);
					$version = $db->loadResult();
					if ($version) {
						foreach($files as $file)
						{
							if (version_compare($file,$version) > 0) {
								$buffer = file_get_contents($this->getPath('extension_root') . '/' . $schemapath . '/' . $file.'.sql');
								if ($buffer === false) {
									JError::raiseWarning(1, JText::_('JLIB_INSTALLER_ERROR_SQL_READBUFFER'));
									return false;
								}
								jimport('joomla.installer.helper');
								$queries = JInstallerHelper::splitSql($buffer);
								if (count($queries) == 0) {
									continue;
								}
								foreach ($queries as $query)
								{
									$query = trim($query);
									if ($query != '' && $query{0} != '#') {
										$db->setQuery($query);
										if (!$db->query())
										{
											JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)));
											return false;
										}
										$update_count++;
									}
								}
							}
						}
					}
					$query = $db->getQuery(true);
					$query->delete()->from('#__schemas')->where('extension_id = ' . $eid);
					$db->setQuery($query);
					if ($db->Query()) {
						$query->clear();
						$query->insert('#__schemas')->set('extension_id = '. $eid)->set('version_id = '. $db->quote(end($files)));
						$db->setQuery($query);
						$db->Query();
					}
				}
			}
		}
		return $update_count;
	}
public function parseSchemaUpdates ( $ schema , $ eid ) { $ files = Array ( ) ; $ update_count = 0 ; if ( $ eid && $ schema ) { $ db = JFactory :: getDBO ( ) ; $ schemapaths = $ schema -> children ( ) ; if ( count ( $ schemapaths ) ) { $ dbDriver = strtolower ( $ db -> name ) ; if ( $ dbDriver == 'mysqli' ) { $ dbDriver = 'mysql' ; } $ schemapath = '' ; foreach ( $ schemapaths as $ entry ) { $ attrs = $ entry -> attributes ( ) ; if ( $ attrs [ 'type' ] == $ dbDriver ) { $ schemapath = $ entry ; break ; } } if ( strlen ( $ schemapath ) ) { $ files = str_replace ( '.sql' , '' , JFolder :: files ( $ this -> getPath ( 'extension_root' ) . '/' . $ schemapath , '\.sql$' ) ) ; usort ( $ files , 'version_compare' ) ; if ( ! count ( $ files ) ) { return false ; } $ query = $ db -> getQuery ( true ) ; $ query -> select ( 'version_id' ) -> from ( '#__schemas' ) -> where ( 'extension_id = ' . $ eid ) ; $ db -> setQuery ( $ query ) ; $ version = $ db -> loadResult ( ) ; if ( $ version ) { foreach ( $ files as $ file ) { if ( version_compare ( $ file , $ version ) > 0 ) { $ buffer = file_get_contents ( $ this -> getPath ( 'extension_root' ) . '/' . $ schemapath . '/' . $ file . '.sql' ) ; if ( $ buffer === false ) { JError :: raiseWarning ( 1 , JText :: _ ( 'JLIB_INSTALLER_ERROR_SQL_READBUFFER' ) ) ; return false ; } jimport ( 'joomla.installer.helper' ) ; $ queries = JInstallerHelper :: splitSql ( $ buffer ) ; if ( count ( $ queries ) == 0 ) { continue ; } foreach ( $ queries as $ query ) { $ query = trim ( $ query ) ; if ( $ query != '' && $ query { 0 } != '#' ) { $ db -> setQuery ( $ query ) ; if ( ! $ db -> query ( ) ) { JError :: raiseWarning ( 1 , JText :: sprintf ( 'JLIB_INSTALLER_ERROR_SQL_ERROR' , $ db -> stderr ( true ) ) ) ; return false ; } $ update_count ++ ; } } } } } $ query = $ db -> getQuery ( true ) ; $ query -> delete ( ) -> from ( '#__schemas' ) -> where ( 'extension_id = ' . $ eid ) ; $ db -> setQuery ( $ query ) ; if ( $ db -> Query ( ) ) { $ query -> clear ( ) ; $ query -> insert ( '#__schemas' ) -> set ( 'extension_id = ' . $ eid ) -> set ( 'version_id = ' . $ db -> quote ( end ( $ files ) ) ) ; $ db -> setQuery ( $ query ) ; $ db -> Query ( ) ; } } } } return $ update_count ; }
Method to process the updates for an item
 @param   JXMLElement  $schema  The XML node to process
 @param   integer      $eid     Extension Identifier
Method to process the updates for an item @param JXMLElement $schema The XML node to process @param integer $eid Extension Identifier
// Ensure we have an XML element and a valid extension id // we have a version! // Graceful exit and rollback if read not successful // Create an array of queries from the sql file // No queries to process // Process each query in the $queries array (split out of sql file). // Update the database