public static function getConfigurationInstance() { if (is_null(self::$_instance)) { self::$_instance = new PS_CLI_CONFIGURE(); } return self::$_instance; }
public static function core_show_version() { $version = _PS_VERSION_; $configuration = PS_CLI_Configure::getConfigurationInstance(); if ($configuration->porcelain) { echo "{$version}\n"; } else { echo "PrestaShop version is {$version}\n"; } }
public static function disable_language($isoCode) { //first get id from isocode $langId = Language::getIdByIso($isoCode); $language = new Language($langId); // make sure we got at least a language and default language is not deleted $defaultLang = Configuration::get('PS_LANG_DEFAULT'); if ($langId == $defaultLang) { echo "Error, you can not disable a language when it is the shop default lang\n"; return false; } if (Validate::isLoadedObject($language)) { $language->active = 0; $language->save(); echo "Successfully disabled language {$language->name}\n"; } else { echo "Error, could not find language with ID {$langId}\n"; return false; } } public static function delete_language($isoCode) { //todo } public static function list_available_local_xml() { //print out a table | iso_code | file.xml | } } PS_CLI_Configure::register_plugin('PS_CLI_Localization');
if ($fill_default_meta == true) { $metas = Db::getInstance()->executeS('SELECT id_meta FROM ' . _DB_PREFIX_ . 'meta'); foreach ($metas as $meta) { if (!isset($metas_xml[(int) $meta['id_meta']])) { $tmp_meta['id_meta'] = (int) $meta['id_meta']; $tmp_meta['left'] = $new_theme->default_left_column; $tmp_meta['right'] = $new_theme->default_right_column; $metas_xml[(int) $meta['id_meta']] = $tmp_meta; } } } if (!is_dir(_PS_ALL_THEMES_DIR_ . $new_theme->directory)) { if (!mkdir(_PS_ALL_THEMES_DIR_ . $new_theme->directory)) { echo "Error, could not create directory {$new_theme->directory}\n"; return false; } } $new_theme->add(); if ($new_theme->id > 0) { $new_theme->updateMetas($metas_xml); $new_theme_array[] = $new_theme; } else { echo "Error while installing theme {$new_theme->name}\n"; return false; } } return $new_theme_array; } } PS_CLI_Configure::register_plugin('PS_CLI_Themes');
if ($lang === null) { $lang = Configuration::get('PS_LANG_DEFAULT'); } $customers = Customer::getCustomers(); $table = new cli\Table(); $table->setHeaders(array('ID', 'email', 'First name', 'Last name')); foreach ($customers as $customer) { // print_r($customer); $table->addRow(array($customer['id_customer'], $customer['email'], $customer['firstname'], $customer['lastname'])); } $table->display(); } public static function anonimize_customers() { $customers = Customer::getCustomers(); foreach ($customers as $customer) { // print_r($customer); $anon_customer = new Customer($customer["id_customer"]); $anon_customer->email = md5($customer['email']) . '@example.com'; $res = $anon_customer->update(); if ($res) { echo "Successfully updated user " . $anon_customer->id . "\n"; } else { echo "Error, could not update user " . $customer['id_customer'] . "\n"; return false; } } } } PS_CLI_Configure::register_plugin('PS_CLI_Customer');
public function disablePsCoreLoad() { echo "[DEBUG]: 1clickupgrade disable ps core load\n"; $conf = PS_CLI_Configure::getInstance(); //$conf->loadPsCore = false; }
public static function upgrade_all_modules() { $configuration = PS_CLI_Configure::getConfigurationInstance(); $interface = PS_CLI_Interface::getInterface(); //types: // addonsMustHave // addonsNative // addonsBought ? // todo support for loggedOnAddons $loggedOnAddons = false; // Reload caches file_put_contents(_PS_ROOT_DIR_ . Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, Tools::addonsRequest('native')); file_put_contents(_PS_ROOT_DIR_ . Module::CACHE_FILE_MUST_HAVE_MODULES_LIST, Tools::addonsRequest('must-have')); if ($loggedOnAddons) { file_put_contents(_PS_ROOT_DIR_ . Module::CACHE_FILE_CUSTOMER_MODULES_LIST, Tools::addonsRequest('customer')); } $xmlModuleLists = array(); $raw = Tools::file_get_contents(_PS_ROOT_DIR_ . Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST); $xmlModuleLists[] = @simplexml_load_string($raw, null, LIBXML_NOCDATA); $raw = Tools::file_get_contents(_PS_ROOT_DIR_ . Module::CACHE_FILE_MUST_HAVE_MODULES_LIST); $xmlModuleLists[] = @simplexml_load_string($raw, null, LIBXML_NOCDATA); $moduleStore = array(); foreach ($xmlModuleLists as $xmlModuleList) { foreach ($xmlModuleList->module as $km) { $moduleStore[] = $km; } } $modulesOnDisk = Module::getModulesOnDisk(true); $upgradeErrors = array(); foreach ($modulesOnDisk as $module) { foreach ($moduleStore as $km) { if ($km->name != $module->name) { continue; } if (version_compare($module->version, $km->version, '<') == 0) { if ($configuration->debug) { $interface->display_line("{$module->name}: {$module->version} is equal to {$km->version}\n"); } continue; } $interface->display_line("Downloading {$module->name} archive\n"); $moduleArchive = self::_download_module_archive($km); if (!$moduleArchive) { $interface->display_line("Could not download {$module->name} update\n"); $upgradeErrors[] = "{$module->name} could not be downloaded\n"; continue; } $interface->display_line("Extracting {$module->name} archive\n"); if (!Tools::ZipExtract($moduleArchive, _PS_MODULE_DIR_)) { $interface->display_line("Could not extract {$module->name} archive\n"); $upgradeErrors[] = "{$module->name} could not be extracted\n"; continue; } // clean unlink($moduleArchive); } } $interface->display_line("Upgrading database"); self::upgrade_all_modules_database(); if (!empty($upgradeErrors)) { $interface->error('Some modules could not be upgraded'); } $interface->success('Done'); }
echo "Error, could not delete profile ID: {$profileId}\n"; return false; } } public static function list_permissions($profileId) { $configuration = PS_CLI_CONFIGURE::getConfigurationInstance(); if (!Validate::isUnsignedInt($profileId)) { echo "Error, {$profileId} is not a valid profile ID\n"; return false; } $profile = new Profile($profileId); if (!Validate::IsLoadedObject($profile)) { echo "Error, could not find a profile with ID: {$profileId}\n"; return false; } $accesses = Profile::getProfileAccesses($profileId, 'id_tab'); echo "Access rights for profile " . array_pop($profile->name) . " ({$profileId})\n"; $table = new Cli\Table(); $table->setHeaders(array('Tab', 'View', 'Add', 'Edit', 'Delete')); $allowedStr = 'X'; $deniedStr = ''; foreach ($accesses as $access) { $tab = new Tab($access['id_tab'], $configuration->lang); $table->addRow(array($tab->name, $access['view'] == 1 ? $allowedStr : $deniedStr, $access['add'] == 1 ? $allowedStr : $deniedStr, $access['edit'] == 1 ? $allowedStr : $deniedStr, $access['delete'] == 1 ? $allowedStr : $deniedStr)); } $table->display(); } } PS_CLI_Configure::register_plugin('PS_CLI_Profile');
if ($configuration->porcelain) { echo "{$backupCore->id}\n"; } else { echo "Successfully created database backup at {$backupCore->id}\n"; } return true; } public static function list_database_backups() { $dh = @opendir(PrestaShopBackup::getBackupPath()); if ($dh === false) { echo "Error, cannot read database backup directory {$dh}\n"; return false; } $table = new Cli\Table(); $table->setHeaders(array('Filename', 'Size', 'Date')); while ($file = readdir($dh)) { if (preg_match('/^([_a-zA-Z0-9\\-]*[\\d]+-[a-z\\d]+)\\.sql(\\.gz|\\.bz2)?$/', $file, $matches) == 0) { continue; } $filename = $file; $size = number_format(filesize(PrestaShopBackup::getBackupPath($file)) / 1000, 2) . ' Kb'; $date = date('Y-m-d H:i:s', (int) $matches[1]); $table->addRow(array($filename, $size, $date)); } $table->display(); return true; } } PS_CLI_Configure::register_plugin('PS_CLI_Db');
$callback = array(get_class() . '::regenerate_thumbnails', array()); $validValue = Validate::isUnsignedInt($value) && $value <= 9; break; case 'PS_IMAGE_GENERATION_METHOD': $callback = array(get_class() . '::regenerate_thumbnails', array()); $validValue = Validate::isUnsignedInt($value) && $value <= 2; break; case 'PS_PRODUCT_PICTURE_MAX_SIZE': case 'PS_PRODUCT_PICTURE_WIDTH': case 'PS_PRODUCT_PICTURE_HEIGHT': $validValue = Validate::isUnsignedInt($value); break; default: $interface->error("The configuration key '{$key}' is not handled by this plugin"); break; } if (!$validValue) { $interface->error("Invalid value '{$value}' for configuration key '{$key}'"); } if (PS_CLI_Utils::update_configuration_value($key, $value)) { if (is_array($callback)) { call_user_func_array($callback[0], $callback[1]); } $interface->success("Successfully updated configuration key '{$key}'"); } else { $interface->error("Could not update configuration key '{$key}'"); } } } PS_CLI_Configure::register_plugin('PS_CLI_Images');
$employee->id_profile = $profile; } if ($firstname != NULL) { $employee->firstname = $firstname; } if ($lastname != NULL) { $employee->lastname = $lastname; } $res = $employee->update(); if ($res) { echo "Successfully updated user {$email}\n"; return true; } else { echo "Error, could not update user {$email}\n"; return false; } } public static function get_any_superadmin_id() { $users = Employee::getEmployees(); $superadminID = NULL; foreach ($users as $user) { if ($user['id_employee'] == PS_CLI_PROFILE::_SUPERADMIN_PROFILE_ID_) { $superadminID = $user['id_employee']; } } return $superadminID; } } PS_CLI_Configure::register_plugin('PS_CLI_Employee');
require_once PS_CLI_ROOT . '/PS_CLI/ps-cli_arguments.php'; require_once PS_CLI_ROOT . '/PS_CLI/ps-cli_configure.php'; require_once PS_CLI_ROOT . '/PS_CLI/ps-cli_interface.php'; require_once PS_CLI_ROOT . '/PS_CLI/ps-cli_plugins.php'; require_once PS_CLI_ROOT . '/PS_CLI/ps-cli_command.php'; require_once PS_CLI_ROOT . '/PS_CLI/ps-cli_hooks.php'; /* * Load 3d party librairies */ //php-cli-tools require_once PS_CLI_ROOT . '/lib/php-cli-tools/load-php-cli-tools.php'; //garden-cli argument parser require_once PS_CLI_ROOT . '/lib/garden-cli/Args.php'; require_once PS_CLI_ROOT . '/lib/garden-cli/Cli.php'; require_once PS_CLI_ROOT . '/lib/garden-cli/Table.php'; $conf = PS_CLI_Configure::getConfigurationInstance(); $conf->preload_configure(); $arguments = PS_CLI_Arguments::getArgumentsInstance(); $arguments->parse_arguments(); // run before_load_ps_core hooks PS_CLI_Hooks::callHooks('before_load_ps_core'); //load ps core if ($conf->loadPsCore) { PS_CLI_UTILS::ps_cli_load_ps_core(); } else { echo "[DEBUG]: PS core not loaded\n"; } $conf->postload_configure(); $interface = PS_CLI_INTERFACE::getInterface(); // todo: create a runner and export this code in it; we'll need to create an interface instance before //find what to run
$FH = fopen('php://output', 'w'); $csvVals = array('id_supplier', 'name', 'date_add', 'date_upd', 'active', 'description', 'link_rewrite'); fputcsv($FH, $csvVals, $separator); foreach ($suppliers as $supplier) { $csvVals = array($supplier['id_supplier'], self::_csv_filter($supplier['name']), $supplier['date_add'], $supplier['date_upd'], $supplier['active'], self::_csv_filter($supplier['description']), self::_csv_filter($supplier['link_rewrite'])); fputcsv($FH, $csvVals, $separator); } } private static function _csv_export_orders() { $separator = ';'; $FH = fopen('php://output', 'w'); $csvVals = array('id_order', 'reference', 'customer_firstname', 'customer_lastname', 'customer_email', 'payment', 'module', 'current_state', 'state_name', 'total_paid', 'siret', 'ape', 'company', 'invoice_date', 'delivery_date', 'total_products', 'total_products_wt', 'total_discounts', 'total_discounts_tax_incl', 'total_discounts_tax_excl', 'total_discounts', 'total_shipping', 'total_shipping_tax_incl', 'total_shipping_tax_excl', 'total_paid_tax_incl', 'total_paid_tax_excl', 'total_paid_real', 'active', 'is_guest'); fputcsv($FH, $csvVals, $separator); $orders = Order::getOrdersWithInformations(); foreach ($orders as $order) { //print_r($order); $csvVals = array($order['id_order'], $order['reference'], self::_csv_filter($order['firstname']), self::_csv_filter($order['lastname']), $order['email'], $order['payment'], $order['module'], $order['current_state'], $order['state_name'], $order['total_paid'], $order['siret'], $order['ape'], self::_csv_filter($order['company']), $order['invoice_date'], $order['delivery_date'], $order['total_products'], $order['total_products_wt'], $order['total_discounts'], $order['total_discounts_tax_incl'], $order['total_discounts_tax_excl'], $order['total_discounts'], $order['total_shipping'], $order['total_shipping_tax_incl'], $order['total_shipping_tax_excl'], $order['total_paid_tax_incl'], $order['total_paid_tax_excl'], $order['total_paid_real'], $order['active'], $order['is_guest']); fputcsv($FH, $csvVals, $separator); } } private static function _csv_filter($content) { $content = Tools::safeOutput($content); //csv import do not like line returns $content = preg_replace('/\\n/', '', $content); return $content; } } PS_CLI_Configure::register_plugin('PS_CLI_Import');
$interface->success("Successfully updated '{$key}' configuration"); } else { $interface->error("Could not update configuration key '{$key}'"); } } public function show_status() { $table = new Cli\Table(); $table->setHeaders(array('Key', 'Configuration', 'Value')); PS_CLI_Utils::add_boolean_configuration_status($table, 'PS_STORE_DISPLAY_FOOTER', 'Display link to store locator in the footer'); PS_CLI_Utils::add_boolean_configuration_status($table, 'PS_STORE_DISPLAY_SITEMAP', 'Display link to store locator in the sitemap'); PS_CLI_Utils::add_boolean_configuration_status($table, 'PS_STORE_SIMPLIFIED', 'Show a simplified store locator'); PS_CLI_Utils::add_configuration_value($table, 'PS_STORES_CENTER_LAT', 'Default latitude'); PS_CLI_Utils::add_configuration_value($table, 'PS_STORES_CENTER_LONG', 'Default longitude'); PS_CLI_Utils::add_configuration_value($table, 'PS_SHOP_NAME', 'Shop name'); PS_CLI_Utils::add_configuration_value($table, 'PS_SHOP_EMAIL', 'Shop email'); PS_CLI_Utils::add_configuration_value($table, 'PS_SHOP_DETAILS', 'Shop details'); PS_CLI_Utils::add_configuration_value($table, 'PS_SHOP_ADDR1', 'Shop address line 1'); PS_CLI_Utils::add_configuration_value($table, 'PS_SHOP_ADDR2', 'Shop address line 2'); PS_CLI_Utils::add_configuration_value($table, 'PS_SHOP_CODE', 'Zip/postal code'); PS_CLI_Utils::add_configuration_value($table, 'PS_SHOP_CITY', 'City'); PS_CLI_Utils::add_configuration_value($table, 'PS_SHOP_COUNTRY_ID', 'Country ID'); PS_CLI_Utils::add_configuration_value($table, 'PS_SHOP_STATE_ID', 'State ID'); PS_CLI_Utils::add_configuration_value($table, 'PS_SHOP_PHONE', 'Phone number'); PS_CLI_Utils::add_configuration_value($table, 'PS_SHOP_FAX', 'Fax number'); $table->display(); return; } } PS_CLI_Configure::register_plugin('PS_CLI_Stores');
public static function add_configuration_value(Cli\Table &$table, $key, $friendlyName, $since = NULL) { $configuration = PS_CLI_Configure::getConfigurationInstance(); //if since is given and we know we're bellow, skip the value if ($since !== NULL) { if (version_compare($since, $configuration->psVersion, '>')) { return; } } $line = array($key, $friendlyName); $value = Configuration::get($key); array_push($line, $value); $table->addRow($line); }
$table->addRow(array('PS_MAIL_TYPE', "Email Type (" . Mail::TYPE_HTML . " for HTML, " . Mail::TYPE_TEXT . " for text, " . Mail::TYPE_BOTH . " for both)", $type . ' (' . $typeName . ')')); PS_CLI_UTILS::add_configuration_value($table, 'PS_MAIL_DOMAIN', 'Mail domain name'); PS_CLI_UTILS::add_configuration_value($table, 'PS_SHOP_EMAIL', 'Shop email'); //todo $mailMethod = Configuration::get('PS_MAIL_METHOD'); switch ($mailMethod) { case self::MAIL_PHP: $methodName = 'PHP mail()'; break; case self::MAIL_SMTP: $methodName = 'SMTP'; break; case self::MAIL_DISABLED: $methodName = 'Disabled'; break; default: $methodName = ''; break; } $table->addRow(array('PS_MAIL_METHOD', 'Email method (' . self::MAIL_PHP . ' for php mail(), ' . self::MAIL_SMTP . ' for smtp, ' . self::MAIL_DISABLED . ' for disabled)', $mailMethod . ' (' . $methodName . ')')); PS_CLI_UTILS::add_configuration_value($table, 'PS_MAIL_SERVER', 'Email server'); PS_CLI_UTILS::add_configuration_value($table, 'PS_MAIL_USER', 'Email user'); PS_CLI_UTILS::add_configuration_value($table, 'PS_MAIL_PASSWD', 'Email password'); PS_CLI_UTILS::add_configuration_value($table, 'PS_MAIL_SMTP_ENCRYPTION', 'SMTP encryption (off, tls or ssl)'); PS_CLI_UTILS::add_configuration_value($table, 'PS_MAIL_SMTP_PORT', 'SMTP port'); PS_CLI_UTILS::add_boolean_configuration_status($table, 'PS_LOG_EMAILS', 'Logs emails'); $table->display(); } } PS_CLI_Configure::register_plugin('PS_CLI_Email');
} else { $arguments->show_command_usage('shop'); exit(1); } if ($status === false) { exit(1); } exit(0); } public static function print_shop_list() { //function getShops($active = true, $id_shop_group = null, $get_as_list_id = false) $shopList = Shop::getShops(); print_r($shopList); $defaultShop = Configuration::get('PS_SHOP_DEFAULT'); foreach ($shopList as $shop) { echo $shop['id_shop'] . ' ' . $shop['id_shop_group'] . ' ' . $shop['name'] . ' ' . $shop['id_theme'] . ' ' . $shop['id_category'] . ' ' . $shop['domain'] . ' ' . $shop['domain_ssl'] . ' ' . $shop['uri'] . ' ' . $shop['active']; if ($shop['id_shop'] == $defaultShop) { echo " [Default Shop]"; } echo "\n"; } } public static function print_shop_list_tree() { $shopList = Shop::getTree(); print_r($shopList); } } PS_CLI_Configure::register_plugin('PS_CLI_Shop');
$isEnabled = (bool) Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE'); if ($isEnabled) { echo "Multistore feature is already enabled\n"; return true; } if (Configuration::updateValue('PS_MULTISHOP_FEATURE_ACTIVE', 1)) { echo "Multistore feature enabled\n"; return true; } else { echo "Error, could not enable multistore feature\n"; return false; } } public static function disable_multistore() { $isEnabled = (bool) Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE'); if (!$isEnabled) { echo "Multistore feature is already disabled\n"; return true; } if (Configuration::updateValue('PS_MULTISHOP_FEATURE_ACTIVE', 0)) { echo "Multistore feature disabled\n"; return true; } else { echo "Error, could not disable multistore feature\n"; return false; } } } PS_CLI_Configure::register_plugin('PS_CLI_Multistore');
$validValue = Validate::isBool($value); break; case 'PS_COOKIE_LIFETIME_FO': case 'PS_COOKIE_LIFETIME_FO': case 'PS_LIMIT_UPLOAD_FILE_VALUE': case 'PS_LIMIT_UPLOAD_IMAGE_VALUE': case 'PS_ATTACHMENT_MAXIMUM_SIZE': $validValue = Validate::isUnsignedInt($value); break; case 'PS_PRICE_ROUND_MODE': $validValue = Validate::isUnsignedInt($value) && $value <= 2; break; case 'PS_SHOP_ACTIVITY': $validValue = Validate::isUnsignedInt($value) && $value <= 20; break; default: $interface->error("The configuration key '{$key}' is not handled by this plugin"); break; } if (!$validValue) { $interface->error("'{$value}' is not a valid value for configuration key '{$key}'"); } if (PS_CLI_Utils::update_configuration_value($key, $value)) { $interface->success("Configuration key '{$key}' successfully updated"); } else { $interface->error("Could not update configuration key '{$key}'"); } } } PS_CLI_Configure::register_plugin('PS_CLI_Preferences');
public static function clear_smarty_cache() { $configuration = PS_CLI_Configure::getConfigurationInstance(); echo "Clearing cache...\n"; if ($configuration->verbose) { echo "Smarty cache "; } Tools::clearSmartyCache(); if ($configuration->verbose) { echo "[OK]\nXML cache "; } Tools::clearXMLCache(); if ($configuration->verbose) { echo "[OK]\nClearing media cache "; } Media::clearCache(); if ($configuration->verbose) { echo "[OK]\nRegenerating index "; } Tools::generateIndex(); if ($configuration->verbose) { echo "[OK]\n"; } echo "Done !\n"; return true; }
if ($alias->save()) { echo "Sucessfully enabled alias {$aliasId}\n"; return true; } else { echo "Could not enable alias {$aliasId}\n"; return false; } } public static function disable_alias($aliasId) { if (!Validate::isUnsignedId($aliasId)) { echo "Error, {$aliasId} is not a valid alias ID\n"; return false; } $alias = new Alias($aliasId); if (!$alias->active) { echo "alias {$aliasId} is already disabled\n"; return true; } $alias->active = false; if ($alias->save()) { echo "Sucessfully disabled alias {$aliasId}\n"; return true; } else { echo "Could not disable alias {$aliasId}\n"; return false; } } } PS_CLI_Configure::register_plugin('PS_CLI_Search');
switch ($key) { case 'PS_PASSWD_TIME_BACK': $validValue = Validate::isUnsignedInt($value); break; case 'PS_BO_ALLOW_EMPLOYEE_FORM_LANG': $validValue = Validate::isBool($value); break; default: $interface->error("This configuration key is not handled by this plugin"); break; } if (!$validValue) { $interface->error("'{$value}' is not a valid value for configuration key '{$key}'"); } if (PS_CLI_Utils::update_configuration_value($key, $value)) { $interface->success("Configuration key '{$key}' successfully updated"); } else { $interface->error("Could not update configuration key '{$key}'"); } } public static function print_employee_options() { $table = new Cli\Table(); $table->setHeaders(array('Key', 'Configuration', 'Value')); PS_CLI_UTILS::add_configuration_value($table, 'PS_PASSWD_TIME_BACK', 'Minimum delay for password regeneration'); PS_CLI_UTILS::add_configuration_value($table, 'PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 'Memorize last used language in forms'); $table->display(); } } PS_CLI_Configure::register_plugin('PS_CLI_EmployeePreferences');