Exemplo n.º 1
0
 public function run()
 {
     if (!class_exists('Autoupgrade')) {
         PS_CLI_Interface::error('The 1clickUpgrade module seems not installed or not active !');
     }
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     $calledCommand = $arguments->getCommand();
     if ($arguments->getOpt('show-status')) {
         $this->_show_status();
     } elseif ($arguments->getOpt('update', false)) {
         $key = $arguments->getOpt('key', NULL);
         $value = $arguments->getOpt('value', NULL);
         if (is_null($key)) {
             PS_CLI_Interface::error("You must provide --key with --update");
         }
         if (is_null($value)) {
             PS_CLI_Interface::error("You must provide --value with --update");
         }
         $this->_update_configuration($key, $value);
     } elseif ($arguments->getOpt('list-modified-files', false)) {
         $this->_listModifiedFiles();
     } elseif ($arguments->getOpt('check-version', false)) {
         $this->_isUpToDate();
     } elseif ($arguments->getOpt('upgrade-core', false)) {
         $this->_upgradeCore();
     } else {
         $arguments->show_command_usage($calledCommand);
         PS_CLI_Interface::error();
     }
 }
Exemplo n.º 2
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     $command = $arguments->getCommand();
     if ($arguments->getOpt('list-languages', false)) {
         $this->list_languages();
     } elseif ($arguments->getOpt('show-status', false)) {
         $this->show_status();
     } elseif ($id = $arguments->getOpt('enable', false)) {
         $this->enable_language($id);
     } elseif ($id = $arguments->getOpt('disable', false)) {
         $this->disable_language($id);
     } elseif ($isoCode = $arguments->getOpt('import', false)) {
         //todo: allow partial imports
         $this->import_language($isoCode, 'all', true);
     } elseif ($arguments->getOpt('update')) {
         $key = $arguments->getOpt('key', NULL);
         $value = $arguments->getOpt('value', NULL);
         if (is_null($key)) {
             $interface->error("You must provide --key with --update");
         }
         if (is_null($value)) {
             $interface->error("You must provide --value with --update");
         }
         $this->_update_configuration($key, $value);
     } else {
         $arguments->show_command_usage($command);
         $interface->error();
     }
     $interface->success();
 }
Exemplo n.º 3
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new PS_CLI_ARGUMENTS();
     }
     return self::$instance;
 }
Exemplo n.º 4
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($arguments->getOpt('show-status', false)) {
         $this->show_preferences_status();
         $status = true;
     } elseif ($arguments->getOpt('udpate', false)) {
         $key = $arguments->getOpt('key', NULL);
         $value = $arguments->getOpt('value', NULL);
         if (is_null($key)) {
             $interface->error("You must provide --key with --update");
         }
         if (is_null($value)) {
             $interface->error("You must provide --value with --update");
         }
         $this->_update_configuration($key, $value);
     } else {
         $arguments->show_command_usage('preferences');
         $interface->error();
     }
     if ($status) {
         $interface->success();
     } else {
         $interface->error();
     }
 }
Exemplo n.º 5
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     if ($arguments->getOpt('show-status', false)) {
         $this->show_status();
         $status = true;
     } else {
         $arguments->show_command_usage('product-preferences');
         exit(1);
     }
 }
