Changeset View
Standalone View
core/install/install_toolkit.php
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | |||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
function CheckPrerequisites($module_path, $versions, $mode) | function CheckPrerequisites($module_path, $versions, $mode) | ||||
{ | { | ||||
if ( !$versions ) { | if ( !$versions ) { | ||||
return Array (); | return Array (); | ||||
} | } | ||||
/** @var InPortalPrerequisites $prerequisite_object */ | |||||
$prerequisite_object =& $this->getPrerequisiteObject($module_path); | $prerequisite_object =& $this->getPrerequisiteObject($module_path); | ||||
/* @var $prerequisite_object InPortalPrerequisites */ | |||||
// some errors possible | // some errors possible | ||||
return is_object($prerequisite_object) ? $prerequisite_object->CheckPrerequisites($versions, $mode) : Array (); | return is_object($prerequisite_object) ? $prerequisite_object->CheckPrerequisites($versions, $mode) : Array (); | ||||
} | } | ||||
/** | /** | ||||
* Call prerequisites method | * Call prerequisites method | ||||
* | * | ||||
* @param string $module_path | * @param string $module_path | ||||
* @param string $method | * @param string $method | ||||
* @return array | * @return array | ||||
*/ | */ | ||||
function CallPrerequisitesMethod($module_path, $method) | function CallPrerequisitesMethod($module_path, $method) | ||||
{ | { | ||||
/** @var InPortalPrerequisites $prerequisite_object */ | |||||
$prerequisite_object =& $this->getPrerequisiteObject($module_path); | $prerequisite_object =& $this->getPrerequisiteObject($module_path); | ||||
/* @var $prerequisite_object InPortalPrerequisites */ | |||||
return is_object($prerequisite_object) ? $prerequisite_object->$method() : false; | return is_object($prerequisite_object) ? $prerequisite_object->$method() : false; | ||||
} | } | ||||
/** | /** | ||||
* Returns prerequisite object to be used for checks | * Returns prerequisite object to be used for checks | ||||
* | * | ||||
* @param string $module_path | * @param string $module_path | ||||
Show All 13 Lines | |||||
if ( !isset($prerequisite_classes[$module_path]) ) { | if ( !isset($prerequisite_classes[$module_path]) ) { | ||||
// save class name, because 2nd time | // save class name, because 2nd time | ||||
// (in after call $prerequisite_class variable will not be present) | // (in after call $prerequisite_class variable will not be present) | ||||
include_once $prerequisites_file; | include_once $prerequisites_file; | ||||
$prerequisite_classes[$module_path] = $prerequisite_class; | $prerequisite_classes[$module_path] = $prerequisite_class; | ||||
} | } | ||||
/** @var InPortalPrerequisites $prerequisite_object */ | |||||
$prerequisite_object = new $prerequisite_classes[$module_path](); | $prerequisite_object = new $prerequisite_classes[$module_path](); | ||||
/* @var $prerequisite_object InPortalPrerequisites */ | |||||
if ( method_exists($prerequisite_object, 'setToolkit') ) { | if ( method_exists($prerequisite_object, 'setToolkit') ) { | ||||
$prerequisite_object->setToolkit($this); | $prerequisite_object->setToolkit($this); | ||||
} | } | ||||
return $prerequisite_object; | return $prerequisite_object; | ||||
} | } | ||||
/** | /** | ||||
* Processes one license, received from server | * Processes one license, received from server | ||||
* | * | ||||
* @param string $file_data | * @param string $file_data | ||||
*/ | */ | ||||
function processLicense($file_data) | function processLicense($file_data) | ||||
{ | { | ||||
/** @var kModulesHelper $modules_helper */ | |||||
$modules_helper = $this->Application->recallObject('ModulesHelper'); | $modules_helper = $this->Application->recallObject('ModulesHelper'); | ||||
/* @var $modules_helper kModulesHelper */ | |||||
$file_data = explode('Code==:', $file_data); | $file_data = explode('Code==:', $file_data); | ||||
$file_data[0] = str_replace('In-Portal License File - do not edit!' . "\n", '', $file_data[0]); | $file_data[0] = str_replace('In-Portal License File - do not edit!' . "\n", '', $file_data[0]); | ||||
$file_data = array_map('trim', $file_data); | $file_data = array_map('trim', $file_data); | ||||
if ($modules_helper->verifyLicense($file_data[0])) { | if ($modules_helper->verifyLicense($file_data[0])) { | ||||
$this->systemConfig->set('License', 'Intechnic', $file_data[0]); | $this->systemConfig->set('License', 'Intechnic', $file_data[0]); | ||||
if (array_key_exists(1, $file_data)) { | if (array_key_exists(1, $file_data)) { | ||||
▲ Show 20 Lines • Show All 217 Lines • ▼ Show 20 Line(s) | |||||
*/ | */ | ||||
function ImportLanguage($lang_file, $upgrade = false) | function ImportLanguage($lang_file, $upgrade = false) | ||||
{ | { | ||||
$lang_file = FULL_PATH.$lang_file.'.lang'; | $lang_file = FULL_PATH.$lang_file.'.lang'; | ||||
if (!file_exists($lang_file)) { | if (!file_exists($lang_file)) { | ||||
return ; | return ; | ||||
} | } | ||||
/** @var LanguageImportHelper $language_import_helper */ | |||||
$language_import_helper = $this->Application->recallObject('LanguageImportHelper'); | $language_import_helper = $this->Application->recallObject('LanguageImportHelper'); | ||||
/* @var $language_import_helper LanguageImportHelper */ | |||||
$language_import_helper->performImport($lang_file, '|0|1|2|', '', $upgrade ? LANG_SKIP_EXISTING : LANG_OVERWRITE_EXISTING); | $language_import_helper->performImport($lang_file, '|0|1|2|', '', $upgrade ? LANG_SKIP_EXISTING : LANG_OVERWRITE_EXISTING); | ||||
} | } | ||||
/** | /** | ||||
* Converts module version in format X.Y.Z[-BN/-RCM] to signle integer | * Converts module version in format X.Y.Z[-BN/-RCM] to signle integer | ||||
* | * | ||||
* @param string $version | * @param string $version | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | |||||
else { | else { | ||||
$info_file = MODULES_PATH . '/' . $module_name . '/install/module_info.xml'; | $info_file = MODULES_PATH . '/' . $module_name . '/install/module_info.xml'; | ||||
} | } | ||||
if ( !file_exists($info_file) ) { | if ( !file_exists($info_file) ) { | ||||
return Array (); | return Array (); | ||||
} | } | ||||
$ret = Array (); | $ret = Array (); | ||||
Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
/** @var SimpleXMLElement[] $module_info */ | |||||
There must be at least 1 empty line above type comment Lint: CodingStandard.Commenting.TypeComment.EmptyLineAbove: There must be at least 1 empty line above type comment | |||||
$module_info = simplexml_load_file($info_file); | $module_info = simplexml_load_file($info_file); | ||||
if ( $module_info === false ) { | if ( $module_info === false ) { | ||||
// non-valid xml file | // non-valid xml file | ||||
return Array (); | return Array (); | ||||
} | } | ||||
foreach ($module_info as $node) { | foreach ($module_info as $node) { | ||||
/* @var $node SimpleXMLElement */ | |||||
$ret[strtolower($node->getName())] = trim($node); | $ret[strtolower($node->getName())] = trim($node); | ||||
} | } | ||||
return $ret; | return $ret; | ||||
} | } | ||||
/** | /** | ||||
* Returns nice module string to be used on install/upgrade screens | * Returns nice module string to be used on install/upgrade screens | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
* @param string $category_icon | * @param string $category_icon | ||||
* @return kDBItem | * @return kDBItem | ||||
*/ | */ | ||||
function &createModuleCategory($name, $description, $category_template = null, $category_icon = null) | function &createModuleCategory($name, $description, $category_template = null, $category_icon = null) | ||||
{ | { | ||||
static $fields = null; | static $fields = null; | ||||
if ( !isset($fields) ) { | if ( !isset($fields) ) { | ||||
/** @var kMultiLanguage $ml_formatter */ | |||||
$ml_formatter = $this->Application->recallObject('kMultiLanguage'); | $ml_formatter = $this->Application->recallObject('kMultiLanguage'); | ||||
/* @var $ml_formatter kMultiLanguage */ | |||||
$fields['name'] = $ml_formatter->LangFieldName('Name'); | $fields['name'] = $ml_formatter->LangFieldName('Name'); | ||||
$fields['description'] = $ml_formatter->LangFieldName('Description'); | $fields['description'] = $ml_formatter->LangFieldName('Description'); | ||||
} | } | ||||
/** @var kDBItem $category */ | |||||
$category = $this->Application->recallObject('c', null, Array ('skip_autoload' => true)); | $category = $this->Application->recallObject('c', null, Array ('skip_autoload' => true)); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
/* @var $category kDBItem */ | |||||
$category_fields = Array ( | $category_fields = Array ( | ||||
$fields['name'] => $name, 'Filename' => $name, 'AutomaticFilename' => 1, | $fields['name'] => $name, 'Filename' => $name, 'AutomaticFilename' => 1, | ||||
$fields['description'] => $description, 'Status' => STATUS_ACTIVE, 'Priority' => -9999, | $fields['description'] => $description, 'Status' => STATUS_ACTIVE, 'Priority' => -9999, | ||||
// prevents empty link to module category on spearate module install | // prevents empty link to module category on spearate module install | ||||
'NamedParentPath' => 'Content/' . $name, | 'NamedParentPath' => 'Content/' . $name, | ||||
); | ); | ||||
Show All 10 Lines | |||||
$category_fields['MenuIconUrl'] = $category_icon; | $category_fields['MenuIconUrl'] = $category_icon; | ||||
} | } | ||||
$category->Clear(); | $category->Clear(); | ||||
$category->SetDBFieldsFromHash($category_fields); | $category->SetDBFieldsFromHash($category_fields); | ||||
$category->Create(); | $category->Create(); | ||||
/** @var kPriorityHelper $priority_helper */ | |||||
$priority_helper = $this->Application->recallObject('PriorityHelper'); | $priority_helper = $this->Application->recallObject('PriorityHelper'); | ||||
/* @var $priority_helper kPriorityHelper */ | |||||
$event = new kEvent('c:OnListBuild'); | $event = new kEvent('c:OnListBuild'); | ||||
// ensure, that newly created category has proper value in Priority field | // ensure, that newly created category has proper value in Priority field | ||||
$priority_helper->recalculatePriorities($event, 'ParentId = ' . $category_fields['ParentId']); | $priority_helper->recalculatePriorities($event, 'ParentId = ' . $category_fields['ParentId']); | ||||
// update Priority field in object, becase "CategoriesItem::Update" method will be called | // update Priority field in object, becase "CategoriesItem::Update" method will be called | ||||
// from "kInstallToolkit::setModuleItemTemplate" and otherwise will set 0 to Priority field | // from "kInstallToolkit::setModuleItemTemplate" and otherwise will set 0 to Priority field | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
SET CustomFieldId = ' . $cf_id . ' | SET CustomFieldId = ' . $cf_id . ' | ||||
WHERE (TableName = "CustomFields") AND (LOWER(ModuleName) = "' . $module_name . '") AND (FieldName = ' . $db->qstr($cf_name) . ')'; | WHERE (TableName = "CustomFields") AND (LOWER(ModuleName) = "' . $module_name . '") AND (FieldName = ' . $db->qstr($cf_name) . ')'; | ||||
$db->Query($sql); | $db->Query($sql); | ||||
} | } | ||||
// because of configs was read only from installed before modules (in-portal), then reread configs | // because of configs was read only from installed before modules (in-portal), then reread configs | ||||
$this->Application->UnitConfigReader->scanModules(MODULES_PATH . DIRECTORY_SEPARATOR . $module_folder); | $this->Application->UnitConfigReader->scanModules(MODULES_PATH . DIRECTORY_SEPARATOR . $module_folder); | ||||
// create correct columns in CustomData table | // create correct columns in CustomData table | ||||
Inline comments must start with a capital letter Lint: CodingStandard.Commenting.InlineComment.NotCapital: Inline comments must start with a capital letter | |||||
Inline comments must end in full-stops, exclamation marks, or question marks Lint: CodingStandard.Commenting.InlineComment.InvalidEndChar: Inline comments must end in full-stops, exclamation marks, or question marks | |||||
/** @var kMultiLanguageHelper $ml_helper */ | |||||
$ml_helper = $this->Application->recallObject('kMultiLanguageHelper'); | $ml_helper = $this->Application->recallObject('kMultiLanguageHelper'); | ||||
/* @var $ml_helper kMultiLanguageHelper */ | |||||
$ml_helper->createFields($prefix . '-cdata', true); | $ml_helper->createFields($prefix . '-cdata', true); | ||||
} | } | ||||
/** | /** | ||||
* Deletes cache, useful after separate module install and installator last step | * Deletes cache, useful after separate module install and installator last step | ||||
* | * | ||||
* @param bool $refresh_permissions | * @param bool $refresh_permissions | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
function deleteCache($refresh_permissions = false) | function deleteCache($refresh_permissions = false) | ||||
{ | { | ||||
$this->Application->HandleEvent(new kEvent('adm:OnResetMemcache')); // not in DB = 100% invalidate | $this->Application->HandleEvent(new kEvent('adm:OnResetMemcache')); // not in DB = 100% invalidate | ||||
$this->Application->HandleEvent(new kEvent('adm:OnResetConfigsCache')); | $this->Application->HandleEvent(new kEvent('adm:OnResetConfigsCache')); | ||||
$this->Application->HandleEvent(new kEvent('adm:OnResetSections')); | $this->Application->HandleEvent(new kEvent('adm:OnResetSections')); | ||||
$this->Application->HandleEvent(new kEvent('c:OnResetCMSMenuCache')); | $this->Application->HandleEvent(new kEvent('c:OnResetCMSMenuCache')); | ||||
$this->Conn->Query('DELETE FROM ' . TABLE_PREFIX . 'CachedUrls'); | $this->Conn->Query('DELETE FROM ' . TABLE_PREFIX . 'CachedUrls'); | ||||
if ( $refresh_permissions ) { | if ( $refresh_permissions ) { | ||||
$rebuild_mode = $this->Application->ConfigValue('CategoryPermissionRebuildMode'); | $rebuild_mode = $this->Application->ConfigValue('CategoryPermissionRebuildMode'); | ||||
if ( $rebuild_mode == CategoryPermissionRebuild::SILENT ) { | if ( $rebuild_mode == CategoryPermissionRebuild::SILENT ) { | ||||
// refresh permission without progress bar | // refresh permission without progress bar | ||||
Inline comments must start with a capital letter Lint: CodingStandard.Commenting.InlineComment.NotCapital: Inline comments must start with a capital letter | |||||
Inline comments must end in full-stops, exclamation marks, or question marks Lint: CodingStandard.Commenting.InlineComment.InvalidEndChar: Inline comments must end in full-stops, exclamation marks, or question marks | |||||
/** @var kPermCacheUpdater $updater */ | |||||
$updater = $this->Application->makeClass('kPermCacheUpdater'); | $updater = $this->Application->makeClass('kPermCacheUpdater'); | ||||
/* @var $updater kPermCacheUpdater */ | |||||
$updater->OneStepRun(); | $updater->OneStepRun(); | ||||
} | } | ||||
elseif ( $rebuild_mode == CategoryPermissionRebuild::AUTOMATIC ) { | elseif ( $rebuild_mode == CategoryPermissionRebuild::AUTOMATIC ) { | ||||
// refresh permissions with ajax progress bar (when available) | // refresh permissions with ajax progress bar (when available) | ||||
$this->Application->setDBCache('ForcePermCacheUpdate', 1); | $this->Application->setDBCache('ForcePermCacheUpdate', 1); | ||||
} | } | ||||
} | } | ||||
Show All 27 Lines | |||||
function finalizeModuleInstall($module_folder, $refresh_permissions = false) | function finalizeModuleInstall($module_folder, $refresh_permissions = false) | ||||
{ | { | ||||
$this->SetModuleVersion(basename($module_folder), $module_folder); | $this->SetModuleVersion(basename($module_folder), $module_folder); | ||||
if (!$this->Application->GetVar('redirect')) { | if (!$this->Application->GetVar('redirect')) { | ||||
return ; | return ; | ||||
} | } | ||||
/** @var kThemesHelper $themes_helper */ | |||||
$themes_helper = $this->Application->recallObject('ThemesHelper'); | $themes_helper = $this->Application->recallObject('ThemesHelper'); | ||||
/* @var $themes_helper kThemesHelper */ | |||||
// use direct query, since module isn't yet in kApplication::ModuleInfo array | // use direct query, since module isn't yet in kApplication::ModuleInfo array | ||||
$sql = 'SELECT Name | $sql = 'SELECT Name | ||||
FROM ' . TABLE_PREFIX . 'Modules | FROM ' . TABLE_PREFIX . 'Modules | ||||
WHERE Path = ' . $this->Conn->qstr(rtrim($module_folder, '/') . '/'); | WHERE Path = ' . $this->Conn->qstr(rtrim($module_folder, '/') . '/'); | ||||
$module_name = $this->Conn->GetOne($sql); | $module_name = $this->Conn->GetOne($sql); | ||||
$themes_helper->synchronizeModule($module_name); | $themes_helper->synchronizeModule($module_name); | ||||
/** @var kMultiLanguageHelper $ml_helper */ | |||||
$ml_helper = $this->Application->recallObject('kMultiLanguageHelper'); | $ml_helper = $this->Application->recallObject('kMultiLanguageHelper'); | ||||
/* @var $ml_helper kMultiLanguageHelper */ | |||||
$ml_helper->massCreateFields(); | $ml_helper->massCreateFields(); | ||||
$this->deleteCache($refresh_permissions); | $this->deleteCache($refresh_permissions); | ||||
$url_params = Array ( | $url_params = Array ( | ||||
'pass' => 'm', 'admin' => 1, | 'pass' => 'm', 'admin' => 1, | ||||
'RefreshTree' => 1, 'index_file' => 'index.php', | 'RefreshTree' => 1, 'index_file' => 'index.php', | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
); | ); | ||||
} | } | ||||
if ( !$versions ) { | if ( !$versions ) { | ||||
// not skin changes -> quit | // not skin changes -> quit | ||||
return true; | return true; | ||||
} | } | ||||
/** @var kDBItem $primary_skin */ | |||||
$primary_skin = $this->Application->recallObject('skin.primary', null, Array ('skip_autoload' => true)); | $primary_skin = $this->Application->recallObject('skin.primary', null, Array ('skip_autoload' => true)); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
/* @var $primary_skin kDBItem */ | |||||
$primary_skin->Load(1, 'IsPrimary'); | $primary_skin->Load(1, 'IsPrimary'); | ||||
if ( !$primary_skin->isLoaded() ) { | if ( !$primary_skin->isLoaded() ) { | ||||
// we always got primary skin, but just in case | // we always got primary skin, but just in case | ||||
return false; | return false; | ||||
} | } | ||||
/** @var kTempTablesHandler $temp_handler */ | |||||
$temp_handler = $this->Application->recallObject('skin_TempHandler', 'kTempTablesHandler'); | $temp_handler = $this->Application->recallObject('skin_TempHandler', 'kTempTablesHandler'); | ||||
/* @var $temp_handler kTempTablesHandler */ | |||||
// clone current skin | // clone current skin | ||||
$cloned_ids = $temp_handler->CloneItems('skin', '', Array ($primary_skin->GetID())); | $cloned_ids = $temp_handler->CloneItems('skin', '', Array ($primary_skin->GetID())); | ||||
if ( !$cloned_ids ) { | if ( !$cloned_ids ) { | ||||
// can't clone | // can't clone | ||||
return false; | return false; | ||||
} | } | ||||
/** @var kDBItem $skin */ | |||||
$skin = $this->Application->recallObject('skin.tmp', null, Array ('skip_autoload' => true)); | $skin = $this->Application->recallObject('skin.tmp', null, Array ('skip_autoload' => true)); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
/* @var $skin kDBItem */ | |||||
$skin->Load($cloned_ids[0]); | $skin->Load($cloned_ids[0]); | ||||
// save css to temp file (for patching) | // save css to temp file (for patching) | ||||
$skin_file = tempnam('/tmp', 'skin_css_'); | $skin_file = tempnam('/tmp', 'skin_css_'); | ||||
$fp = fopen($skin_file, 'w'); | $fp = fopen($skin_file, 'w'); | ||||
fwrite($fp, str_replace("\r\n", "\n", $skin->GetDBField('CSS'))); | fwrite($fp, str_replace("\r\n", "\n", $skin->GetDBField('CSS'))); | ||||
fclose($fp); | fclose($fp); | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | |||||
foreach ($cache_handlers AS $class_prefix => $title) { | foreach ($cache_handlers AS $class_prefix => $title) { | ||||
$handler_class = $class_prefix . 'CacheHandler'; | $handler_class = $class_prefix . 'CacheHandler'; | ||||
if ( !class_exists($handler_class) ) { | if ( !class_exists($handler_class) ) { | ||||
unset($cache_handlers[$class_prefix]); | unset($cache_handlers[$class_prefix]); | ||||
} | } | ||||
else { | else { | ||||
/** @var FakeCacheHandler $handler */ | |||||
$handler = new $handler_class($cache_handler, 'localhost:11211'); | $handler = new $handler_class($cache_handler, 'localhost:11211'); | ||||
/* @var $handler FakeCacheHandler */ | |||||
if ( !$handler->isWorking() ) { | if ( !$handler->isWorking() ) { | ||||
if ( $current == $class_prefix ) { | if ( $current == $class_prefix ) { | ||||
$cache_handlers[$class_prefix] .= ' (offline)'; | $cache_handlers[$class_prefix] .= ' (offline)'; | ||||
} | } | ||||
else { | else { | ||||
unset($cache_handlers[$class_prefix]); | unset($cache_handlers[$class_prefix]); | ||||
} | } | ||||
Show All 34 Lines |
There must be no space between the Array keyword and the opening parenthesis