// small change on fixtures installation
This commit is contained in:
1 parent
adceb5ccf5
commit
faec5a9226
4 files changed
+46
-12
No files matched your search
@@ -81,12 +81,15 @@ class InstallXmlLoader
|
|||||||
$this->img_path = _PS_INSTALL_DATA_PATH_.'img/';
|
$this->img_path = _PS_INSTALL_DATA_PATH_.'img/';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setFixturesPath()
|
public function setFixturesPath($path = null)
|
||||||
{
|
{
|
||||||
|
if ($path === null)
|
||||||
|
$path = _PS_INSTALL_FIXTURES_PATH_.'apple/';
|
||||||
|
|
||||||
$this->path_type = 'fixture';
|
$this->path_type = 'fixture';
|
||||||
$this->data_path = _PS_INSTALL_FIXTURES_PATH_.'apple/data/';
|
$this->data_path = $path.'data/';
|
||||||
$this->lang_path = _PS_INSTALL_FIXTURES_PATH_.'apple/langs/';
|
$this->lang_path = $path.'langs/';
|
||||||
$this->img_path = _PS_INSTALL_FIXTURES_PATH_.'apple/img/';
|
$this->img_path = $path.'img/';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ class InstallControllerConsoleProcess extends InstallControllerConsole
|
|||||||
$this->initializeContext();
|
$this->initializeContext();
|
||||||
|
|
||||||
$this->model_install->xml_loader_ids = $this->datas->xml_loader_ids;
|
$this->model_install->xml_loader_ids = $this->datas->xml_loader_ids;
|
||||||
$result = $this->model_install->installFixtures();
|
$result = $this->model_install->installFixtures(null, array('shop_activity' => $this->datas->shop_activity, 'shop_country' => $this->datas->shop_country));
|
||||||
$this->datas->xml_loader_ids = $this->model_install->xml_loader_ids;
|
$this->datas->xml_loader_ids = $this->model_install->xml_loader_ids;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ class InstallControllerHttpProcess extends InstallControllerHttp
|
|||||||
$this->initializeContext();
|
$this->initializeContext();
|
||||||
|
|
||||||
$this->model_install->xml_loader_ids = $this->session->xml_loader_ids;
|
$this->model_install->xml_loader_ids = $this->session->xml_loader_ids;
|
||||||
if (!$this->model_install->installFixtures(Tools::getValue('entity')) || $this->model_install->getErrors())
|
if (!$this->model_install->installFixtures(Tools::getValue('entity', null), array('shop_activity' => $this->session->shop_activity, 'shop_country' => $this->session->shop_country)) || $this->model_install->getErrors())
|
||||||
$this->ajaxJsonAnswer(false, $this->model_install->getErrors());
|
$this->ajaxJsonAnswer(false, $this->model_install->getErrors());
|
||||||
$this->session->xml_loader_ids = $this->model_install->xml_loader_ids;
|
$this->session->xml_loader_ids = $this->model_install->xml_loader_ids;
|
||||||
$this->ajaxJsonAnswer(true);
|
$this->ajaxJsonAnswer(true);
|
||||||
|
|||||||
@@ -660,13 +660,40 @@ class InstallModelInstall extends InstallAbstractModel
|
|||||||
* PROCESS : installFixtures
|
* PROCESS : installFixtures
|
||||||
* Install fixtures (E.g. demo products)
|
* Install fixtures (E.g. demo products)
|
||||||
*/
|
*/
|
||||||
public function installFixtures($entity = null)
|
public function installFixtures($entity = null, array $data = array())
|
||||||
{
|
{
|
||||||
// Load class (use fixture class if one exists, or use InstallXmlLoader)
|
$fixtures_path = _PS_INSTALL_FIXTURES_PATH_.'apple/';
|
||||||
if (file_exists(_PS_INSTALL_FIXTURES_PATH_.'apple/install.php'))
|
$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)
|
||||||
{
|
{
|
||||||
require_once _PS_INSTALL_FIXTURES_PATH_.'apple/install.php';
|
if (Tools::copy('http://api.prestashop.com/fixtures/'.$data['shop_country'].'/'.$data['shop_activity'].'/fixtures.zip', $zip_file))
|
||||||
$class = 'InstallFixtures'.Tools::toCamelCase('apple');
|
{
|
||||||
|
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))
|
if (!class_exists($class, false))
|
||||||
{
|
{
|
||||||
$this->setError($this->language->l('Fixtures class "%s" not found', $class));
|
$this->setError($this->language->l('Fixtures class "%s" not found', $class));
|
||||||
@@ -684,7 +711,7 @@ class InstallModelInstall extends InstallAbstractModel
|
|||||||
$xml_loader = new InstallXmlLoader();
|
$xml_loader = new InstallXmlLoader();
|
||||||
|
|
||||||
// Install XML data (data/xml/ folder)
|
// Install XML data (data/xml/ folder)
|
||||||
$xml_loader->setFixturesPath();
|
$xml_loader->setFixturesPath($fixtures_path);
|
||||||
if (isset($this->xml_loader_ids) && $this->xml_loader_ids)
|
if (isset($this->xml_loader_ids) && $this->xml_loader_ids)
|
||||||
$xml_loader->setIds($this->xml_loader_ids);
|
$xml_loader->setIds($this->xml_loader_ids);
|
||||||
|
|
||||||
@@ -696,7 +723,11 @@ class InstallModelInstall extends InstallAbstractModel
|
|||||||
if ($entity)
|
if ($entity)
|
||||||
$xml_loader->populateEntity($entity);
|
$xml_loader->populateEntity($entity);
|
||||||
else
|
else
|
||||||
|
{
|
||||||
$xml_loader->populateFromXmlFiles();
|
$xml_loader->populateFromXmlFiles();
|
||||||
|
Tools::deleteDirectory($temp_dir, true);
|
||||||
|
@unlink($zip_file);
|
||||||
|
}
|
||||||
|
|
||||||
if ($errors = $xml_loader->getErrors())
|
if ($errors = $xml_loader->getErrors())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user