Index: branches/5.3.x/core/install/upgrades.php =================================================================== diff -u -N -r15945 -r15956 --- branches/5.3.x/core/install/upgrades.php (.../upgrades.php) (revision 15945) +++ branches/5.3.x/core/install/upgrades.php (.../upgrades.php) (revision 15956) @@ -1,6 +1,6 @@ updateDeploymentLog(); } } + + /** + * Upgrades project deployment log. + * + * @return void + */ + protected function updateDeploymentLog() + { + $log = $this->Application->recallObject('module-deployment-log', null, array('skip_autoload' => true)); + /* @var $log kDBItem */ + + $table_name = $this->Application->getUnitConfig('mod')->getTableName(); + $structure = $this->Conn->Query('DESCRIBE ' . $table_name, 'Field'); + + if ( !isset($structure['AppliedDBRevisions']) ) { + return; + } + + $sql = 'SELECT Name, Path, AppliedDBRevisions + FROM ' . $table_name . ' + WHERE COALESCE(AppliedDBRevisions, "") <> ""'; + $modules = $this->Conn->Query($sql, 'Name'); + + foreach ( $modules as $module_name => $module_data ) { + $filename = FULL_PATH . DIRECTORY_SEPARATOR . $module_data['Path'] . 'install/project_upgrades.sql'; + + if ( !file_exists($filename) ) { + continue; + } + + $sqls = file_get_contents($filename); + preg_match_all("/# r([\d]+)([^\:]*):(.*?)(\n|$)/s", $sqls, $matches, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); + + if ( !$matches ) { + continue; + } + + $revisions = array_flip(explode(',', $module_data['AppliedDBRevisions'])); + + foreach ( $matches as $match ) { + $revision_number = $match[1][0]; + + if ( !isset($revisions[$revision_number]) ) { + continue; + } + + $log->Clear(); + $log->SetDBField('Module', $module_name); + $log->SetDBField('RevisionNumber', $revision_number); + $log->SetDBField('RevisionTitle', trim($match[3][0])); + $log->SetDBField('IPAddress', '0.0.0.0'); + $log->SetDBField('Output', 'IMPORTED'); + $log->Create(); + } + } + + $sql = 'ALTER TABLE ' . $table_name . ' DROP AppliedDBRevisions'; + $this->Conn->Query($sql); + } } \ No newline at end of file