Exemplo n.º 6
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($arguments->getOpt('show-status', false)) {
         $this->show_status();
         $status = true;
     } elseif ($arguments->getOpt('update', false)) {
         $key = $arguments->getOpt('key', null);
         $value = $arguments->getOpt('value', null);
         if (is_null($key)) {
             $interface->error("You must provide --key with --update");
         }
         if (is_null($value)) {
             $interface->error("You must provide --value with --update");
         }
         $this->_update_configuration($key, $value);
     } elseif ($arguments->getOpt('list-aliases', false)) {
         $this->list_aliases();
         $status = true;
     } elseif ($arguments->getOpt('add-alias', false)) {
         $alias = $arguments->getOpt('alias', NULL);
         $search = $arguments->getOpt('search', NULL);
         if (is_null($alias)) {
             echo "Error, you must specify --alias with a value\n";
             $arguments->show_command_usage('search-preferences');
             $interface->error();
         }
         if (is_null($search)) {
             echo "Error, you must specify --search with a value\n";
             $arguments->show_command_usage('search-preferences');
             $interface->error();
         }
         $status = $this->add_alias($alias, $search);
     } elseif ($aliasId = $arguments->getOpt('delete-alias', false)) {
         $status = $this->delete_alias($aliasId);
     } elseif ($aliasId = $arguments->getOpt('enable-alias', false)) {
         $status = $this->enable_alias($aliasId);
     } elseif ($aliasId = $arguments->getOpt('disable-alias', false)) {
         $status = $this->disable_alias($aliasId);
     } else {
         $arguments->show_command_usage('search-preferences');
         $interface->error();
     }
     if ($status) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 7
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     if ($arguments->getOpt('show-status', false)) {
         $this->print_order_preferences();
         $status = true;
     } else {
         $arguments->show_command_usage('order-preferences');
         exit(1);
     }
     if ($status) {
         exit(0);
     } else {
         exit(1);
     }
 }
Exemplo n.º 8
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($opt = $arguments->getOpt('list', false)) {
         $this->print_profile_list();
     } elseif ($id = $arguments->getOpt('delete', false)) {
         $status = $this->delete_profile($id);
     } elseif ($id = $arguments->getOpt('list-permissions', false)) {
         $status = $this->list_permissions($id);
     } else {
         $arguments->show_command_usage('profile');
         exit(1);
     }
     exit(0);
 }
Exemplo n.º 9
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($arguments->getOpt('check-version', false)) {
         $this->core_check_version();
     } elseif ($arguments->getOpt('list-modified-files', false)) {
         $this->core_list_changed_files();
     } elseif ($arguments->getOpt('show-info', false)) {
         $this->print_server_info();
     } elseif ($arguments->getOpt('show-version', false)) {
         $this->core_show_version();
     } else {
         $arguments->show_command_usage('core');
         exit(1);
     }
 }
Exemplo n.º 10
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     $status = null;
     if ($arguments->getOpt('list', false)) {
         $status = $this->list_customers();
     } elseif ($arguments->getOpt('anonimize', false)) {
         $status = $this->anonimize_customers();
     } else {
         $arguments->show_command_usage('customer');
         exit(1);
     }
     if ($status === false) {
         exit(1);
     }
     exit(0);
 }
Exemplo n.º 11
0
 public static function callHooks($event)
 {
     echo "callHook called\n";
     $arguments = PS_CLI_Arguments::getInstance();
     $command = $arguments->get_command_handler_class();
     if (isset(self::$_hooks[$event])) {
         foreach (self::$_hooks[$event] as $hook) {
             if (is_callable($hook[0])) {
                 //todo: try//catch ?
                 call_user_func_array($hook[0], $hook[1]);
             } else {
                 echo '[DEBUG]: uncallable hook in event ' . $event;
             }
         }
     } else {
         echo "[DEBUG]: no hooks registered for event {$event} under command {$command}\n";
     }
 }
Exemplo n.º 12
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($opt = $arguments->getOpt('list', false)) {
         $this->list_images();
     } elseif ($arguments->getOpt('show-status', false)) {
         $this->show_status();
     } elseif ($arguments->getOpt('update', false)) {
         $key = $arguments->getOpt('key', NULL);
         $value = $arguments->getOpt('value', NULL);
         if (is_null($key)) {
             $interface->error('You must provide --key with --update');
         }
         if (is_null($value)) {
             $interface->error('You must provide --value with --update');
         }
         $this->_update_configuration($key, $value);
     } elseif ($opt = $arguments->getOpt('regenerate-thumbs', false)) {
         if ($category = $arguments->getOpt('category', false)) {
             $cats = array('categories', 'manufacturers', 'suppliers', 'scenes', 'products', 'stores', 'all');
             if (!in_array($category, $cats)) {
                 $error = '--category must be ';
                 foreach ($cats as $cat) {
                     $error .= $cat . ' ';
                 }
                 $this->_show_command_usage('image', $error);
                 exit(1);
             }
         } else {
             $category = 'all';
         }
         if ($keepOld = $arguments->getOpt('keep-old-images', false)) {
             $deleteOldImages = false;
         } else {
             $deleteOldImages = true;
         }
         $this->regenerate_thumbnails($category, $deleteOldImages);
     } else {
         $arguments->show_command_usage('image');
         $interface->error();
     }
     exit(0);
 }
