public function init() { $this->type = Tools::getValue('type'); $this->loader = new InstallXmlLoader(); $languages = array(); foreach (Language::getLanguages(false) as $language) { $languages[$language['id_lang']] = $language['iso_code']; } $this->loader->setLanguages($languages); if (Tools::getValue('submit')) { $this->generateSchemas(); } elseif (Tools::getValue('synchronize')) { $this->synchronizeEntities(); } if ($this->type == 'demo') { $this->loader->setFixturesPath(); } else { $this->loader->setDefaultPath(); } $this->displayTemplate('index'); }
/** * 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; }
/** * 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; }
/** * 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; }