/**
* Updates addon status
*
* @param string $addon Addon to update status for
* @param string $status Status to change to
* @param bool $show_notification Display notification if set to true
* @param bool $on_install If status was changed right after install process
* @param bool $allow_unmanaged Whether to allow change status for unmanaged addons in non-console environment
*
* @return bool|string True on success, old status ID if status was not changed
*/
function fn_update_addon_status($addon, $status, $show_notification = true, $on_install = false, $allow_unmanaged = false)
{
$old_status = db_get_field("SELECT status FROM ?:addons WHERE addon = ?s", $addon);
$new_status = $status;
$scheme = SchemesManager::getScheme($addon);
// Unmanaged addons can be enabled/disabled via console only
if ($scheme->getUnmanaged() && !($allow_unmanaged || defined('CONSOLE'))) {
return false;
}
/**
* Hook is executed before changing add-on status (i.e. before add-on enabling or disabling).
*
* @param string $addon Add-on name
* @param string $status New addon status - "A" for enabled, "D" for disabled
* @param bool $show_notification Display notification if set to true
* @param bool $on_install If status was changed right after install process
* @param bool $allow_unmanaged Whether to allow change status for unmanaged addons in non-console environment
* @param string $old_status Previous addon status - "A" for enabled, "D" for disabled
* @param \Tygh\Addons\AXmlScheme $scheme Add-on scheme
*/
fn_set_hook('update_addon_status_pre', $addon, $status, $show_notification, $on_install, $allow_unmanaged, $old_status, $scheme);
if ($old_status != $new_status) {
// Check if addon can be enabled
$conflicts = db_get_fields("SELECT addon FROM ?:addons WHERE status = 'A' AND FIND_IN_SET(?s, conflicts)", $addon);
if ($new_status == 'A' && !empty($conflicts)) {
$scheme = SchemesManager::getScheme($addon);
fn_set_notification('W', __('warning'), __('text_addon_cannot_enable', array('[addons]' => implode(', ', SchemesManager::getNames($conflicts)), '[addon_name]' => $scheme->getName())));
return $old_status;
}
fn_get_schema('settings', 'actions.functions', 'php', true);
$func = 'fn_settings_actions_addons_' . $addon;
if (function_exists($func)) {
$func($new_status, $old_status, $on_install);
}
// If status change is allowed, update it
if ($old_status != $new_status) {
if ($new_status != 'D') {
// Check that addon have conflicts
$scheme = SchemesManager::getScheme($addon);
$conflicts = db_get_field("SELECT conflicts FROM ?:addons WHERE addon = ?s", $addon);
if (!empty($conflicts)) {
$conflicts = explode(',', $conflicts);
$conflicted_addons = db_get_fields("SELECT addon FROM ?:addons WHERE addon IN (?a) AND status = 'A'", $conflicts);
if (!empty($conflicted_addons)) {
$lang_var = 'text_addon_confclicts_on_install';
if (!$on_install) {
foreach ($conflicts as $conflict) {
fn_disable_addon($conflict, $scheme->getName(), $show_notification);
}
$lang_var = 'text_addon_confclicts';
}
fn_set_notification('W', __('warning'), __($lang_var, array('[addons]' => implode(', ', SchemesManager::getNames($conflicts)), '[addon_name]' => $scheme->getName())));
// On install we cannot enable addon with conflicts automaticly
if ($on_install) {
return $old_status;
}
}
}
}
db_query("UPDATE ?:addons SET status = ?s WHERE addon = ?s", $status, $addon);
$func = 'fn_settings_actions_addons_post_' . $addon;
if (function_exists($func)) {
$func($status);
}
if ($show_notification == true) {
fn_set_notification('N', __('notice'), __('status_changed'));
}
// Enable/disable tabs for addon
ProductTabs::instance()->updateAddonTabStatus($addon, $new_status);
Registry::set('addons.' . $addon . '.status', $status);
} else {
return $old_status;
}
}
// Clean cache
fn_clear_cache();
if ($status == 'A') {
foreach (fn_get_installed_themes() as $theme_name) {
$theme = Themes::factory($theme_name);
$theme_manifest = $theme->getManifest();
// Precompile addon LESS files if the theme has been converted to CSS
if (!empty($theme_manifest['converted_to_css']) && !$theme->convertAddonToCss($addon)) {
fn_update_addon_status($addon, 'D', $show_notification, $on_install);
return $old_status;
}
}
}
/**
* Hook is executed after changing add-on status (i.e. after add-on enabling or disabling).
//.........这里部分代码省略.........
public static function import($store_data, $actualize_data = false)
{
set_time_limit(0);
ini_set('memory_limit', '1024M');
fn_define('STORE_IMPORT', true);
fn_define('DISABLE_HOOK_CACHE', true);
$log_dir = Registry::get('config.dir.store_import');
fn_mkdir($log_dir);
$logger = \Tygh\Logger::instance();
$logger->logfile = $log_dir . date('Y-m-d_H-i') . '.log';
if ($actualize_data) {
$logos = self::_backupLogos();
}
$import_classes_cascade = self::getImportClassesCascade($store_data);
$db_already_cloned = false;
Registry::set('runtime.skip_sharing_selection', true);
self::_removeTempTables();
self::_setUnavailableLangVars();
if (!$actualize_data) {
self::_uninstallAllAddons();
}
fn_set_progress('parts', count($import_classes_cascade) * 6 + 2);
$result = !empty($import_classes_cascade) ? true : false;
self::setDefaultLanguage($store_data);
$store_data['skin_name'] = self::setDefaultSkinName($store_data);
$theme_to_be_installed = db_get_field("SELECT value FROM ?:settings_vendor_values WHERE object_id = (SELECT object_id FROM ?:settings_objects WHERE name = 'theme_name')");
if (empty($theme_to_be_installed)) {
$theme_to_be_installed = db_get_field("SELECT value FROM ?:settings_objects WHERE name = 'theme_name'");
}
$style_id_to_be_installed = db_get_field("SELECT style_id FROM ?:bm_layouts WHERE is_default = '1'");
foreach ($import_classes_cascade as $class_name) {
if ($result) {
if (class_exists($class_name)) {
$obj = new $class_name($store_data);
$result = $db_already_cloned = $obj->import($db_already_cloned);
Settings::instance()->reloadSections();
} else {
$result = false;
fn_set_notification('E', __('error'), __('store_import.class_not_found'));
break;
}
} else {
fn_set_notification('E', __('error'), __('store_import.import_failed'));
break;
}
}
Registry::set('runtime.skip_sharing_selection', false);
if ($result) {
if (fn_allowed_for('ULTIMATE')) {
General::setForcedCompanyId();
}
General::setLicenseData();
//First, we should install all addons from old version in the new version that all templates, etc were installed in the new version
self::installAddons();
//Next, we should install all tabs in the upgraded database (mostly for the old version, 2.2.x)
self::installAddonsTabs();
if (fn_allowed_for('ULTIMATE')) {
General::ultProcessImages($store_data);
} else {
General::mveProcessImages($store_data);
}
General::processFiles($store_data, 'downloads');
General::processFiles($store_data, 'attachments');
General::processFiles($store_data, 'custom_files');
fn_clear_cache();
if (!$actualize_data) {
self::_removeRussianServices($store_data);
General::uninstallAddons(array('twigmo', 'searchanise', 'live_help', 'exim_store', 'webmail'));
/*
if (fn_allowed_for('ULTIMATE')) {
$company_ids = db_get_fields("SELECT company_id FROM ?:companies");
foreach ($company_ids as $company_id) {
self::_installTheme($company_id);
}
} else {
self::_installTheme();
}
*/
db_query("UPDATE ?:settings_objects SET value = '{$theme_to_be_installed}' WHERE name = 'theme_name'");
db_query("UPDATE ?:settings_vendor_values SET value = '{$theme_to_be_installed}' WHERE object_id = (SELECT object_id FROM ?:settings_objects WHERE name = 'theme_name')");
db_query("UPDATE ?:bm_layouts SET style_id = '{$style_id_to_be_installed}'");
db_query("UPDATE ?:bm_layouts SET theme_name = '{$theme_to_be_installed}'");
}
self::replaceOriginalDB($store_data, $actualize_data);
fn_install_addon('store_import', false);
fn_uninstall_addon('twigmo', false);
self::_removeTempTables();
if (defined('AJAX_REQUEST')) {
Registry::get('ajax')->assign('non_ajax_notifications', true);
Registry::get('ajax')->assign('force_redirection', fn_url('index.index'));
}
if ($actualize_data) {
self::_restoreLogos($logos);
}
fn_set_progress('step_scale', '1');
fn_set_progress('echo', __('store_import.done'), true);
return true;
}
return false;
}
/**
* Updates addon status
* @param string $addon Addon to update status for
* @param string $status Status to change to
* @param bool $show_notification Display notification if set to true
* @param bool $on_install If status was changed on after ionstall process
* @return bool|string True on success, old status ID if status was not changed
*/
function fn_update_addon_status($addon, $status, $show_notification = true, $on_install = false)
{
$old_status = db_get_field("SELECT status FROM ?:addons WHERE addon = ?s", $addon);
$new_status = $status;
$scheme = SchemesManager::getScheme($addon);
// Unmanaged addons can be enabled/disabled via console only
if ($scheme->getUnmanaged() && !defined('CONSOLE')) {
return false;
}
if ($old_status != $new_status) {
// Check if addon can be enabled
$conflicts = db_get_fields("SELECT addon FROM ?:addons WHERE status = 'A' AND FIND_IN_SET(?s, conflicts)", $addon);
if ($new_status == 'A' && !empty($conflicts)) {
$scheme = SchemesManager::getScheme($addon);
fn_set_notification('W', __('warning'), __('text_addon_cannot_enable', array('[addons]' => implode(', ', SchemesManager::getNames($conflicts)), '[addon_name]' => $scheme->getName())));
return $old_status;
}
fn_get_schema('settings', 'actions.functions', 'php', true);
$func = 'fn_settings_actions_addons_' . $addon;
if (function_exists($func)) {
$func($new_status, $old_status, $on_install);
}
// If status change is allowed, update it
if ($old_status != $new_status) {
if ($new_status != 'D') {
// Check that addon have conflicts
$scheme = SchemesManager::getScheme($addon);
$conflicts = db_get_field("SELECT conflicts FROM ?:addons WHERE addon = ?s", $addon);
if (!empty($conflicts)) {
$conflicts = explode(',', $conflicts);
$lang_var = 'text_addon_confclicts_on_install';
if (!$on_install) {
foreach ($conflicts as $conflict) {
fn_disable_addon($conflict, $scheme->getName(), $show_notification);
}
$lang_var = 'text_addon_confclicts';
}
fn_set_notification('W', __('warning'), __($lang_var, array('[addons]' => implode(', ', SchemesManager::getNames($conflicts)), '[addon_name]' => $scheme->getName())));
// On install we cannot enable addon with conflicts automaticly
if ($on_install) {
return $old_status;
}
}
}
db_query("UPDATE ?:addons SET status = ?s WHERE addon = ?s", $status, $addon);
$func = 'fn_settings_actions_addons_post_' . $addon;
if (function_exists($func)) {
$func($status);
}
if ($show_notification == true) {
fn_set_notification('N', __('notice'), __('status_changed'));
}
// Enable/disable tabs for addon
ProductTabs::instance()->updateAddonTabStatus($addon, $new_status);
Registry::set('addons.' . $addon . '.status', $status);
} else {
return $old_status;
}
}
// Clean cache
fn_clear_cache();
if ($status == 'A') {
foreach (fn_get_installed_themes() as $theme_name) {
$theme = Themes::factory($theme_name);
$theme_manifest = $theme->getManifest();
// Precompile addon LESS files if the theme has been converted to CSS
if (!empty($theme_manifest['converted_to_css']) && !$theme->convertAddonToCss($addon)) {
fn_update_addon_status($addon, 'D', $show_notification, $on_install);
return $old_status;
}
}
}
return true;
}
请发表评论