Exemplo n.º 13
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($arguments->getOpt('backup', false)) {
         $skipStats = $arguments->getOpt('skip-stats', false);
         $status = PS_CLI_DB::database_create_backup($skipStats);
     } elseif ($arguments->getOpt('list', false)) {
         $status = PS_CLI_DB::list_database_backups();
     } else {
         $arguments->show_command_usage('db');
         exit(1);
     }
     if ($status === false) {
         exit(1);
     } else {
         exit(0);
     }
 }
Exemplo n.º 14
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($opt = $arguments->getOpt('list', false)) {
         $this->print_theme_list();
         exit(0);
     } elseif ($opt = $arguments->getOpt('list-available', false)) {
         $this->print_available_themes();
         exit(0);
     } elseif ($theme = $arguments->getOpt('activate', false)) {
         $this->activate_theme($theme);
         exit(0);
     } elseif ($zip = $arguments->getOpt('install-zip', false)) {
         $this->install_theme_zip($zip);
     } else {
         $arguments->show_command_usage('theme');
         exit(1);
     }
 }
Exemplo n.º 15
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($opt = $arguments->getOpt('list-metas', false)) {
         $this->list_metas();
     } elseif ($arguments->getOpt('show-status', false)) {
         $this->show_status();
     } elseif ($baseUri = $arguments->getOpt('base-uri', null)) {
         if (!Validate::isUrl($baseUri)) {
             echo "Error: '{$baseUri}' is not a valid URI\n";
             exit(1);
         }
         $status = $this->update_base_uri($baseUri);
     } else {
         $arguments->show_command_usage('seo');
         exit(1);
     }
     exit(0);
 }
Exemplo n.º 16
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($arguments->getOpt('show-status', false)) {
         $this->show_status();
     } elseif ($arguments->getOpt('update', false)) {
         $key = $arguments->getOpt('option', NULL);
         $value = $arguments->getOpt('value', NULL);
         if (is_null($key)) {
             $interface->error('--option must be provided with --update');
         }
         if (is_null($value)) {
             $interface->error('--option must be provided with --value');
         }
         $this->update_configuration_value($key, $value);
     } else {
         $arguments->show_command_usage('email');
         exit(1);
     }
     exit(0);
 }
Exemplo n.º 17
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($opt = $arguments->getOpt('categories', false)) {
         $this->csv_export('categories');
     } elseif ($opt = $arguments->getOpt('products', false)) {
         $this->csv_export('products');
     } elseif ($opt = $arguments->getOpt('customers', false)) {
         $this->csv_export('customers');
     } elseif ($opt = $arguments->getOpt('manufacturers', false)) {
         $this->csv_export('manufacturers');
     } elseif ($opt = $arguments->getOpt('suppliers', false)) {
         $this->csv_export('suppliers');
     } elseif ($opt = $arguments->getOpt('orders', false)) {
         $this->csv_export('orders');
     } else {
         $arguments->show_command_usage('export');
         exit(1);
     }
     exit(0);
 }
Exemplo n.º 18
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($opt = $arguments->getOpt('list-shops', false)) {
         $this->list_shops();
         $status = true;
     } elseif ($opt = $arguments->getOpt('list-groups', false)) {
         $this->list_groups();
         $status = true;
     } elseif ($opt = $arguments->getOpt('enable-multistore', false)) {
         $this->enable_multistore();
     } elseif ($opt = $arguments->getOpt('disable-multistore', false)) {
         $this->disable_multistore();
     } elseif ($opt = $arguments->getOpt('create-group', false)) {
         $active = $arguments->getOpt('active', false);
         $shareCustomers = $arguments->getOpt('share-customers', false);
         $shareStock = $arguments->getOpt('share-stock', false);
         $shareOrders = $arguments->getOpt('share-orders', false);
         if ($name = $arguments->getOpt('name', false)) {
             if ($name == "1") {
                 echo "You must specify a name with --name option\n";
                 exit(1);
             }
         } else {
             echo "You must specify group name with --name option\n";
             exit(1);
         }
         $this->create_group($name, $shareCustomers, $shareStock, $shareOrders, $active = true);
     } else {
         $arguments->show_command_usage('multistore');
         exit(1);
     }
     if ($status) {
         exit(0);
     } else {
         exit(1);
     }
 }
