[-] BO: Don't delete the directory of modules before upgrade them

This commit is contained in:
Rémi Gaillard
2013-04-15 11:17:17 +02:00
parent 5d3f48354b
commit 7fddcd3f38

View File

@@ -600,25 +600,14 @@ class AdminModulesControllerCore extends AdminController
foreach ($modules as $name)
{
$full_report = null;
if ($key == 'update')
{
if (ConfigurationTest::test_dir('modules/'.$name, true, $full_report))
Tools::deleteDirectory('../modules/'.$name.'/');
else
{
$module = Module::getInstanceByName(urldecode($name));
$this->errors[] = $this->l(sprintf("Module %s can't be upgraded : ", $module->displayName)).$full_report;
continue;
}
}
// If Addons module, download and unzip it before installing it
if (!file_exists('../modules/'.$name.'/'.$name.'.php'))
if (!file_exists('../modules/'.$name.'/'.$name.'.php') || $key == 'update')
{
$filesList = array(
array('type' => 'addonsNative', 'file' => Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 'loggedOnAddons' => 0),
array('type' => 'addonsBought', 'file' => Module::CACHE_FILE_CUSTOMER_MODULES_LIST, 'loggedOnAddons' => 1),
);
foreach ($filesList as $f)
if (file_exists(_PS_ROOT_DIR_.$f['file']))
{
@@ -628,12 +617,19 @@ class AdminModulesControllerCore extends AdminController
foreach ($xml->module as $modaddons)
if ($name == $modaddons->name && isset($modaddons->id) && ($this->logged_on_addons || $f['loggedOnAddons'] == 0))
{
$download_ok = false;
if ($f['loggedOnAddons'] == 0)
if (file_put_contents('../modules/'.$modaddons->name.'.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id)))))
$this->extractArchive('../modules/'.$modaddons->name.'.zip', false);
if ($f['loggedOnAddons'] == 1 && $this->logged_on_addons)
if (file_put_contents('../modules/'.$modaddons->name.'.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id), 'username_addons' => pSQL(trim($this->context->cookie->username_addons)), 'password_addons' => pSQL(trim($this->context->cookie->password_addons))))))
$this->extractArchive('../modules/'.$modaddons->name.'.zip', false);
if (file_put_contents(_PS_MODULE_DIR_.$modaddons->name.'.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id)))))
$download_ok = true;
elseif ($f['loggedOnAddons'] == 1 && $this->logged_on_addons)
if (file_put_contents(_PS_MODULE_DIR_.$modaddons->name.'.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id), 'username_addons' => pSQL(trim($this->context->cookie->username_addons)), 'password_addons' => pSQL(trim($this->context->cookie->password_addons))))))
$download_ok = true;
if (!$download_ok)
$this->errors[] = $this->l('Error on downloading the lastest version');
else
if(!$this->extractArchive(_PS_MODULE_DIR_.$modaddons->name.'.zip', false))
$this->errors[] = $this->l(sprintf("Module %s can't be upgraded: ", $module->displayName));
}
}
}