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');
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');
$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 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');
} 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');
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');
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');
$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');
$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');
$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');
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');
$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');
$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');
* */ protected function _listModifiedFiles() { $upgrader = new Upgrader(); if (!is_object($upgrader)) { PS_CLI_Interface::error('Could not load upgrader module'); } $modifiedFiles = $upgrader->getChangedFilesList(NULL, true); $table = new Cli\Table(); $table->setHeaders(array('Category', 'File')); foreach ($modifiedFiles as $category => $filesArray) { foreach ($filesArray as $id => $file) { $table->addRow(array($category, $file)); } } $table->display(); } /* * Disable PrestaShop core load (called by hook) * */ public function disablePsCoreLoad() { echo "[DEBUG]: 1clickupgrade disable ps core load\n"; $conf = PS_CLI_Configure::getInstance(); //$conf->loadPsCore = false; } } PS_CLI_Configure::register_plugin('PS_CLI_Autoupgrade');
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');