Exemplo n.º 19
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($arguments->getOpt('show-status', false)) {
         $this->print_employee_options();
         $interface->success();
     } elseif ($arguments->getOpt('update', false)) {
         $key = $arguments->getOpt('key', null);
         $value = $arguments->getOpt('value', null);
         if (is_null($key)) {
             $interface->error("You must provide --key with --update");
         }
         if (is_null($value)) {
             $interface->error("You must provide --value with --update");
         }
         $this->_update_configuration_key($key, $value);
     } else {
         $arguments->show_command_usage('employee-preferences');
         $interface->error();
     }
 }
Exemplo n.º 20
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $status = NULL;
     if ($arguments->getOpt('enable', false)) {
         $successMsg = 'Maintenance mode disabled';
         $errMsg = 'Could not disable maintenance mode';
         $notChanged = 'Maintenance mode was already disabled';
         PS_CLI_UTILS::update_global_value('PS_SHOP_ENABLE', true, $successMsg, $errMsg, $notChanged);
     } elseif ($opt = $arguments->getOpt('disable', false)) {
         $successMsg = 'Maintenance mode enabled';
         $errMsg = 'Could not enable maintenance mode';
         $notChanged = 'Maintenance mode was already enabled';
         PS_CLI_UTILS::update_global_value('PS_SHOP_ENABLE', false, $successMsg, $errMsg, $notChanged);
     } else {
         $arguments->show_command_usage('shop');
         exit(1);
     }
     if ($status === false) {
         exit(1);
     }
     exit(0);
 }
