Ejemplo n.º 1
0
 public function synchronizeEntities()
 {
     $entities = Tools::getValue('entities');
     if (isset($entities['common'])) {
         $this->loader->setDefaultPath();
         $this->loader->generateEntityFiles($entities['common']);
     }
     if (isset($entities['fixture'])) {
         $this->loader->setFixturesPath();
         $this->loader->generateEntityFiles($entities['fixture']);
     }
     $this->errors = $this->loader->getErrors();
     $this->loader->setDefaultPath();
 }
Ejemplo n.º 2
0
 /**
  * PROCESS : installFixtures
  * Install fixtures (E.g. demo products)
  */
 public function installFixtures($entity = null, array $data = array())
 {
     $fixtures_path = _PS_INSTALL_FIXTURES_PATH_ . 'apple/';
     $fixtures_name = 'apple';
     $zip_file = _PS_ROOT_DIR_ . '/download/fixtures.zip';
     $temp_dir = _PS_ROOT_DIR_ . '/download/fixtures/';
     // try to download fixtures if no low memory mode
     if ($entity === null) {
         if (Tools::copy('http://api.prestashop.com/fixtures/' . $data['shop_country'] . '/' . $data['shop_activity'] . '/fixtures.zip', $zip_file)) {
             Tools::deleteDirectory($temp_dir, true);
             if (Tools::ZipTest($zip_file)) {
                 if (Tools::ZipExtract($zip_file, $temp_dir)) {
                     $files = scandir($temp_dir);
                     if (count($files)) {
                         foreach ($files as $file) {
                             if (!preg_match('/^\\./', $file) && is_dir($temp_dir . $file . '/')) {
                                 $fixtures_path = $temp_dir . $file . '/';
                                 $fixtures_name = $file;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     // Load class (use fixture class if one exists, or use InstallXmlLoader)
     if (file_exists($fixtures_path . '/install.php')) {
         require_once $fixtures_path . '/install.php';
         $class = 'InstallFixtures' . Tools::toCamelCase($fixtures_name);
         if (!class_exists($class, false)) {
             $this->setError($this->language->l('Fixtures class "%s" not found', $class));
             return false;
         }
         $xml_loader = new $class();
         if (!$xml_loader instanceof InstallXmlLoader) {
             $this->setError($this->language->l('"%s" must be an instane of "InstallXmlLoader"', $class));
             return false;
         }
     } else {
         $xml_loader = new InstallXmlLoader();
     }
     // Install XML data (data/xml/ folder)
     $xml_loader->setFixturesPath($fixtures_path);
     if (isset($this->xml_loader_ids) && $this->xml_loader_ids) {
         $xml_loader->setIds($this->xml_loader_ids);
     }
     $languages = array();
     foreach (Language::getLanguages(false) as $lang) {
         $languages[$lang['id_lang']] = $lang['iso_code'];
     }
     $xml_loader->setLanguages($languages);
     if ($entity) {
         $xml_loader->populateEntity($entity);
     } else {
         $xml_loader->populateFromXmlFiles();
         Tools::deleteDirectory($temp_dir, true);
         @unlink($zip_file);
     }
     if ($errors = $xml_loader->getErrors()) {
         $this->setError($errors);
         return false;
     }
     // IDS from xmlLoader are stored in order to use them for fixtures
     $this->xml_loader_ids = $xml_loader->getIds();
     unset($xml_loader);
     // Index products in search tables
     Search::indexation(true);
     return true;
 }
Ejemplo n.º 3
0
 /**
  * @see InstallAbstractModel::display()
  */
 public function display()
 {
     // The installer SHOULD take less than 32M, but may take up to 35/36M sometimes. So 42M is a good value :)
     $low_memory = Tools::getMemoryLimit() < Tools::getOctets('42M');
     // We fill the process step used for Ajax queries
     $this->process_steps[] = array('key' => 'generateSettingsFile', 'lang' => $this->l('Create settings.inc file'));
     $this->process_steps[] = array('key' => 'installDatabase', 'lang' => $this->l('Create database tables'));
     $this->process_steps[] = array('key' => 'installDefaultData', 'lang' => $this->l('Create default shop and languages'));
     // If low memory, create subtasks for populateDatabase step (entity per entity)
     $populate_step = array('key' => 'populateDatabase', 'lang' => $this->l('Populate database tables'));
     if ($low_memory) {
         $populate_step['subtasks'] = array();
         $xml_loader = new InstallXmlLoader();
         foreach ($xml_loader->getSortedEntities() as $entity) {
             $populate_step['subtasks'][] = array('entity' => $entity);
         }
     }
     $this->process_steps[] = $populate_step;
     $this->process_steps[] = array('key' => 'configureShop', 'lang' => $this->l('Configure shop information'));
     if ($this->session->install_type == 'full') {
         // If low memory, create subtasks for installFixtures step (entity per entity)
         $fixtures_step = array('key' => 'installFixtures', 'lang' => $this->l('Install demonstration data'));
         if ($low_memory) {
             $fixtures_step['subtasks'] = array();
             $xml_loader = new InstallXmlLoader();
             $xml_loader->setFixturesPath();
             foreach ($xml_loader->getSortedEntities() as $entity) {
                 $fixtures_step['subtasks'][] = array('entity' => $entity);
             }
         }
         $this->process_steps[] = $fixtures_step;
     }
     $install_modules = array('key' => 'installModules', 'lang' => $this->l('Install modules'));
     if ($low_memory) {
         foreach ($this->model_install->getModulesList() as $module) {
             $install_modules['subtasks'][] = array('module' => $module);
         }
     }
     $this->process_steps[] = $install_modules;
     $install_modules = array('key' => 'installModulesAddons', 'lang' => $this->l('Install Addons modules'));
     $params = array('iso_lang' => $this->language->getLanguageIso(), 'iso_country' => $this->session->shop_country, 'email' => $this->session->admin_email, 'shop_url' => Tools::getHttpHost(), 'version' => _PS_INSTALL_VERSION_);
     if ($low_memory) {
         foreach ($this->model_install->getAddonsModulesList($params) as $module) {
             $install_modules['subtasks'][] = array('module' => (string) $module['name'], 'id_module' => (string) $module['id_module']);
         }
     }
     $this->process_steps[] = $install_modules;
     $this->process_steps[] = array('key' => 'installTheme', 'lang' => $this->l('Install theme'));
     $this->displayTemplate('process');
 }
Ejemplo n.º 4
0
 /**
  * PROCESS : installFixtures
  * Install fixtures (E.g. demo products)
  */
 public function installFixtures($entity = null)
 {
     // Load class (use fixture class if one exists, or use InstallXmlLoader)
     if (file_exists(_PS_INSTALL_FIXTURES_PATH_ . 'apple/install.php')) {
         require_once _PS_INSTALL_FIXTURES_PATH_ . 'apple/install.php';
         $class = 'InstallFixtures' . Tools::toCamelCase('apple');
         if (!class_exists($class, false)) {
             $this->setError($this->language->l('Fixtures class "%s" not found', $class));
             return false;
         }
         $xml_loader = new $class();
         if (!$xml_loader instanceof InstallXmlLoader) {
             $this->setError($this->language->l('"%s" must be an instane of "InstallXmlLoader"', $class));
             return false;
         }
     } else {
         $xml_loader = new InstallXmlLoader();
     }
     // Install XML data (data/xml/ folder)
     $xml_loader->setFixturesPath();
     if (isset($this->xml_loader_ids) && $this->xml_loader_ids) {
         $xml_loader->setIds($this->xml_loader_ids);
     }
     $languages = array();
     foreach (Language::getLanguages(false) as $lang) {
         $languages[$lang['id_lang']] = $lang['iso_code'];
     }
     $xml_loader->setLanguages($languages);
     if ($entity) {
         $xml_loader->populateEntity($entity);
     } else {
         $xml_loader->populateFromXmlFiles();
     }
     if ($errors = $xml_loader->getErrors()) {
         $this->setError($errors);
         return false;
     }
     // IDS from xmlLoader are stored in order to use them for fixtures
     $this->xml_loader_ids = $xml_loader->getIds();
     unset($xml_loader);
     // Index products in search tables
     Search::indexation(true);
     return true;
 }
Ejemplo n.º 5
0
 /**
  * @see InstallAbstractModel::display()
  */
 public function display()
 {
     // The installer SHOULD take less than 32M, but may take up to 35/36M sometimes. So 42M is a good value :)
     $low_memory = Tools::getMemoryLimit() < Tools::getOctets('42M');
     // We fill the process step used for Ajax queries
     $this->process_steps[] = array('key' => 'generateSettingsFile', 'lang' => $this->l('Create settings.inc file'));
     $this->process_steps[] = array('key' => 'installDatabase', 'lang' => $this->l('Create database tables'));
     $this->process_steps[] = array('key' => 'installDefaultData', 'lang' => $this->l('Create default shop and languages'));
     // If low memory, create subtasks for populateDatabase step (entity per entity)
     $populate_step = array('key' => 'populateDatabase', 'lang' => $this->l('Populate database tables'));
     if ($low_memory) {
         $populate_step['subtasks'] = array();
         $xml_loader = new InstallXmlLoader();
         foreach ($xml_loader->getSortedEntities() as $entity) {
             $populate_step['subtasks'][] = array('entity' => $entity);
         }
     }
     $this->process_steps[] = $populate_step;
     $this->process_steps[] = array('key' => 'configureShop', 'lang' => $this->l('Configure shop information'));
     $install_modules = array('key' => 'installModules', 'lang' => $this->l('Install modules'));
     if ($low_memory) {
         foreach ($this->model_install->getModulesList() as $module) {
             $install_modules['subtasks'][] = array('module' => $module);
         }
     }
     $this->process_steps[] = $install_modules;
     // Fixtures are installed only if option is selected
     if ($this->session->install_type == 'full') {
         // If low memory, create subtasks for installFixtures step (entity per entity)
         $fixtures_step = array('key' => 'installFixtures', 'lang' => $this->l('Install demonstration data'));
         if ($low_memory) {
             $fixtures_step['subtasks'] = array();
             $xml_loader = new InstallXmlLoader();
             $xml_loader->setFixturesPath();
             foreach ($xml_loader->getSortedEntities() as $entity) {
                 $fixtures_step['subtasks'][] = array('entity' => $entity);
             }
         }
         $this->process_steps[] = $fixtures_step;
     }
     $this->process_steps[] = array('key' => 'installTheme', 'lang' => $this->l('Install theme'));
     $this->displayTemplate('process');
 }
Ejemplo n.º 6
0
 /**
  * PROCESS : installFixtures
  * Install fixtures (E.g. demo products)
  */
 public function installFixtures($entity = null, array $data = array())
 {
     $fixtures_path = _PS_INSTALL_FIXTURES_PATH_ . 'fashion/';
     $fixtures_name = 'fashion';
     $zip_file = _PS_ROOT_DIR_ . '/download/fixtures.zip';
     $temp_dir = _PS_ROOT_DIR_ . '/download/fixtures/';
     // Load class (use fixture class if one exists, or use InstallXmlLoader)
     if (file_exists($fixtures_path . '/install.php')) {
         require_once $fixtures_path . '/install.php';
         $class = 'InstallFixtures' . Tools::toCamelCase($fixtures_name);
         if (!class_exists($class, false)) {
             $this->setError($this->translator->trans('Fixtures class "%class%" not found', array('%class%' => $class), 'Install'));
             return false;
         }
         $xml_loader = new $class();
         if (!$xml_loader instanceof InstallXmlLoader) {
             $this->setError($this->translator->trans('"%class%" must be an instance of "InstallXmlLoader"', array('%class%' => $class), 'Install'));
             return false;
         }
     } else {
         $xml_loader = new InstallXmlLoader();
     }
     // Install XML data (data/xml/ folder)
     $xml_loader->setFixturesPath($fixtures_path);
     if (isset($this->xml_loader_ids) && $this->xml_loader_ids) {
         $xml_loader->setIds($this->xml_loader_ids);
     }
     $languages = array();
     foreach (Language::getLanguages(false) as $lang) {
         $languages[$lang['id_lang']] = $lang['iso_code'];
     }
     $xml_loader->setLanguages($languages);
     if ($entity) {
         $xml_loader->populateEntity($entity);
     } else {
         $xml_loader->populateFromXmlFiles();
         Tools::deleteDirectory($temp_dir, true);
         @unlink($zip_file);
     }
     if ($errors = $xml_loader->getErrors()) {
         $this->setError($errors);
         return false;
     }
     // IDS from xmlLoader are stored in order to use them for fixtures
     $this->xml_loader_ids = $xml_loader->getIds();
     unset($xml_loader);
     // Index products in search tables
     Search::indexation(true);
     return true;
 }