[+] CORE : Module properly upgraded with message even if no file upgrade file exist, add 'upgrade' button

This commit is contained in:
vSchoener committed 2012-02-23 11:02:35 +00:00
1 parent e142fd12b6
commit 478049cac9
6 files changed
+121 -15

No files matched your search

+4 -1
View File
@@ -235,7 +235,10 @@ form#product, form#access_form{ background-color:#ebedf4; border:1px solid #cc
#moduleContainer .row-actions-module span { padding-right:5px;} #moduleContainer .row-actions-module span { padding-right:5px;}
#moduleContainer .row-actions-module span a { font-size:12px;} #moduleContainer .row-actions-module span a { font-size:12px;}
#moduleContainer .button.uninstalled, #moduleContainer .button.uninstalled,
#moduleContainer .button.installed { float:right; clear:both; margin-top:15px; font-size:12px;} #moduleContainer .button.installed { float:right; display: inline-block; margin-top:15px; font-size:12px;}
#moduleContainer .button.updated { margin-top:15px; display: inline-block; font-size:12px;}
#list-action-button{width:175px}
#list-action-button li{margin-left:10px;display: inline;float: left;}
/*FOOTER*/ /*FOOTER*/
@@ -56,7 +56,9 @@
{/if} {/if}
<dl class=""> <dl class="">
<dt>{l s='Version'} :</dt> <dt>{l s='Version'} :</dt>
<dd>{$module->version} {if isset($module->version_addons)}({l s='Update'} {$module->version_addons} {l s='available on PrestaShop Addons'}){/if}</dd>| <dd>{$module->version}
{if isset($module->version_addons)}({l s='Update'} {$module->version_addons} {l s='available on PrestaShop Addons'}){/if}
</dd>|
</dl> </dl>
<dl class=""> <dl class="">
<dt>{l s='Category'} :</dt> <dt>{l s='Category'} :</dt>
@@ -70,7 +72,15 @@
</div> </div>
</div> </div>
</td> </td>
<td><a {if isset($module->id) && $module->id gt 0 && !empty($module->options.uninstall_onclick)}onclick="{$module->options.uninstall_onclick}"{/if} href="{if isset($module->id) && $module->id gt 0}{$module->options.uninstall_url}{else}{$module->options.install_url}{/if}" class="button installed"><span>{if isset($module->id) && $module->id gt 0}{l s='Uninstall'}{else}{l s='Install'}{/if}</span></a></td> <td>
<ul id="list-action-button">
{if $module->id && isset($module->version_addons) && $module->version_addons}
<li>
<a href="{$module->options.update_url}" class="button updated"><span>{l s='Update it !'}</span></a></li>
{/if}
<li><a {if isset($module->id) && $module->id gt 0 && !empty($module->options.uninstall_onclick)}onclick="{$module->options.uninstall_onclick}"{/if} href="{if isset($module->id) && $module->id gt 0}{$module->options.uninstall_url}{else}{$module->options.install_url}{/if}" class="button installed"><span>{if isset($module->id) && $module->id gt 0}{l s='Uninstall'}{else}{l s='Install'}{/if}</span></a></li>
</ul>
</td>
</tr> </tr>
{/foreach} {/foreach}
</tbody> </tbody>
+45 -8
View File
@@ -307,7 +307,8 @@ abstract class ModuleCore
); );
// Need Upgrade will check and load upgrade file to the moduleCache upgrade case detail // Need Upgrade will check and load upgrade file to the moduleCache upgrade case detail
return Module::isInstalled($module_name) && Module::needUpgrade($module_name, $module_version); $ret = Module::isInstalled($module_name) && Module::needUpgrade($module_name, $module_version);
return $ret;
} }
/** /**
@@ -350,17 +351,29 @@ abstract class ModuleCore
} }
$upgrade['number_upgrade_left'] = count($upgrade['upgrade_file_left']); $upgrade['number_upgrade_left'] = count($upgrade['upgrade_file_left']);
// Update module version in DB with the last succeed upgrade // Update module version in DB with the last succeed upgrade
if ($upgrade['upgraded_to']) if ($upgrade['upgraded_to'])
Db::getInstance()->execute(' Module::upgradeModuleVersion($this->name, $upgrade['upgraded_to']);
UPDATE `'._DB_PREFIX_.'module` m
SET m.version = \''.bqSQL($upgrade['upgraded_to']).'\'
WHERE m.name = \''.bqSQL($this->name).'\'');
$this->setUpgradeMessage($upgrade); $this->setUpgradeMessage($upgrade);
return $upgrade; return $upgrade;
} }
/**
* Upgrade the registered version to a new one
*
* @static
* @param $name
* @param $version
* @return bool
*/
public static function upgradeModuleVersion($name, $version)
{
return Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'module` m
SET m.version = \''.bqSQL($version).'\'
WHERE m.name = \''.bqSQL($name).'\'');
}
/** /**
* Check if a module need to be upgraded. * Check if a module need to be upgraded.
* This method modify the module_cache adding an upgrade list file * This method modify the module_cache adding an upgrade list file
@@ -377,6 +390,7 @@ abstract class ModuleCore
WHERE m.`name` = \''.bqSQL($module_name).'\''); WHERE m.`name` = \''.bqSQL($module_name).'\'');
self::$modules_cache[$module_name]['upgrade']['upgraded_from'] = $registered_version; self::$modules_cache[$module_name]['upgrade']['upgraded_from'] = $registered_version;
Tools::alignVersionNumber($module_version, $registered_version);
// Check the version of the module with the registered one and look if any upgrade file exist // Check the version of the module with the registered one and look if any upgrade file exist
return version_compare($module_version, $registered_version, '>') return version_compare($module_version, $registered_version, '>')
&& Module::loadUpgradeVersionList($module_name, $module_version, $registered_version); && Module::loadUpgradeVersionList($module_name, $module_version, $registered_version);
@@ -388,6 +402,7 @@ abstract class ModuleCore
* *
* @static * @static
* @param $module_name * @param $module_name
* @param $module_version
* @param $registered_version * @param $registered_version
* @return bool to know directly if any files have been found * @return bool to know directly if any files have been found
*/ */
@@ -402,10 +417,12 @@ abstract class ModuleCore
{ {
// Read each file name // Read each file name
foreach ($files as $file) foreach ($files as $file)
if (!in_array($file, array('.', '..', '.svn'))) if (!in_array($file, array('.', '..', '.svn', 'index.php')))
{ {
$tab = explode('-', $file); $tab = explode('-', $file);
$file_version = basename($tab[1], '.php'); $file_version = basename($tab[1], '.php');
Tools::alignVersionNumber($file_version, $module_version);
Tools::alignVersionNumber($file_version, $registered_version);
// Compare version, if minor than actual, we need to upgrade the module // Compare version, if minor than actual, we need to upgrade the module
if (count($tab) == 2 && if (count($tab) == 2 &&
(version_compare($file_version, $module_version, '<=') && (version_compare($file_version, $module_version, '<=') &&
@@ -417,7 +434,14 @@ abstract class ModuleCore
'upgrade_function' => 'upgrade_module_'.str_replace('.', '_', $file_version)); 'upgrade_function' => 'upgrade_module_'.str_replace('.', '_', $file_version));
} }
} }
} }
// No files upgrade, then upgrade succeed
if (count($list) == 0)
{
self::$modules_cache[$module_name]['upgrade']['success'] = true;
Module::upgradeModuleVersion($module_name, $module_version);
}
// Set the list to module cache // Set the list to module cache
self::$modules_cache[$module_name]['upgrade']['upgrade_file_left'] = $list; self::$modules_cache[$module_name]['upgrade']['upgrade_file_left'] = $list;
@@ -425,6 +449,19 @@ abstract class ModuleCore
return (bool)count($list); return (bool)count($list);
} }
/**
* Return the status of the upgraded module
*
* @static
* @param $module_name
* @return bool
*/
public static function getUpgradeStatus($module_name)
{
return (isset(self::$modules_cache[$module_name]) &&
self::$modules_cache[$module_name]['upgrade']['success']);
}
/** /**
* Delete module from datable * Delete module from datable
* *
+30
View File
@@ -2191,6 +2191,36 @@ FileETag INode MTime Size
$filtered_files[] = $dir.'/'.$file; $filtered_files[] = $dir.'/'.$file;
return $filtered_files; return $filtered_files;
} }
/**
* Align 2 version with the same number of sub version
* version_compare will work better for its comparison :)
* (Means: '1.8' to '1.9.3' will change '1.8' to '1.8.0')
* @static
* @param $v1
* @param $v2
*/
public static function alignVersionNumber(&$v1, &$v2)
{
$len1 = count(explode('.', trim($v1, '.')));
$len2 = count(explode('.', trim($v2, '.')));
$len = 0;
$str = '';
if ($len1 > $len2)
{
$len = $len1 - $len2;
$str = &$v2;
}
else if ($len2 > $len1)
{
$len = $len2 - $len1;
$str = &$v1;
}
for ($len; $len > 0; $len--)
$str .= '.0';
}
} }
/** /**
+1
View File
@@ -290,6 +290,7 @@ class AdminControllerCore extends Controller
26 => $this->l('Cover selection saved'), 26 => $this->l('Cover selection saved'),
27 => $this->l('Image shop association modified'), 27 => $this->l('Image shop association modified'),
28 => $this->l('Zone affected to the selection successfully'), 28 => $this->l('Zone affected to the selection successfully'),
29 => $this->l('Upgrade succeed')
); );
if (!$this->identifier) $this->identifier = 'id_'.$this->table; if (!$this->identifier) $this->identifier = 'id_'.$this->table;
if (!$this->_defaultOrderBy) $this->_defaultOrderBy = $this->identifier; if (!$this->_defaultOrderBy) $this->_defaultOrderBy = $this->identifier;
+29 -4
View File
@@ -35,6 +35,7 @@ class AdminModulesControllerCore extends AdminController
'install' => 'install', 'install' => 'install',
'uninstall' => 'uninstall', 'uninstall' => 'uninstall',
'configure' => 'getContent', 'configure' => 'getContent',
'update' => 'update',
'delete' => 'delete' 'delete' => 'delete'
); );
@@ -585,6 +586,9 @@ class AdminModulesControllerCore extends AdminController
if ($modules) if ($modules)
foreach ($modules as $name) foreach ($modules as $name)
{ {
if ($key == 'update')
Tools::deleteDirectory('../modules/'.$name.'/');
// If Addons module, download and unzip it before installing it // If Addons module, download and unzip it before installing it
if (!is_dir('../modules/'.$name.'/')) if (!is_dir('../modules/'.$name.'/'))
{ {
@@ -624,6 +628,8 @@ class AdminModulesControllerCore extends AdminController
$this->errors[] = Tools::displayError('This module is already installed:').' '.$module->name; $this->errors[] = Tools::displayError('This module is already installed:').' '.$module->name;
elseif ($key == 'uninstall' && !Module::isInstalled($module->name)) elseif ($key == 'uninstall' && !Module::isInstalled($module->name))
$this->errors[] = Tools::displayError('This module is already uninstalled:').' '.$module->name; $this->errors[] = Tools::displayError('This module is already uninstalled:').' '.$module->name;
else if ($key == 'update' && !Module::isInstalled($module->name))
$this->errors[] = Tools::displayError('This module need to be installed to be updated:').' '.$module->name;
else else
{ {
// If we install a module, force temporary global context for multishop // If we install a module, force temporary global context for multishop
@@ -643,12 +649,16 @@ class AdminModulesControllerCore extends AdminController
if (Tools::getValue('controller') != '') if (Tools::getValue('controller') != '')
$_POST['tab'] = Tools::safeOutput(Tools::getValue('controller')); $_POST['tab'] = Tools::safeOutput(Tools::getValue('controller'));
$echo = '';
if ($key != 'update')
{
// We check if method of module exists // We check if method of module exists
if (!method_exists($module, $method)) if (!method_exists($module, $method))
throw new PrestaShopException('Method of module can\'t be found'); throw new PrestaShopException('Method of module can\'t be found');
// Get the return value of current method // Get the return value of current method
$echo = $module->{$method}(); $echo = $module->{$method}();
}
// If the method called is "configure" (getContent method), we show the html code of configure page // If the method called is "configure" (getContent method), we show the html code of configure page
if ($key == 'configure' && Module::isInstalled($module->name)) if ($key == 'configure' && Module::isInstalled($module->name))
@@ -970,6 +980,7 @@ class AdminModulesControllerCore extends AdminController
{ {
// Upgrade Module process, init check if a module could be upgraded // Upgrade Module process, init check if a module could be upgraded
if (Module::initUpgradeModule($module->name, $module->version)) if (Module::initUpgradeModule($module->name, $module->version))
{
if ($object = new $module->name()) if ($object = new $module->name())
{ {
$object->runUpgradeModule(); $object->runUpgradeModule();
@@ -977,7 +988,20 @@ class AdminModulesControllerCore extends AdminController
$module_errors[] = array('name' => $module->name, 'message' => $errors_module_list); $module_errors[] = array('name' => $module->name, 'message' => $errors_module_list);
else if ((count($conf_module_list = $object->getConfirmations()))) else if ((count($conf_module_list = $object->getConfirmations())))
$module_success[] = array('name' => $module->name, 'message' => $conf_module_list); $module_success[] = array('name' => $module->name, 'message' => $conf_module_list);
unset($object);
} }
}
// Module can't be upgraded if not file exist but can change the database version...
// User has to be prevented
else if (Module::getUpgradeStatus($module->name))
{
$object = new $module->name();
$module_success[] = array('name' => $module->name, 'message' => array(
0 => $this->l('Current version: ').$object->version,
1 => $this->l('No files upgrade applied (none exist)'))
);
unset($object);
}
// Make modules stats // Make modules stats
$this->makeModulesStats($module); $this->makeModulesStats($module);
@@ -1010,6 +1034,7 @@ class AdminModulesControllerCore extends AdminController
$modules[$km]->optionsHtml = $this->displayModuleOptions($module); $modules[$km]->optionsHtml = $this->displayModuleOptions($module);
$modules[$km]->categoryName = (isset($this->list_modules_categories[$module->tab]['name']) ? $this->list_modules_categories[$module->tab]['name'] : $this->list_modules_categories['others']['name']); $modules[$km]->categoryName = (isset($this->list_modules_categories[$module->tab]['name']) ? $this->list_modules_categories[$module->tab]['name'] : $this->list_modules_categories['others']['name']);
$modules[$km]->options['install_url'] = self::$currentIndex.'&install='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name); $modules[$km]->options['install_url'] = self::$currentIndex.'&install='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name);
$modules[$km]->options['update_url'] = self::$currentIndex.'&update='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name);
$modules[$km]->options['uninstall_url'] = self::$currentIndex.'&uninstall='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name); $modules[$km]->options['uninstall_url'] = self::$currentIndex.'&uninstall='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name);
$modules[$km]->options['uninstall_onclick'] = ((!method_exists($module, 'onclickOption')) ? ((empty($module->confirmUninstall)) ? '' : 'return confirm(\''.addslashes($module->confirmUninstall).'\');') : $module->onclickOption('uninstall', $modules[$km]->options['uninstall_url'])); $modules[$km]->options['uninstall_onclick'] = ((!method_exists($module, 'onclickOption')) ? ((empty($module->confirmUninstall)) ? '' : 'return confirm(\''.addslashes($module->confirmUninstall).'\');') : $module->onclickOption('uninstall', $modules[$km]->options['uninstall_url']));
if (Tools::getValue('module_name') == $module->name && (int)Tools::getValue('conf') > 0) if (Tools::getValue('module_name') == $module->name && (int)Tools::getValue('conf') > 0)