Exemplo n.º 21
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     $command = $arguments->getCommand();
     $status = null;
     //TODO: check modulename was given, print a message otherwise
     // maybe add an else die smth ?
     if ($opt = $arguments->getOpt('enable', false)) {
         if ($opt === "1") {
             $arguments->show_command_usage('modules');
             $interface->error();
         }
         $status = $this->enable_module($opt);
     } elseif ($opt = $arguments->getOpt('disable', false)) {
         if ($opt === "1") {
             $arguments->show_command_usage('modules');
             $interface->error();
         }
         $status = $this->disable_module($opt);
     } elseif ($opt = $arguments->getOpt('reset', false)) {
         if ($opt === "1") {
             $arguments->show_command_usage('modules');
             $interface->error();
         }
         $status = $this->reset_module($opt);
     } elseif ($opt = $arguments->getOpt('install', false)) {
         if ($opt === "1") {
             $arguments->show_command_usage('modules');
             $interface->error();
         }
         $status = $this->install_module($opt);
     } elseif ($opt = $arguments->getOpt('uninstall', false)) {
         if ($opt === "1") {
             $arguments->show_command_usage('modules');
             $interface->error();
         }
         $status = $this->uninstall_module($opt);
     } elseif ($opt = $arguments->getOpt('list', false)) {
         $status = $this->print_module_list();
     } elseif ($arguments->getOpt('show-status', false)) {
         $this->print_module_status();
         $status = true;
     } elseif ($arguments->getOpt('update', false)) {
         $key = $arguments->getOpt('key', NULL);
         $value = $arguments->getOpt('value', NULL);
         if (is_null($key)) {
             $interface->error('You must provide --key with --update');
         }
         if (is_null($value)) {
             $interface->error('You must provide --value with --update');
         }
         $this->_update_configuration($key, $value);
     } elseif ($opt = $arguments->getOpt('upgrade', false)) {
         $status = $this->upgrade_all_modules();
     } elseif ($opt = $arguments->getOpt('upgrade-db', false)) {
         $status = $this->upgrade_all_modules_database();
     } elseif ($moduleName = $arguments->getOpt('download', false)) {
         $status = $this->download_install_module($moduleName);
     } elseif ($opt = $arguments->getOpt('enable-overrides', false)) {
         $successMsg = 'modules overrides enabled';
         $errMsg = 'modules overrides could not be enabled';
         $notChanged = 'modules overrides were already enabled';
         $status = PS_CLI_Utils::update_global_value('PS_DISABLE_OVERRIDES', true, $successMsg, $errMsg, $notChanged);
     } elseif ($opt = $arguments->getOpt('disable-overrides', false)) {
         $successMsg = 'modules overrides disabled';
         $errMsg = 'modules overrides could not be disabled';
         $notChanged = 'modules overrides were already disabled';
         $status = PS_CLI_Utils::update_global_value('PS_DISABLE_OVERRIDES', false, $successMsg, $errMsg, $notChanged);
     } elseif ($opt = $arguments->getOpt('enable-non-native', false)) {
         $successMsg = 'non native modules enabled';
         $errMsg = 'non native modules could not be enabled';
         $notChanged = 'non native modules were already enabled';
         $status = PS_CLI_Utils::update_global_value('PS_DISABLE_NON_NATIVE_MODULE', false, $successMsg, $errMsg, $notChanged);
     } elseif ($opt = $arguments->getOpt('disable-non-native', false)) {
         $successMsg = 'non native modules disabled';
         $errMsg = 'non native modules could not be disabled';
         $notChanged = 'non native modules were already disabled';
         $status = PS_CLI_Utils::update_global_value('PS_DISABLE_NON_NATIVE_MODULE', true, $successMsg, $errMsg, $notChanged);
     } elseif ($opt = $arguments->getOpt('enable-check-update', false)) {
         $successMsg = 'modules auto updates check enabled';
         $errMsg = 'modules auto updates could not be enabled';
         $notChanged = 'modules auto updates checks were already enabled';
         $status = PS_CLI_Utils::update_global_value('PRESTASTORE_LIVE', true, $successMsg, $errMsg, $notChanged);
     } elseif ($opt = $arguments->getOpt('disable-check-update', false)) {
         $successMsg = 'modules auto updates check disabled';
         $errMsg = 'modules auto updates could not be disabled';
         $notChanged = 'modules auto updates checks were already disabled';
         $status = PS_CLI_Utils::update_global_value('PRESTASTORE_LIVE', false, $successMsg, $errMsg, $notChanged);
     } else {
         $arguments->show_command_usage($command);
         $interface->error();
     }
     $interface = PS_CLI_Interface::getInterface();
     if ($status === false) {
         $interface->set_ret_val(PS_CLI_Interface::RET_ERR);
     }
     $interface->success();
 }
