public static function database_create_backup($skipStats = false) { $configuration = PS_CLI_CONFIGURE::getConfigurationInstance(); $backupCore = new PrestaShopBackup(); $skipStats ? $backupCore->psBackupAll = false : ($backupCore->psBackupAll = false); $backupCore->psBackupDropTable = true; if (!$backupCore->add()) { echo "Error, could not backup database\n"; return false; } if ($configuration->porcelain) { echo "{$backupCore->id}\n"; } else { echo "Successfully created database backup at {$backupCore->id}\n"; } return true; }
public static function create_category($parent, $name, $linkRewrite, $description = '', $meta_title = '', $meta_description = '', $meta_keywords = '') { $configuration = PS_CLI_CONFIGURE::getConfigurationInstance(); $category = new CMSCategory(); if (!Validate::isUnsignedId($parent)) { echo "Error, {$parent} is not a valid category ID\n"; return false; } $parentCat = new CMSCategory($parent); if (!Validate::isloadedObject($parentCat)) { echo "Error: category {$parentCat} does not exists\n"; return false; } $category->id_parent = $parent; if (!Validate::isName($name)) { echo "Error, {$name} is not a valid category name\n"; return false; } $category->name = array($configuration->lang => $name); if (!Validate::isLinkRewrite($linkRewrite)) { echo "Error, {$linkRewrite} is not a valid link rewrite\n"; return false; } $category->link_rewrite = array($configuration->lang => $linkRewrite); if (!Validate::isCleanHtml($description)) { echo "Warning, {$description} is not a valid category description\n"; $description = ''; } $category->description = array($configuration->lang => $description); if (!Validate::isGenericName($meta_title)) { echo "Warning, {$meta_title} is not a valid value for meta_title\n"; $meta_title = ''; } $category->meta_title = array($configuration->lang => $meta_title); if (!Validate::isGenericName($meta_description)) { echo "Warning, {$meta_description} is not a valid value for meta_description\n"; $meta_description = ''; } $category->meta_description = array($configuration->lang => $meta_description); if (!Validate::isGenericName($meta_keywords)) { echo "Warning, {$meta_keywords} is not a valid value for meta_keywords\n"; $meta_keywords = ''; } $category->meta_keywords = array($configuration->lang => $meta_keywords); if ($category->add()) { if ($configuration->porcelain) { echo $category->id_cms_category; } else { echo "Successfully created category {$category->id_cms_category}\n"; } return true; } else { echo "Error, could not create category {$name}\n"; return false; } }
public static function add_alias($alias, $search) { $configuration = PS_CLI_CONFIGURE::getConfigurationInstance(); if (!Validate::isValidSearch($alias)) { echo "Error, {$alias} is not a valid search string\n"; return false; } if (!Validate::isValidSearch($search)) { echo "Error, {$search} is not a valid search string\n"; return false; } $obj = new Alias(NULL, trim($alias), trim($search)); if ($obj->save()) { if ($configuration->porcelain) { echo "{$obj->id}\n"; } else { echo "Successfully added alias {$alias} => {$search}\n"; } return true; } else { echo "Error, could not add alias {$alias} => {$search} !\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(); }
private function checkXmlFields($xml_file) { $configuration = PS_CLI_CONFIGURE::getConfigurationInstance(); if (!file_exists($xml_file) || !($xml = simplexml_load_file($xml_file))) { if ($configuration->verbose) { echo "Error, cannot load xml file\n"; } return false; } if (!$xml['version'] || !$xml['name']) { return false; } foreach ($xml->variations->variation as $val) { if (!$val['name'] || !$val['directory'] || !$val['from'] || !$val['to']) { return false; } } foreach ($xml->modules->module as $val) { if (!$val['action'] || !$val['name']) { return false; } } foreach ($xml->modules->hooks->hook as $val) { if (!$val['module'] || !$val['hook'] || !$val['position']) { return false; } } return true; }
require_once PS_CLI_ROOT . '/PS_CLI/ps-cli_utils.php'; 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'; /* * 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(); //load ps core PS_CLI_UTILS::ps_cli_load_ps_core(); $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 try { $arguments->runArgCommand(); } catch (Exception $e) { $interface->add_exception($e); } catch (PrestaShopException $e) { $interface->add_exception($e);