public function addOpt($opt, $desc = '', $required = false, $type = 'string') { if (array_key_exists($opt, $this->_opts)) { $interface = PS_CLI_INTERFACE::getInterface(); $interface->add_warning("option {$opt} has already been defined"); } $this->_opts[$opt] = array('description' => $desc, 'type' => $type, 'required' => $required); return $this; }
public function run() { $arguments = PS_CLI_ARGUMENTS::getArgumentsInstance(); $interface = PS_CLI_INTERFACE::getInterface(); if ($arguments->getOpt('show-status')) { $table = new Cli\Table(); $table->setHeaders(array('Key', 'Configuration', 'Value')); PS_CLI_UTILS::add_configuration_value($table, 'PS_UPGRADE_CHANNEL', 'PrestaShop upgrade Channel'); $interface->add_table($table); } else { $interface->add_content("Not implemented"); $interface->set_ret_value(1); } }
public function run() { $arguments = PS_CLI_ARGUMENTS::getArgumentsInstance(); $interface = PS_CLI_INTERFACE::getInterface(); if ($opt = $arguments->getOpt('list-categories', false)) { $this->list_categories(); $status = true; } elseif ($opt = $arguments->getOpt('list-pages', false)) { $this->list_pages(); $status = true; } elseif ($pageId = $arguments->getOpt('delete-page', false)) { $status = $this->delete_page($pageId); } elseif ($pageId = $arguments->getOpt('disable-page', false)) { $status = $this->disable_page($pageId); } elseif ($pageId = $arguments->getOpt('enable-page', false)) { $status = $this->enable_page($pageId); } elseif ($catId = $arguments->getOpt('enable-category', false)) { $status = $this->enable_category($catId); } elseif ($catId = $arguments->getOpt('disable-category', false)) { $status = $this->disable_category($catId); } elseif ($arguments->getOpt('create-category', false)) { $name = $arguments->getOpt('name', false); $parent = $arguments->getOpt('parent', false); $rewrite = $arguments->getOpt('link-rewrite', false); $description = $arguments->getOpt('description', ''); $meta_title = $arguments->getOpt('meta_title', ''); $meta_description = $arguments->getOpt('meta_description', ''); $meta_keywords = $arguments->getOpt('meta_keywords', ''); $status = $this->create_category($parent, $name, $rewrite, $description, $meta_title, $meta_description, $meta_keywords); } elseif ($catId = $arguments->getOpt('delete-category', false)) { $status = $this->delete_category($catId); } else { $arguments->show_command_usage('cms'); $interface->exit_program(1); } if ($status === true) { $interface->exit_program(0); } else { $interface->exit_program(1); } }
public static function register_plugin($pluginClass) { $configuration = self::getConfigurationInstance(); $interface = PS_CLI_INTERFACE::getInterface(); if (!class_exists($pluginClass)) { return false; } $pluginInstance = $pluginClass::getInstance(); if (is_subclass_of($pluginInstance, 'PS_CLI_Plugin')) { if ($configuration->debug) { $interface->display_line("Registering plugin {$pluginClass}"); } $configuration->_register_plugin($pluginClass, $pluginInstance); return true; } else { $interface->add_warning("Invalid load_plugin call !"); return false; } }
public function add_command(PS_CLI_Command $command, $handler) { $interface = PS_CLI_INTERFACE::getInterface(); if (is_object($handler)) { $this->_cli->command($command->name); $this->_cli->description($command->description); foreach ($command->getOpts() as $opt => $fields) { $this->_cli->opt($opt, $fields['description'], $fields['required'], $fields['type']); } foreach ($command->getArgs() as $arg => $fields) { $this->_cli->arg($arg, $fields['description'], $fields['required']); } //keep track of who handles what $this->_commands[$command->name] = $handler; return true; } else { $interface->add_warning("Could not add command {$command}\n"); return false; } }
* 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); } catch (PrestaShopDatabaseException $e) { $interface->add_exception($e); } catch (PrestaShopModuleException $e) { $interface->add_exception($e); } catch (PrestaShopPaymentException $e) { $interface->add_exception($e); }