From 3da350ae6f5e225b0571c5994e4aad9c0e0cb303 Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Wed, 30 Oct 2024 22:27:13 +0100 Subject: [PATCH 01/13] Add InstallerScriptTrait --- .../src/Installer/InstallerScriptTrait.php | 296 ++++++++++++++++++ 1 file changed, 296 insertions(+) create mode 100644 libraries/src/Installer/InstallerScriptTrait.php diff --git a/libraries/src/Installer/InstallerScriptTrait.php b/libraries/src/Installer/InstallerScriptTrait.php new file mode 100644 index 0000000000000..13e5ee9ec9acc --- /dev/null +++ b/libraries/src/Installer/InstallerScriptTrait.php @@ -0,0 +1,296 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\CMS\Installer; + +use Joomla\CMS\Application\ApplicationHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Log\Log; +use Joomla\Filesystem\File; +use Joomla\Filesystem\Folder; +use Joomla\Filesystem\Path; + +trait InstallerScriptTrait +{ + /** + * The extension name. This should be set in the installer script. + * + * @var string + * @since __DEPLOY_VERSION__ + */ + protected $extension; + + /** + * Minimum PHP version required to install the extension + * + * @var string + * @since __DEPLOY_VERSION__ + */ + protected $minimumPhp; + + /** + * Minimum Joomla! version required to install the extension + * + * @var string + * @since __DEPLOY_VERSION__ + */ + protected $minimumJoomla; + + /** + * Allow downgrades of your extension + * + * Use at your own risk as if there is a change in functionality people may wish to downgrade. + * + * @var boolean + * @since __DEPLOY_VERSION__ + */ + protected $allowDowngrades = false; + + /** + * A list of files to be deleted + * + * @var array + * @since __DEPLOY_VERSION__ + */ + protected $deleteFiles = []; + + /** + * A list of folders to be deleted + * + * @var array + * @since __DEPLOY_VERSION__ + */ + protected $deleteFolders = []; + + /** + * Function called after the extension is installed. + * + * @param InstallerAdapter $adapter The adapter calling this method + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + public function install(InstallerAdapter $adapter): bool + { + return true; + } + + /** + * Function called after the extension is updated. + * + * @param InstallerAdapter $adapter The adapter calling this method + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + public function update(InstallerAdapter $adapter): bool + { + return true; + } + + /** + * Function called after the extension is uninstalled. + * + * @param InstallerAdapter $adapter The adapter calling this method + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + public function uninstall(InstallerAdapter $adapter): bool + { + return true; + } + + /** + * Function called before extension installation/update/removal procedure commences. + * + * @param string $type The type of change (install or discover_install, update, uninstall) + * @param InstallerAdapter $adapter The adapter calling this method + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + public function preflight(string $type, InstallerAdapter $adapter): bool + { + $this->extension = $adapter->getName(); + + if (!$this->checkCompatibility($type, $adapter)) { + return false; + } + + if (!$this->checkDowngrade($type, $adapter)) { + return false; + } + return true; + } + + /** + * Function called after extension installation/update/removal procedure commences. + * + * @param string $type The type of change (install or discover_install, update, uninstall) + * @param InstallerAdapter $adapter The adapter calling this method + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + public function postflight(string $type, InstallerAdapter $adapter): bool + { + + $this->removeFiles(); + + return true; + } + + /** + * Check if the extension passes the minimum requirements to be installed + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + protected function checkCompatibility(string $type, InstallerAdapter $adapter): bool + { + // Check for the minimum PHP version before continuing + if (!empty($this->minimumPhp) && version_compare(PHP_VERSION, $this->minimumPhp, '<')) { + Log::add(Text::sprintf('JLIB_INSTALLER_MINIMUM_PHP', $this->minimumPhp), Log::WARNING, 'jerror'); + + return false; + } + + // Check for the minimum Joomla version before continuing + if (!empty($this->minimumJoomla) && version_compare(JVERSION, $this->minimumJoomla, '<')) { + Log::add(Text::sprintf('JLIB_INSTALLER_MINIMUM_JOOMLA', $this->minimumJoomla), Log::WARNING, 'jerror'); + + return false; + } + + return true; + } + + /** + * Check if the extension is allowed to be downgraded + * + * @return boolean False when downgrade not allowed and new version is lower than old version otherwise true + * + * @since __DEPLOY_VERSION__ + */ + protected function checkDowngrade(string $type, InstallerAdapter $adapter): bool + { + if ($type !== 'update' || $this->allowDowngrades) { + return true; + } + + $oldManifest = $this->getOldManifest($adapter); + + if ($oldManifest !== null && $oldManifest->version && version_compare($oldManifest->version, $adapter->getManifest()->version, '>')) { + Log::add(Text::_('JLIB_INSTALLER_ERROR_DOWNGRADE'), Log::WARNING, 'jerror'); + + return false; + } + + return true; + } + + /** + * Returns the manifest file if it exists or null + * + * @param InstallerAdapter $adapter + * + * @return SimpleXMLElement|null + * + * @since __DEPLOY_VERSION__ + */ + protected function getOldManifest(InstallerAdapter $adapter): ?\SimpleXMLElement + { + $client = ApplicationHelper::getClientInfo(1); + + $pathname = 'extension_' . ($client ? $client->name : 'root'); + + $manifestPath = $this->getPath($pathname) . '/' . $this->getPath('manifest'); + + return is_file($manifestPath) ? $adapter->getParent()->isManifest($manifestPath) : null; + } + + /** + * Remove the files and folders in the given array from + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + protected function removeFiles(): void + { + if (!empty($this->deleteFiles)) { + foreach ($this->deleteFiles as $file) { + if (is_file(Path::check(JPATH_ROOT . $file)) && !File::delete(JPATH_ROOT . $file)) { + Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_FILE_FOLDER', $file)); + } + } + } + + if (!empty($this->deleteFolders)) { + foreach ($this->deleteFolders as $folder) { + if (is_dir(Path::check(JPATH_ROOT . $folder)) && !Folder::delete(JPATH_ROOT . $folder)) { + Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_FILE_FOLDER', $folder)); + } + } + } + } + + /** + * Creates the dashboard menu module + * + * @param string $dashboard The name of the dashboard + * @param string $preset The name of the menu preset + * + * @return void + * + * @throws \Exception + * @since __DEPLOY_VERSION__ + */ + protected function addDashboardMenu(string $dashboard, string $preset) + { + $model = Factory::getApplication()->bootComponent('com_modules')->getMVCFactory()->createModel('Module', 'Administrator', ['ignore_request' => true]); + $module = [ + 'id' => 0, + 'asset_id' => 0, + 'language' => '*', + 'note' => '', + 'published' => 1, + 'assignment' => 0, + 'client_id' => 1, + 'showtitle' => 0, + 'content' => '', + 'module' => 'mod_submenu', + 'position' => 'cpanel-' . $dashboard, + ]; + + // Try to get a translated module title, otherwise fall back to a fixed string. + $titleKey = strtoupper('COM_' . $this->extension . '_DASHBOARD_' . $dashboard . '_TITLE'); + $title = Text::_($titleKey); + $module['title'] = ($title === $titleKey) ? ucfirst($dashboard) . ' Dashboard' : $title; + + $module['access'] = (int) Factory::getApplication()->get('access', 1); + $module['params'] = [ + 'menutype' => '*', + 'preset' => $preset, + 'style' => 'System-none', + ]; + + if (!$model->save($module)) { + Factory::getApplication()->enqueueMessage(Text::sprintf('JLIB_INSTALLER_ERROR_COMP_INSTALL_FAILED_TO_CREATE_DASHBOARD', $model->getError())); + } + } +} From ce87cfecdcb33af161b57e93aca186a27900bd9e Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Wed, 30 Oct 2024 22:27:34 +0100 Subject: [PATCH 02/13] Deprecate InstallerScript --- libraries/src/Installer/InstallerScript.php | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libraries/src/Installer/InstallerScript.php b/libraries/src/Installer/InstallerScript.php index 13083cdcac38a..d52ddedba799c 100644 --- a/libraries/src/Installer/InstallerScript.php +++ b/libraries/src/Installer/InstallerScript.php @@ -25,6 +25,9 @@ * Base install script for use by extensions providing helper methods for common behaviours. * * @since 3.6 + * + * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 + * Use InstallerScriptTrait instead. */ class InstallerScript { @@ -111,6 +114,9 @@ class InstallerScript * @return boolean True on success * * @since 3.6 + * + * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 + * Use InstallerScriptTrait::preflight instead. */ public function preflight($type, $parent) { @@ -169,6 +175,9 @@ public function preflight($type, $parent) * @return array An array of ID's of the extension * * @since 3.6 + * + * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 + * Will be removed without replacement. */ public function getInstances($isModule) { @@ -203,6 +212,9 @@ public function getInstances($isModule) * @return string The parameter desired * * @since 3.6 + * + * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 + * Will be removed without replacement. */ public function getParam($name, $id = 0) { @@ -228,6 +240,9 @@ public function getParam($name, $id = 0) * @return boolean True on success * * @since 3.6 + * + * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 + * Will be removed without replacement. */ public function setParams($paramArray = null, $type = 'edit', $id = 0) { @@ -285,6 +300,9 @@ public function setParams($paramArray = null, $type = 'edit', $id = 0) * @return array Associated array containing data from the cell * * @since 3.6 + * + * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 + * Will be removed without replacement. */ public function getItemArray($element, $table, $column, $identifier) { @@ -313,6 +331,9 @@ public function getItemArray($element, $table, $column, $identifier) * @return void * * @since 3.6 + * + * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 + * Use InstallerScriptTrait::removeFiles instead. */ public function removeFiles() { @@ -339,6 +360,9 @@ public function removeFiles() * @return void * * @since 3.6 + * + * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 + * Will be removed without replacement. Use console plugins instead. */ public function moveCliFiles() { @@ -363,6 +387,9 @@ public function moveCliFiles() * * @throws \Exception * @since 4.0.0 + * + * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 + * Use InstallerScriptTrait::addDashboardMenu instead. */ public function addDashboardMenu(string $dashboard, string $preset) { From dad75750e209f035a19c79cc6e2b7e4819a0fa77 Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Thu, 31 Oct 2024 09:42:07 +0100 Subject: [PATCH 03/13] Fix wrong path call --- libraries/src/Installer/InstallerScriptTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Installer/InstallerScriptTrait.php b/libraries/src/Installer/InstallerScriptTrait.php index 13e5ee9ec9acc..00bb0ed25b50f 100644 --- a/libraries/src/Installer/InstallerScriptTrait.php +++ b/libraries/src/Installer/InstallerScriptTrait.php @@ -218,7 +218,7 @@ protected function getOldManifest(InstallerAdapter $adapter): ?\SimpleXMLElement $pathname = 'extension_' . ($client ? $client->name : 'root'); - $manifestPath = $this->getPath($pathname) . '/' . $this->getPath('manifest'); + $manifestPath = $adapter->getParent()->getPath($pathname) . '/' . $adapter->getParent()->getPath('manifest'); return is_file($manifestPath) ? $adapter->getParent()->isManifest($manifestPath) : null; } From dae0b8e944b1590350fdc2496599faa137a1a3fc Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Mon, 3 Mar 2025 12:01:58 +0100 Subject: [PATCH 04/13] Remove deprecations --- libraries/src/Installer/InstallerScript.php | 24 --------------------- 1 file changed, 24 deletions(-) diff --git a/libraries/src/Installer/InstallerScript.php b/libraries/src/Installer/InstallerScript.php index d52ddedba799c..7b4b0c00a2f7d 100644 --- a/libraries/src/Installer/InstallerScript.php +++ b/libraries/src/Installer/InstallerScript.php @@ -114,9 +114,6 @@ class InstallerScript * @return boolean True on success * * @since 3.6 - * - * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 - * Use InstallerScriptTrait::preflight instead. */ public function preflight($type, $parent) { @@ -175,9 +172,6 @@ public function preflight($type, $parent) * @return array An array of ID's of the extension * * @since 3.6 - * - * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 - * Will be removed without replacement. */ public function getInstances($isModule) { @@ -212,9 +206,6 @@ public function getInstances($isModule) * @return string The parameter desired * * @since 3.6 - * - * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 - * Will be removed without replacement. */ public function getParam($name, $id = 0) { @@ -240,9 +231,6 @@ public function getParam($name, $id = 0) * @return boolean True on success * * @since 3.6 - * - * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 - * Will be removed without replacement. */ public function setParams($paramArray = null, $type = 'edit', $id = 0) { @@ -300,9 +288,6 @@ public function setParams($paramArray = null, $type = 'edit', $id = 0) * @return array Associated array containing data from the cell * * @since 3.6 - * - * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 - * Will be removed without replacement. */ public function getItemArray($element, $table, $column, $identifier) { @@ -331,9 +316,6 @@ public function getItemArray($element, $table, $column, $identifier) * @return void * * @since 3.6 - * - * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 - * Use InstallerScriptTrait::removeFiles instead. */ public function removeFiles() { @@ -360,9 +342,6 @@ public function removeFiles() * @return void * * @since 3.6 - * - * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 - * Will be removed without replacement. Use console plugins instead. */ public function moveCliFiles() { @@ -387,9 +366,6 @@ public function moveCliFiles() * * @throws \Exception * @since 4.0.0 - * - * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 - * Use InstallerScriptTrait::addDashboardMenu instead. */ public function addDashboardMenu(string $dashboard, string $preset) { From 52733b325d16d1ce57204280978fe1d6f761ab69 Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Mon, 3 Mar 2025 12:03:02 +0100 Subject: [PATCH 05/13] Remove deprecation of class --- libraries/src/Installer/InstallerScript.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/libraries/src/Installer/InstallerScript.php b/libraries/src/Installer/InstallerScript.php index 7b4b0c00a2f7d..13083cdcac38a 100644 --- a/libraries/src/Installer/InstallerScript.php +++ b/libraries/src/Installer/InstallerScript.php @@ -25,9 +25,6 @@ * Base install script for use by extensions providing helper methods for common behaviours. * * @since 3.6 - * - * @deprecated __DEPLOY_VERSION__ will be removed in 7.0 - * Use InstallerScriptTrait instead. */ class InstallerScript { From b9c79a2863533f5cd43ee1166f505c7915a62755 Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Mon, 3 Mar 2025 12:06:27 +0100 Subject: [PATCH 06/13] Rename method --- libraries/src/Installer/InstallerScriptTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Installer/InstallerScriptTrait.php b/libraries/src/Installer/InstallerScriptTrait.php index 00bb0ed25b50f..fb4ca98f32ae5 100644 --- a/libraries/src/Installer/InstallerScriptTrait.php +++ b/libraries/src/Installer/InstallerScriptTrait.php @@ -260,7 +260,7 @@ protected function removeFiles(): void * @throws \Exception * @since __DEPLOY_VERSION__ */ - protected function addDashboardMenu(string $dashboard, string $preset) + protected function addDashboardMenuModule(string $dashboard, string $preset) { $model = Factory::getApplication()->bootComponent('com_modules')->getMVCFactory()->createModel('Module', 'Administrator', ['ignore_request' => true]); $module = [ From 8fe2e7763fbad8845c28517437a338137726477e Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Fri, 25 Apr 2025 20:36:17 +0200 Subject: [PATCH 07/13] Add set/getApplication --- libraries/src/Installer/InstallerAdapter.php | 4 ++ .../src/Installer/InstallerScriptTrait.php | 38 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/libraries/src/Installer/InstallerAdapter.php b/libraries/src/Installer/InstallerAdapter.php index 25bd05afc99cc..43547433cf56e 100644 --- a/libraries/src/Installer/InstallerAdapter.php +++ b/libraries/src/Installer/InstallerAdapter.php @@ -997,6 +997,10 @@ function (Container $container) use ($classname) { // Create a new instance $this->parent->manifestClass = $container->get(InstallerScriptInterface::class); + if (method_exists($this->parent->manifestClass, 'setApplication')) { + $this->parent->manifestClass->setApplication(Factory::getApplication()); + } + // Set the database if ($this->parent->manifestClass instanceof DatabaseAwareInterface) { $this->parent->manifestClass->setDatabase($container->get(DatabaseInterface::class)); diff --git a/libraries/src/Installer/InstallerScriptTrait.php b/libraries/src/Installer/InstallerScriptTrait.php index fb4ca98f32ae5..9d8ae948fef91 100644 --- a/libraries/src/Installer/InstallerScriptTrait.php +++ b/libraries/src/Installer/InstallerScriptTrait.php @@ -10,6 +10,7 @@ namespace Joomla\CMS\Installer; use Joomla\CMS\Application\ApplicationHelper; +use Joomla\CMS\Application\CMSApplicationInterface; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Log\Log; @@ -69,6 +70,15 @@ trait InstallerScriptTrait */ protected $deleteFolders = []; + /** + * The application object + * + * @var CMSApplicationInterface + * + * @since __DEPLOY_VERSION__ + */ + private $application; + /** * Function called after the extension is installed. * @@ -249,6 +259,32 @@ protected function removeFiles(): void } } + /** + * Returns the internal application or null when not set. + * + * @return CMSApplicationInterface|null + * + * @since __DEPLOY_VERSION__ + */ + protected function getApplication(): ?CMSApplicationInterface + { + return $this->application; + } + + /** + * Sets the application to use. + * + * @param CMSApplicationInterface $application The application + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function setApplication(CMSApplicationInterface $application): void + { + $this->application = $application; + } + /** * Creates the dashboard menu module * @@ -262,7 +298,7 @@ protected function removeFiles(): void */ protected function addDashboardMenuModule(string $dashboard, string $preset) { - $model = Factory::getApplication()->bootComponent('com_modules')->getMVCFactory()->createModel('Module', 'Administrator', ['ignore_request' => true]); + $model = $this->getApplication()->bootComponent('com_modules')->getMVCFactory()->createModel('Module', 'Administrator', ['ignore_request' => true]); $module = [ 'id' => 0, 'asset_id' => 0, From 347fff93800e2587314c036fbe6e6e4e1886466d Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Fri, 25 Apr 2025 21:04:08 +0200 Subject: [PATCH 08/13] Add custom pre/postflight which can be overwritten by the developer --- .../src/Installer/InstallerScriptTrait.php | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/libraries/src/Installer/InstallerScriptTrait.php b/libraries/src/Installer/InstallerScriptTrait.php index 9d8ae948fef91..557a17fd2a91f 100644 --- a/libraries/src/Installer/InstallerScriptTrait.php +++ b/libraries/src/Installer/InstallerScriptTrait.php @@ -142,6 +142,22 @@ public function preflight(string $type, InstallerAdapter $adapter): bool if (!$this->checkDowngrade($type, $adapter)) { return false; } + + return $this->customPreflight($type, $adapter); + } + + /** + * Custom preflight method to be overridden by the extension developer + * + * @param string $type The type of change (install or discover_install, update, uninstall) + * @param InstallerAdapter $adapter The adapter calling this method + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + protected function customPreflight(string $type, InstallerAdapter $adapter): bool + { return true; } @@ -157,9 +173,23 @@ public function preflight(string $type, InstallerAdapter $adapter): bool */ public function postflight(string $type, InstallerAdapter $adapter): bool { - $this->removeFiles(); + return $this->customPostflight($type, $adapter); + } + + /** + * Custom postflight method to be overridden by the extension developer + * + * @param string $type The type of change (install or discover_install, update, uninstall) + * @param InstallerAdapter $adapter The adapter calling this method + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + protected function customPostflight(string $type, InstallerAdapter $adapter): bool + { return true; } From 32ec14699494733e2f701ef3887af635fc87a140 Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Sat, 26 Apr 2025 18:05:56 +0200 Subject: [PATCH 09/13] Apply suggestions from code review Co-authored-by: Harald Leithner --- .../src/Installer/InstallerScriptTrait.php | 53 ++++--------------- 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/libraries/src/Installer/InstallerScriptTrait.php b/libraries/src/Installer/InstallerScriptTrait.php index 557a17fd2a91f..5c28b8263dc01 100644 --- a/libraries/src/Installer/InstallerScriptTrait.php +++ b/libraries/src/Installer/InstallerScriptTrait.php @@ -11,7 +11,6 @@ use Joomla\CMS\Application\ApplicationHelper; use Joomla\CMS\Application\CMSApplicationInterface; -use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Log\Log; use Joomla\Filesystem\File; @@ -26,7 +25,7 @@ trait InstallerScriptTrait * @var string * @since __DEPLOY_VERSION__ */ - protected $extension; + protected string $extension; /** * Minimum PHP version required to install the extension @@ -34,7 +33,7 @@ trait InstallerScriptTrait * @var string * @since __DEPLOY_VERSION__ */ - protected $minimumPhp; + protected string $minimumPhp; /** * Minimum Joomla! version required to install the extension @@ -42,7 +41,7 @@ trait InstallerScriptTrait * @var string * @since __DEPLOY_VERSION__ */ - protected $minimumJoomla; + protected string $minimumJoomla; /** * Allow downgrades of your extension @@ -52,7 +51,7 @@ trait InstallerScriptTrait * @var boolean * @since __DEPLOY_VERSION__ */ - protected $allowDowngrades = false; + protected bool $allowDowngrades = false; /** * A list of files to be deleted @@ -60,7 +59,7 @@ trait InstallerScriptTrait * @var array * @since __DEPLOY_VERSION__ */ - protected $deleteFiles = []; + protected array $deleteFiles = []; /** * A list of folders to be deleted @@ -68,7 +67,7 @@ trait InstallerScriptTrait * @var array * @since __DEPLOY_VERSION__ */ - protected $deleteFolders = []; + protected array $deleteFolders = []; /** * The application object @@ -77,7 +76,7 @@ trait InstallerScriptTrait * * @since __DEPLOY_VERSION__ */ - private $application; + private CMSApplicationInterface $application; /** * Function called after the extension is installed. @@ -143,21 +142,6 @@ public function preflight(string $type, InstallerAdapter $adapter): bool return false; } - return $this->customPreflight($type, $adapter); - } - - /** - * Custom preflight method to be overridden by the extension developer - * - * @param string $type The type of change (install or discover_install, update, uninstall) - * @param InstallerAdapter $adapter The adapter calling this method - * - * @return boolean True on success - * - * @since __DEPLOY_VERSION__ - */ - protected function customPreflight(string $type, InstallerAdapter $adapter): bool - { return true; } @@ -174,23 +158,6 @@ protected function customPreflight(string $type, InstallerAdapter $adapter): boo public function postflight(string $type, InstallerAdapter $adapter): bool { $this->removeFiles(); - - return $this->customPostflight($type, $adapter); - } - - /** - * Custom postflight method to be overridden by the extension developer - * - * @param string $type The type of change (install or discover_install, update, uninstall) - * @param InstallerAdapter $adapter The adapter calling this method - * - * @return boolean True on success - * - * @since __DEPLOY_VERSION__ - */ - protected function customPostflight(string $type, InstallerAdapter $adapter): bool - { - return true; } /** @@ -254,7 +221,7 @@ protected function checkDowngrade(string $type, InstallerAdapter $adapter): bool */ protected function getOldManifest(InstallerAdapter $adapter): ?\SimpleXMLElement { - $client = ApplicationHelper::getClientInfo(1); + $client = ApplicationHelper::getClientInfo('administrator', true); $pathname = 'extension_' . ($client ? $client->name : 'root'); @@ -348,7 +315,7 @@ protected function addDashboardMenuModule(string $dashboard, string $preset) $title = Text::_($titleKey); $module['title'] = ($title === $titleKey) ? ucfirst($dashboard) . ' Dashboard' : $title; - $module['access'] = (int) Factory::getApplication()->get('access', 1); + $module['access'] = (int) $this->getApplication()->get('access', 1); $module['params'] = [ 'menutype' => '*', 'preset' => $preset, @@ -356,7 +323,7 @@ protected function addDashboardMenuModule(string $dashboard, string $preset) ]; if (!$model->save($module)) { - Factory::getApplication()->enqueueMessage(Text::sprintf('JLIB_INSTALLER_ERROR_COMP_INSTALL_FAILED_TO_CREATE_DASHBOARD', $model->getError())); + $this->getApplication()->enqueueMessage(Text::sprintf('JLIB_INSTALLER_ERROR_COMP_INSTALL_FAILED_TO_CREATE_DASHBOARD', $model->getError())); } } } From bf9c294ea37b3bf7d911b3317f37641fd9cdbe3f Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Sat, 26 Apr 2025 18:06:37 +0200 Subject: [PATCH 10/13] Update libraries/src/Installer/InstallerScriptTrait.php --- libraries/src/Installer/InstallerScriptTrait.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/src/Installer/InstallerScriptTrait.php b/libraries/src/Installer/InstallerScriptTrait.php index 5c28b8263dc01..09a530e130e29 100644 --- a/libraries/src/Installer/InstallerScriptTrait.php +++ b/libraries/src/Installer/InstallerScriptTrait.php @@ -158,6 +158,8 @@ public function preflight(string $type, InstallerAdapter $adapter): bool public function postflight(string $type, InstallerAdapter $adapter): bool { $this->removeFiles(); + + return true; } /** From 70efcfd78de07b2e29496c8a6f373889653d4bae Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Thu, 31 Jul 2025 03:36:54 +0200 Subject: [PATCH 11/13] Fix CS --- libraries/src/Installer/InstallerScriptTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Installer/InstallerScriptTrait.php b/libraries/src/Installer/InstallerScriptTrait.php index 09a530e130e29..607fc27acc57e 100644 --- a/libraries/src/Installer/InstallerScriptTrait.php +++ b/libraries/src/Installer/InstallerScriptTrait.php @@ -158,7 +158,7 @@ public function preflight(string $type, InstallerAdapter $adapter): bool public function postflight(string $type, InstallerAdapter $adapter): bool { $this->removeFiles(); - + return true; } From 1d8b720bdbe7fa2260f0ac5ddd92a6c0b4aeda55 Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Thu, 14 Aug 2025 15:23:21 +0200 Subject: [PATCH 12/13] Remove unneded check --- libraries/src/Installer/InstallerScriptTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Installer/InstallerScriptTrait.php b/libraries/src/Installer/InstallerScriptTrait.php index 607fc27acc57e..3d6359b3d93d7 100644 --- a/libraries/src/Installer/InstallerScriptTrait.php +++ b/libraries/src/Installer/InstallerScriptTrait.php @@ -225,7 +225,7 @@ protected function getOldManifest(InstallerAdapter $adapter): ?\SimpleXMLElement { $client = ApplicationHelper::getClientInfo('administrator', true); - $pathname = 'extension_' . ($client ? $client->name : 'root'); + $pathname = 'extension_' . $client->name; $manifestPath = $adapter->getParent()->getPath($pathname) . '/' . $adapter->getParent()->getPath('manifest'); From e02ee22a40336e985699b248bd716bf839d04467 Mon Sep 17 00:00:00 2001 From: Benjamin Trenkle Date: Sat, 16 Aug 2025 16:49:14 +0200 Subject: [PATCH 13/13] Update libraries/src/Installer/InstallerScriptTrait.php Co-authored-by: Brian Teeman --- libraries/src/Installer/InstallerScriptTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Installer/InstallerScriptTrait.php b/libraries/src/Installer/InstallerScriptTrait.php index 3d6359b3d93d7..007caf7b37fa2 100644 --- a/libraries/src/Installer/InstallerScriptTrait.php +++ b/libraries/src/Installer/InstallerScriptTrait.php @@ -3,7 +3,7 @@ /** * Joomla! Content Management System * - * @copyright (C) 2024 Open Source Matters, Inc. + * @copyright (C) 2025 Open Source Matters, Inc. * @license GNU General Public License version 2 or later; see LICENSE.txt */