Index: branches/5.1.x/core/install/install_toolkit.php =================================================================== diff -u -r13750 -r13780 --- branches/5.1.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 13750) +++ branches/5.1.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 13780) @@ -1,6 +1,6 @@ getSystemConfig('Database', 'TablePrefix'); @@ -818,6 +818,8 @@ $this->Application->HandleEvent($event, 'adm:OnResetConfigsCache'); $this->Application->HandleEvent($event, 'c:OnResetCMSMenuCache'); + $this->Conn->Query('DELETE FROM ' . TABLE_PREFIX . 'CachedUrls'); + if ($refresh_permissions) { if ($this->Application->ConfigValue('QuickCategoryPermissionRebuild')) { // refresh permission without progress bar @@ -906,4 +908,129 @@ $permissions = fileperms($file); return $permissions & 0x0010 || $permissions & 0x0002; } + + /** + * Upgrades primary skin to the latest version + * + * @param Array $module_info + * @return string + */ + function upgradeSkin($module_info) + { + $upgrades_file = sprintf(UPGRADES_FILE, $module_info['Path'], 'css'); + $data = file_get_contents($upgrades_file); + + // get all versions with their positions in file + $versions = Array (); + preg_match_all('/(' . VERSION_MARK . ')/s', $data, $matches, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); + $from_version_int = $this->ConvertModuleVersion($module_info['FromVersion']); + + foreach ($matches as $index => $match) { + $version_int = $this->ConvertModuleVersion($match[2][0]); + + if ($version_int < $from_version_int) { + // only process versions, that were released after currently used version + continue; + } + + $start_pos = $match[0][1] + strlen($match[0][0]); + $end_pos = array_key_exists($index + 1, $matches) ? $matches[$index + 1][0][1] : mb_strlen($data); + $patch_data = str_replace("\r\n", "\n", substr($data, $start_pos, $end_pos - $start_pos)); + + $versions[] = Array ( + 'Version' => $match[2][0], + // fixes trimmed leading spaces by modern text editor + 'Data' => ltrim( str_replace("\n\n", "\n \n", $patch_data) ), + ); + } + + if (!$versions) { + // not skin changes -> quit + return ; + } + + $primary_skin =& $this->Application->recallObject('skin.primary', null, Array ('skip_autoload' => true)); + /* @var $primary_skin kDBItem */ + + $primary_skin->Load(1, 'IsPrimary'); + + if (!$primary_skin->isLoaded()) { + // we always got primary skin, but just in case + return ; + } + + $temp_handler =& $this->Application->recallObject('skin_TempHandler', 'kTempTablesHandler'); + /* @var $temp_handler kTempTablesHandler */ + + // clone current skin + $cloned_ids = $temp_handler->CloneItems('skin', '', Array ($primary_skin->GetID())); + + if (!$cloned_ids) { + // can't clone + return ; + } + + $skin =& $this->Application->recallObject('skin.tmp', null, Array ('skip_autoload' => true)); + /* @var $skin kDBItem */ + + $skin->Load( $cloned_ids[0] ); + + // save css to temp file (for patching) + $skin_file = tempnam('/tmp', 'skin_css_'); + $fp = fopen($skin_file, 'w'); + fwrite($fp, str_replace("\r\n", "\n", $skin->GetDBField('CSS'))); + fclose($fp); + + $output = Array (); + $patch_file = tempnam('/tmp', 'skin_patch_'); + + foreach ($versions as $version_info) { + // for each left version get it's patch and apply to temp file + $fp = fopen($patch_file, 'w'); + fwrite($fp, $version_info['Data']); + fclose($fp); + + $output[ $version_info['Version'] ] = shell_exec('patch ' . $skin_file . ' ' . $patch_file . ' 2>&1') . "\n"; + } + + // place temp file content into cloned skin + $skin->SetDBField('Name', 'Upgraded to ' . $module_info['ToVersion']); + $skin->SetDBField('CSS', file_get_contents($skin_file)); + $skin->Update(); + + unlink($skin_file); + unlink($patch_file); + + $has_errors = false; + + foreach ($output as $version => $version_output) { + $version_errors = trim( preg_replace("/(^|\n)(patching file .*?|Hunk #.*?\.)(\n|$)/m", '', $version_output) ); + + if ($version_errors) { + $has_errors = true; + $output[$version] = trim( preg_replace("/(^|\n)(patching file .*?)(\n|$)/m", '', $output[$version]) ); + } + else { + unset($output[$version]); + } + } + + if (!$has_errors) { + // copy patched css back to primary skin + $primary_skin->SetDBField('CSS', $skin->GetDBField('CSS')); + $primary_skin->Update(); + + // delete temporary skin record + $temp_handler->DeleteItems('skin', '', Array ($skin->GetID())); + + return true; + } + + // put clean skin from new version + $skin->SetDBField('CSS', file_get_contents(FULL_PATH . '/core/admin_templates/incs/style_template.css')); + $skin->Update(); + + // return output in case of errors + return $output; + } } \ No newline at end of file