Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 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;
     }
 }
Esempio n. 3
0
    }
    public function updateModules()
    {
    }
    public function updateThemes()
    {
    }
    protected function __construct()
    {
        $command = new PS_CLI_Command('autoupgrade', 'Manage autoupgrade plugin');
        $command->addOpt('show-status', 'Show configuration', false, 'boolean');
        //$command->register($this);
        $this->register_command($command);
    }
    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);
        }
    }
}
PS_CLI_CONFIGURE::register_plugin('PS_CLI_Autoupgrade');
Esempio n. 4
0
 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;
     }
 }
Esempio n. 5
0
    {
        $raw = Tools::file_get_contents(_PS_ROOT_DIR_ . Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST);
        $xmlModuleLists[] = @simplexml_load_string($raw, null, LIBXML_NOCDATA);
        $moduleStore = NULL;
        foreach ($xmlModuleLists as $xmlModuleList) {
            foreach ($xmlModuleList->module as $km) {
                if ($km->name != $moduleName) {
                    continue;
                }
                $moduleStore = $km;
            }
        }
        if (is_null($moduleStore)) {
            echo "Error, could not find {$moduleName} in addons store...\n";
            return false;
        }
        if (!($moduleArchive = self::_download_module_archive($moduleStore))) {
            echo "Error, could not download module\n";
            return false;
        }
        if (!Tools::ZipExtract($moduleArchive, _PS_MODULE_DIR_)) {
            echo "Could not extract {$module->name} archive\n";
            return false;
        }
        @unlink($moduleArchive);
        echo "Sucessfully downloaded module {$moduleName}\n";
        return true;
    }
}
PS_CLI_CONFIGURE::register_plugin('PS_CLI_Modules');
Esempio n. 6
0
 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();
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
                    echo "Error: Cache directory is not writeable\n";
                    return false;
                }
                CacheFs::deleteCacheDirectory();
                CacheFs::createCacheDirectories($cacheFSDepth);
                Configuration::updateValue('PS_CACHEFS_DIRECTORY_DEPTH', $cacheFSDepth);
                break;
            default:
                echo "Unknown cache type: {$cache}\n";
                return false;
        }
        $new_settings = preg_replace('/define\\(\'_PS_CACHING_SYSTEM_\', \'([a-z0-9=\\/+-_]*)\'\\);/Ui', 'define(\'_PS_CACHING_SYSTEM_\', \'' . $cache . '\');', $new_settings);
        if ($new_settings == $prev_settings) {
            echo "Cache {$cache} is already in use\n";
            return true;
        }
        if (!@copy(_PS_ROOT_DIR_ . '/config/settings.inc.php', _PS_ROOT_DIR_ . '/config/settings.old.php')) {
            echo "Error, could not backup config file\n";
            return false;
        }
        if (file_put_contents(_PS_ROOT_DIR_ . '/config/settings.inc.php', $new_settings)) {
            echo "cache {$cache} successfully activated\n";
            return true;
        } else {
            echo "Could not update config file\n";
            return false;
        }
    }
}
PS_CLI_CONFIGURE::register_plugin('PS_CLI_Ccc');
Esempio n. 9
0
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);