// small change on fixtures installation

This commit is contained in:
Rémi Gaillard
2013-08-05 20:33:39 +02:00
parent adceb5ccf5
commit faec5a9226
4 changed files with 47 additions and 13 deletions

View File

@@ -81,12 +81,15 @@ class InstallXmlLoader
$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->data_path = _PS_INSTALL_FIXTURES_PATH_.'apple/data/';
$this->lang_path = _PS_INSTALL_FIXTURES_PATH_.'apple/langs/';
$this->img_path = _PS_INSTALL_FIXTURES_PATH_.'apple/img/';
$this->data_path = $path.'data/';
$this->lang_path = $path.'langs/';
$this->img_path = $path.'img/';
}
/**

View File

@@ -225,7 +225,7 @@ class InstallControllerConsoleProcess extends InstallControllerConsole
$this->initializeContext();
$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;
return $result;
}
@@ -288,4 +288,4 @@ class InstallControllerConsoleProcess extends InstallControllerConsole
{
return $this->model_install->installModulesAddons();
}
}
}

View File

@@ -260,7 +260,7 @@ class InstallControllerHttpProcess extends InstallControllerHttp
$this->initializeContext();
$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->session->xml_loader_ids = $this->model_install->xml_loader_ids;
$this->ajaxJsonAnswer(true);

View File

@@ -660,13 +660,40 @@ class InstallModelInstall extends InstallAbstractModel
* PROCESS : installFixtures
* 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)
if (file_exists(_PS_INSTALL_FIXTURES_PATH_.'apple/install.php'))
$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)
{
require_once _PS_INSTALL_FIXTURES_PATH_.'apple/install.php';
$class = 'InstallFixtures'.Tools::toCamelCase('apple');
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));
@@ -684,7 +711,7 @@ class InstallModelInstall extends InstallAbstractModel
$xml_loader = new InstallXmlLoader();
// Install XML data (data/xml/ folder)
$xml_loader->setFixturesPath();
$xml_loader->setFixturesPath($fixtures_path);
if (isset($this->xml_loader_ids) && $this->xml_loader_ids)
$xml_loader->setIds($this->xml_loader_ids);
@@ -696,7 +723,11 @@ class InstallModelInstall extends InstallAbstractModel
if ($entity)
$xml_loader->populateEntity($entity);
else
{
$xml_loader->populateFromXmlFiles();
Tools::deleteDirectory($temp_dir, true);
@unlink($zip_file);
}
if ($errors = $xml_loader->getErrors())
{