Skip to content

Commit

Permalink
Merge pull request #768 from ga-devfront/feat/update-tab
Browse files Browse the repository at this point in the history
Move menu entry in back-office sidebar
  • Loading branch information
Quetzacoalt91 authored Jul 12, 2024
2 parents d698158 + 44fefab commit 9d65880
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
25 changes: 5 additions & 20 deletions autoupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,38 +84,22 @@ public function install()
return false;
}

// Before creating a new tab "AdminSelfUpgrade" we need to remove any existing "AdminUpgrade" tab (present in v1.4.4.0 and v1.4.4.1)
if ($id_tab = Tab::getIdFromClassName('AdminUpgrade')) {
$tab = new Tab((int) $id_tab);
if (!$tab->delete()) {
$this->_errors[] = $this->trans('Unable to delete outdated "AdminUpgrade" tab (tab ID: %idtab%).', ['%idtab%' => (int) $id_tab]);
}
}

// If the "AdminSelfUpgrade" tab does not exist yet, create it
if (!$id_tab = Tab::getIdFromClassName('AdminSelfUpgrade')) {
if (!Tab::getIdFromClassName('AdminSelfUpgrade')) {
$tab = new Tab();
$tab->class_name = 'AdminSelfUpgrade';
$tab->icon = 'upgrade';
$tab->module = 'autoupgrade';

// We use DEFAULT to add Upgrade tab as a standalone tab in the back office menu
$tab->id_parent = (int) Tab::getIdFromClassName('DEFAULT');
$tab->id_parent = (int) Tab::getIdFromClassName('CONFIGURE');

foreach (Language::getLanguages(false) as $lang) {
$tab->name[(int) $lang['id_lang']] = '1-Click Upgrade';
}
if (!$tab->save()) {
return $this->_abortInstall($this->trans('Unable to create the "AdminSelfUpgrade" tab'));
}
} else {
$tab = new Tab((int) $id_tab);
}

// Update the "AdminSelfUpgrade" tab id in database or exit
if (Validate::isLoadedObject($tab)) {
Configuration::updateValue('PS_AUTOUPDATE_MODULE_IDTAB', (int) $tab->id);
} else {
return $this->_abortInstall($this->trans('Unable to load the "AdminSelfUpgrade" tab'));
}

return parent::install();
Expand All @@ -127,7 +111,8 @@ public function install()
public function uninstall()
{
// Delete the 1-click upgrade Back-office tab
if ($id_tab = Tab::getIdFromClassName('AdminSelfUpgrade')) {
$id_tab = Tab::getIdFromClassName('AdminSelfUpgrade');
if ($id_tab) {
$tab = new Tab((int) $id_tab);
$tab->delete();
}
Expand Down
28 changes: 27 additions & 1 deletion upgrade/install-6.0.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,31 @@
*/
function upgrade_module_6_0_0($module)
{
return $module->unregisterHook('dashboardZoneOne');
if (!$module->unregisterHook('dashboardZoneOne')) {
return false;
}

// Update the 'AdminSelfUpgrade' tab configuration
$id_tab = \Tab::getIdFromClassName('AdminSelfUpgrade');
if ($id_tab) {
$tab = new \Tab($id_tab);
} else {
// If the tab doesn't exist, create it
$tab = new \Tab();
$tab->class_name = 'AdminSelfUpgrade';
$tab->module = 'autoupgrade';
}

$tab->id_parent = (int) \Tab::getIdFromClassName('CONFIGURE');
$tab->icon = 'upgrade';

foreach (\Language::getLanguages(false) as $lang) {
$tab->name[(int) $lang['id_lang']] = '1-Click Upgrade';
}

if (!$tab->save()) {
return false;
}

return true;
}

0 comments on commit 9d65880

Please sign in to comment.