Exemplo n.º 22
0
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
try {
    $arguments->runArgCommand();
Exemplo n.º 23
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     $status = null;
     if ($arguments->getOpt('list', false)) {
         $status = $this->list_employees();
     } elseif ($opt = $arguments->getOpt('delete', false)) {
         if ($opt === "1") {
             $arguments->show_command_usage('employee');
             exit(1);
         }
         $status = $this->delete_employee($opt);
     } elseif ($opt = $arguments->getOpt('disable', false)) {
         if ($opt === "1") {
             $arguments->show_command_usage('employee');
             exit(1);
         }
         $status = $this->disable_employee($opt);
     } elseif ($opt = $arguments->getOpt('enable', false)) {
         if ($opt === "1") {
             $arguments->show_command_usage('employee');
             exit(1);
         }
         $status = $this->enable_employee($opt);
     } elseif ($email = $arguments->getOpt('create', false)) {
         if (!Validate::isEmail($email)) {
             echo "Error, {$email} is not a valid email address\n";
             exit(1);
         }
         $pwdError = 'You must provide a password for the employee';
         if ($password = $arguments->getOpt('password', false)) {
             if ($password === "1") {
                 $arguments->show_command_usage('employee', $pwdError);
                 exit(1);
             }
         } else {
             $arguments->show_command_usage('employee', $pwdError);
             exit(1);
         }
         $profileError = 'You must provide a profile for the Employee';
         if ($profile = $arguments->getOpt('profile', false)) {
             if (!Validate::isUnsignedInt($profile)) {
                 $arguments->show_command_usage('employee', $profileError);
                 exit(1);
             }
         } else {
             $arguments->show_command_usage('employee', $profileError);
             exit(1);
         }
         $firstnameError = 'You must specify a name with --first-name option';
         if ($firstname = $arguments->getOpt('first-name', false)) {
             if ($firstname == '') {
                 $arguments->show_command_usage('employee', $firstnameError);
                 exit(1);
             }
         } else {
             $arguments->show_command_usage('employee', $firstnameError);
             exit(1);
         }
         $lastnameError = 'You must specify a last name with --last-name option';
         if ($lastname = $arguments->getOpt('last-name', false)) {
             if ($lastname == '') {
                 $arguments->show_command_usage('employee', $lastnameError);
                 exit(1);
             }
         } else {
             $arguments->show_command_usage('employee', $lastnameError);
             exit(1);
         }
         $status = $this->add_employee($email, $password, $profile, $firstname, $lastname);
     } elseif ($email = $arguments->getOpt('edit', false)) {
         if ($email === "1") {
             echo "You must specify an email address!\n";
             $arguments->show_command_usage();
             exit(1);
         }
         if ($password = $arguments->getOpt('password', false)) {
             if ($password === "1") {
                 echo "You must specify a password with --password option\n";
                 exit(1);
             }
         } else {
             $password = NULL;
         }
         if ($profile = $arguments->getOpt('profile', false)) {
             //usual check === 1 cannot work with int values
             if (!Validate::isUnsignedInt($profile)) {
                 echo "{$profile} is not a valid profile id\n";
                 exit(1);
             }
         } else {
             $profile = NULL;
         }
         if ($firstname = $arguments->getOpt('firstname', false)) {
             if ($firstname === "1") {
                 echo "You must specify a name with --firstname option\n";
                 exit(1);
             }
         } else {
             $firstname = NULL;
         }
         if ($lastname = $arguments->getOpt('lastname', false)) {
             if ($firstname === "1") {
                 echo "You must specify a name with --lastname option\n";
                 exit(1);
             }
         } else {
             $lastname = NULL;
         }
         $res = $this->edit_employee($email, $password, $profile, $firstname, $lastname);
         if ($res) {
             echo "Employee {$email} successfully updated\n";
             exit(0);
         } else {
             echo "Error, could not update employee {$email}\n";
             exit(1);
         }
     } else {
         $arguments->show_command_usage('employee');
         exit(1);
     }
     if ($status === false) {
         exit(1);
     }
     exit(0);
 }
