Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37091 from Digital-Peak/j4/installer/service
[4.2] Extension installer script enhancements
- Loading branch information
Showing
4 changed files
with
327 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\CMS\Installer; | ||
|
||
\defined('_JEXEC') or die; | ||
|
||
/** | ||
* Base install script interface for use by extensions providing helper methods for common behaviours. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
interface InstallerScriptInterface | ||
{ | ||
/** | ||
* 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; | ||
|
||
/** | ||
* 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; | ||
|
||
/** | ||
* 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; | ||
|
||
/** | ||
* 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; | ||
|
||
/** | ||
* 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
<?php | ||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\CMS\Installer; | ||
|
||
\defined('_JEXEC') or die; | ||
|
||
/** | ||
* Legacy installer script which delegates the methods to the internal instance when possible. | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class LegacyInstallerScript implements InstallerScriptInterface | ||
{ | ||
/** | ||
* @var \stdClass | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
private $installerScript; | ||
|
||
/** | ||
* @param \stdClass $installerScript The script instance | ||
*/ | ||
public function __construct($installerScript) | ||
{ | ||
$this->installerScript = $installerScript; | ||
} | ||
|
||
/** | ||
* 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 | ||
{ | ||
if (!method_exists($this->installerScript, 'install')) | ||
{ | ||
return true; | ||
} | ||
|
||
return (bool) $this->installerScript->install($adapter); | ||
} | ||
|
||
/** | ||
* 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 | ||
{ | ||
if (!method_exists($this->installerScript, 'update')) | ||
{ | ||
return true; | ||
} | ||
|
||
return (bool) $this->installerScript->update($adapter); | ||
} | ||
|
||
/** | ||
* 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 | ||
{ | ||
if (!method_exists($this->installerScript, 'uninstall')) | ||
{ | ||
return true; | ||
} | ||
|
||
return (bool) $this->installerScript->uninstall($adapter); | ||
} | ||
|
||
/** | ||
* 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 | ||
{ | ||
if (!method_exists($this->installerScript, 'preflight')) | ||
{ | ||
return true; | ||
} | ||
|
||
return (bool) $this->installerScript->preflight($type, $adapter); | ||
} | ||
|
||
/** | ||
* 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 | ||
{ | ||
if (!method_exists($this->installerScript, 'postflight')) | ||
{ | ||
return true; | ||
} | ||
|
||
return (bool) $this->installerScript->postflight($type, $adapter); | ||
} | ||
|
||
/** | ||
* Sets the variable to the internal script. | ||
* | ||
* @param string $name The name of the variable | ||
* @param mixed $value The value of the variable | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function __set(string $name, $value) | ||
{ | ||
$this->installerScript->$name = $value; | ||
} | ||
|
||
/** | ||
* Returns the variable from the internal script. | ||
* | ||
* @param string $name The name of the variable | ||
* | ||
* @return mixed | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function __get(string $name) | ||
{ | ||
return $this->installerScript->$name; | ||
} | ||
|
||
/** | ||
* Calls the function with the given name on the internal script. | ||
* | ||
* @param string $name The name of the function | ||
* @param array $arguments The arguments | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function __call(string $name, array $arguments) | ||
{ | ||
return call_user_func([$this->installerScript, $name], $arguments); | ||
} | ||
} |