iaPatchApplier::process PHP Method

process() public method

public process ( $patch, $version )
    public function process($patch, $version)
    {
        if (!$this->_dbConnect()) {
            $this->_logInfo('Unable to connect to the database :database.', self::LOG_INFO, array('database' => $this->_dbConnectionParams['database']));
            return false;
        }
        if ($patch['executables']['pre']) {
            $this->_runPhpCode($patch['executables']['pre']);
        }
        if ($patch['info']['num_queries'] > 0) {
            $this->_logInfo('Starting to process SQL queries...', self::LOG_INFO);
            foreach ($patch['queries'] as $entry) {
                $this->_processQuery($entry);
            }
        }
        if ($patch['info']['num_files'] > 0) {
            $this->_logInfo('Starting to process files in :mode mode...', self::LOG_INFO, array('mode' => $this->_forceMode ? 'forced' : 'regular'));
            chdir($this->_scriptRoot);
            foreach ($patch['files'] as $entry) {
                $this->_processFile($entry);
            }
        }
        empty($patch['extras']) || $this->_processExtras($patch['extras']);
        $patchVersion = $patch['header']['major'] . '.' . $patch['header']['minor'];
        // implemented from the 4.0+
        if (version_compare($patchVersion, '4.0', '>=')) {
            if ($patch['info']['num_phrases']) {
                $this->_logInfo('Starting to process language phrases...', self::LOG_INFO);
                $this->_processPhrases($patch['phrases']);
            }
        }
        // finally, update the version num in DB
        if ($this->_dbConnectionParams['link']) {
            $sql = sprintf("UPDATE `{prefix}config` SET `value` = '%s' WHERE `name` = '%s'", $version, 'version');
            $this->_processQuery($sql, false);
        }
        if ($patch['executables']['post']) {
            $this->_runPhpCode($patch['executables']['post']);
        }
        return true;
    }

Usage Example

Example #1
0
 public static function forceUpgrade($version)
 {
     iaCore::instance()->factory('util');
     $patchUrl = iaUtil::REMOTE_TOOLS_URL . 'get/patch/%s/%s/';
     $patchUrl = sprintf($patchUrl, IA_VERSION, $version);
     $filePath = IA_TMP . 'patch.iap';
     iaUtil::downloadRemoteContent($patchUrl, $filePath);
     if ($contents = file_get_contents($filePath)) {
         require_once IA_HOME . 'install/classes/ia.patch.parser.php';
         require_once IA_HOME . 'install/classes/ia.patch.applier.php';
         try {
             $iaPatchParser = new iaPatchParser($contents);
             $patch = $iaPatchParser->patch;
             $iaPatchApplier = new iaPatchApplier(IA_HOME, array('host' => INTELLI_DBHOST . ':' . INTELLI_DBPORT, 'database' => INTELLI_DBNAME, 'user' => INTELLI_DBUSER, 'password' => INTELLI_DBPASS, 'prefix' => INTELLI_DBPREFIX), true);
             $iaPatchApplier->process($patch, $version);
             $logFile = 'upgrade-log-' . $patch['info']['version_to'] . '_' . date('d-m-y-Hi') . '.txt';
             if ($fh = fopen(IA_UPLOADS . $logFile, 'wt')) {
                 fwrite($fh, $iaPatchApplier->getLog());
                 fclose($fh);
             }
             $logParams = array('type' => 'app-forced', 'from' => IA_VERSION, 'to' => $version, 'file' => $logFile);
             $iaLog = iaCore::instance()->factory('log');
             $iaLog->write(iaLog::ACTION_UPGRADE, $logParams);
             return true;
         } catch (Exception $e) {
             return $e->getMessage();
         }
     }
     return false;
 }
All Usage Examples Of iaPatchApplier::process