Exemplo n.º 24
0
 public function run()
 {
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     $interface = PS_CLI_Interface::getInterface();
     if ($arguments->getOpt('show-status', false)) {
         $this->show_status();
         $interface->success();
     } elseif ($arguments->getOpt('enable-html-minifier', false)) {
         $successMsg = 'HTML code reduction successfully enabled';
         $errMsg = 'Could not enable HTML code reduction';
         $notChanged = 'HTML code reduction was already enabled';
         $status = PS_CLI_Utils::update_global_value('PS_HTML_THEME_COMPRESSION', true, $successMsg, $errMsg, $notChanged);
     } elseif ($arguments->getOpt('disable-html-minifier', false)) {
         $successMsg = 'HTML code reduction successfully disabled';
         $errMsg = 'Could not disable HTML code reduction';
         $notChanged = 'HTML code reduction was already disabled';
         $status = PS_CLI_Utils::update_global_value('PS_HTML_THEME_COMPRESSION', false, $successMsg, $errMsg, $notChanged);
     } elseif ($arguments->getOpt('enable-js-minifier', false)) {
         $successMsg = 'JavaScript code reduction successfully enabled';
         $errMsg = 'Could not enable JavaScript code reduction';
         $notChanged = 'JavaScript code reduction was already enabled';
         $status = PS_CLI_Utils::update_global_value('PS_JS_THEME_COMPRESSION', true, $successMsg, $errMsg, $notChanged);
     } elseif ($arguments->getOpt('disable-js-minifier', false)) {
         $successMsg = 'JavaScript code reduction successfully disabled';
         $errMsg = 'Could not disable JavaScript code reduction';
         $notChanged = 'JavaScript code reduction was already disabled';
         $status = PS_CLI_Utils::update_global_value('PS_JS_THEME_COMPRESSION', false, $successMsg, $errMsg, $notChanged);
     } elseif ($opt = $arguments->getOpt('disable-cache', false)) {
         $this->disable_cache();
     } elseif ($cache = $arguments->getOpt('enable-cache', false)) {
         if ($cache == "1") {
             $cache = 'default';
         }
         switch ($cache) {
             case 'fs':
                 $cacheType = 'CacheFS';
                 break;
             case 'memcache':
                 $cacheType = 'CacheMemcache';
                 break;
             case 'xcache':
                 $cacheType = 'CacheXcache';
                 break;
             case 'apc':
                 $cacheType = 'CacheApc';
                 break;
             case 'default':
                 $cacheType = 'default';
                 break;
             default:
                 $error = 'Cache type must be fs, memcache, xcache or apc';
                 $arguments->show_command_usage('cache', $error);
                 exit(1);
         }
         if ($depth = $arguments->getOpt('cache-depth', false)) {
             if ($depth <= 0) {
                 $error = 'cache-depth must be a positive integer';
                 exit(1);
             }
         } else {
             $depth = 1;
         }
         $status = $this->enable_cache($cache, $depth);
     } elseif ($opt = $arguments->getOpt('clear-cache', false)) {
         $status = $this->clear_smarty_cache();
     } else {
         $arguments->show_command_usage('ccc');
         $interface->error();
     }
     if ($status) {
         exit(0);
     } else {
         exit(1);
     }
 }
Exemplo n.º 25
0
 public function postload_configure()
 {
     $context = Context::getContext();
     $arguments = PS_CLI_Arguments::getArgumentsInstance();
     //store PS version for later use
     $this->psVersion = _PS_VERSION_;
     // language to use
     if ($lng = $arguments->getOpt('lang', false)) {
         if (Validate::isLanguageIsoCode($lng)) {
             $this->lang = Language::getIdByIso($lng);
             $language = new Language($this->lang);
             if (validate::isLoadedObject($language)) {
                 $context->lang = $language;
             } else {
                 echo "Could not load language {$lng}\n";
                 exit(1);
             }
         } else {
             echo "Warning: {$lng} is not a valid iso code\n";
             echo "Using default lang\n";
             $this->lang = Configuration::get('PS_LANG_DEFAULT');
             $language = new Language($this->lang);
             $context->lang = $language;
         }
     } else {
         $this->lang = Configuration::get('PS_LANG_DEFAULT');
         $language = new Language($this->lang);
         if (!Validate::isLoadedObject($language)) {
             echo "Fatal error: could not load default language !\n";
             exit(1);
         }
         $context->lang = $language;
     }
     // do we set global ?
     if ($arguments->getOpt('global', false)) {
         $context->shop->id_shop_group = Shop::CONTEXT_ALL;
         Shop::setContext(Shop::CONTEXT_ALL);
         $this->global = true;
     }
     if ($opt = $arguments->getOpt('groupid', false)) {
         //Check if we have set global before as it is non sense
         if ($context->shop->id_shop_group === Shop::CONTEXT_ALL) {
             echo "You can not specify --global with --groupid !\n";
             exit(1);
         }
         if (Validate::isUnsignedInt($opt)) {
             Shop::setContext(Shop::CONTEXT_GROUP);
             $context->shop->shop_group_id = $opt;
         } else {
             echo "{$opt} is not a valid shop id\n";
             exit(1);
         }
     }
     if ($opt = $arguments->getOpt('shopid')) {
         if ($context->shop->id_shop_group === Shop::CONTEXT_ALL) {
             echo "You can not specify --shopid with --global";
             exit(1);
         }
         //todo: check if we are on group context
         self::set_current_shop_context($opt);
     }
 }