Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions administrator/components/com_installer/src/Model/InstallModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace Joomla\Component\Installer\Administrator\Model;

use Joomla\CMS\Event\Installer\AfterInstallerEvent;
use Joomla\CMS\Event\Installer\BeforeInstallationEvent;
use Joomla\CMS\Event\Installer\BeforeInstallerEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Installer\Installer;
Expand Down Expand Up @@ -82,16 +85,22 @@ public function install()
{
$this->setState('action', 'install');

$app = Factory::getApplication();
$app = Factory::getApplication();
$dispatcher = $this->getDispatcher();

// Load installer plugins for assistance if required:
PluginHelper::importPlugin('installer');
PluginHelper::importPlugin('installer', null, true, $dispatcher);

$package = null;

// This event allows an input pre-treatment, a custom pre-packing or custom installation.
// (e.g. from a \JSON description).
$results = $app->triggerEvent('onInstallerBeforeInstallation', [$this, &$package]);
$eventBefore = new BeforeInstallationEvent('onInstallerBeforeInstallation', [
'subject' => $this,
'package' => &$package, // TODO: Remove reference in Joomla 6, see InstallerEvent::__constructor()
]);
$results = $dispatcher->dispatch('onInstallerBeforeInstallation', $eventBefore)->getArgument('result', []);
$package = $eventBefore->getPackage();

if (in_array(true, $results, true)) {
return true;
Expand Down Expand Up @@ -128,7 +137,12 @@ public function install()
}

// This event allows a custom installation of the package or a customization of the package:
$results = $app->triggerEvent('onInstallerBeforeInstaller', [$this, &$package]);
$eventBeforeInst = new BeforeInstallerEvent('onInstallerBeforeInstaller', [
'subject' => $this,
'package' => &$package, // TODO: Remove reference in Joomla 6, see InstallerEvent::__constructor()
]);
$results = $dispatcher->dispatch('onInstallerBeforeInstaller', $eventBeforeInst)->getArgument('result', []);
$package = $eventBeforeInst->getPackage();

if (in_array(true, $results, true)) {
return true;
Expand Down Expand Up @@ -205,7 +219,17 @@ public function install()
}

// This event allows a custom a post-flight:
$app->triggerEvent('onInstallerAfterInstaller', [$this, &$package, $installer, &$result, &$msg]);
$eventAfterInst = new AfterInstallerEvent('onInstallerAfterInstaller', [
'subject' => $this,
'package' => &$package, // TODO: Remove reference in Joomla 6, see InstallerEvent::__constructor()
'installer' => $installer,
'installerResult' => &$result, // TODO: Remove reference in Joomla 6, see AfterInstallerEvent::__constructor()
'message' => &$msg, // TODO: Remove reference in Joomla 6, see AfterInstallerEvent::__constructor()
]);
$dispatcher->dispatch('onInstallerAfterInstaller', $eventAfterInst);
$package = $eventAfterInst->getPackage();
$result = $eventAfterInst->getInstallerResult();
$msg = $eventAfterInst->getMessage();

// Set some model state values.
$app->enqueueMessage($msg, $msgType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

defined('_JEXEC') or die;

use Joomla\CMS\Event\Installer\AddInstallationTabEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
Expand All @@ -29,8 +30,9 @@
->usePreset('com_installer.installer')
->useScript('webcomponent.core-loader');

$app = Factory::getApplication();
$tabs = $app->triggerEvent('onInstallerAddInstallationTab', []);
$tabs = Factory::getApplication()->getDispatcher()
->dispatch('onInstallerAddInstallationTab', new AddInstallationTabEvent('onInstallerAddInstallationTab', []))
->getArgument('result', []);

?>
<div id="installer-install" class="clearfix">
Expand Down
8 changes: 7 additions & 1 deletion libraries/src/Event/CoreEventAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ trait CoreEventAware
'onPrepareModuleList' => Module\PrepareModuleListEvent::class,
'onAfterModuleList' => Module\AfterModuleListEvent::class,
'onAfterCleanModuleList' => Module\AfterCleanModuleListEvent::class,
// Extension and Installer
// Extension
'onExtensionBeforeInstall' => Extension\BeforeInstallEvent::class,
'onExtensionAfterInstall' => Extension\AfterInstallEvent::class,
'onExtensionBeforeUninstall' => Extension\BeforeUninstallEvent::class,
Expand All @@ -163,6 +163,12 @@ trait CoreEventAware
'onExtensionBeforeSave' => Model\BeforeSaveEvent::class,
'onExtensionAfterSave' => Model\AfterSaveEvent::class,
'onExtensionAfterDelete' => Model\AfterDeleteEvent::class,
// Installer
'onInstallerAddInstallationTab' => Installer\AddInstallationTabEvent::class,
'onInstallerBeforeInstallation' => Installer\BeforeInstallationEvent::class,
'onInstallerBeforeInstaller' => Installer\BeforeInstallerEvent::class,
'onInstallerAfterInstaller' => Installer\AfterInstallerEvent::class,
'onInstallerBeforePackageDownload' => Installer\BeforePackageDownloadEvent::class,
// Finder
'onFinderCategoryChangeState' => Finder\AfterCategoryChangeStateEvent::class,
'onFinderChangeState' => Finder\AfterChangeStateEvent::class,
Expand Down
30 changes: 30 additions & 0 deletions libraries/src/Event/Installer/AddInstallationTabEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Installer;

use Joomla\CMS\Event\AbstractImmutableEvent;
use Joomla\CMS\Event\Result\ResultAware;
use Joomla\CMS\Event\Result\ResultAwareInterface;
use Joomla\CMS\Event\Result\ResultTypeArrayAware;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Installer events
*
* @since __DEPLOY_VERSION__
*/
class AddInstallationTabEvent extends AbstractImmutableEvent implements ResultAwareInterface
{
use ResultAware;
use ResultTypeArrayAware;
}
182 changes: 182 additions & 0 deletions libraries/src/Event/Installer/AfterInstallerEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Installer;

use Joomla\CMS\Installer\Installer as ExtensionInstaller;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Installer events
*
* @since __DEPLOY_VERSION__
*/
class AfterInstallerEvent extends InstallerEvent
{
/**
* The argument names, in order expected by legacy plugins.
*
* @var array
*
* @since __DEPLOY_VERSION__
* @deprecated 5.0 will be removed in 6.0
*/
protected $legacyArgumentsOrder = ['subject', 'package', 'installer', 'installerResult', 'message'];

/**
* Constructor.
*
* @param string $name The event name.
* @param array $arguments The event arguments.
*
* @throws \BadMethodCallException
*
* @since __DEPLOY_VERSION__
*/
public function __construct($name, array $arguments = [])
{
parent::__construct($name, $arguments);

if (!\array_key_exists('installer', $this->arguments)) {
throw new \BadMethodCallException("Argument 'installer' of event {$name} is required but has not been provided");
}

if (!\array_key_exists('installerResult', $this->arguments)) {
throw new \BadMethodCallException("Argument 'installerResult' of event {$name} is required but has not been provided");
}

if (!\array_key_exists('message', $this->arguments)) {
throw new \BadMethodCallException("Argument 'message' of event {$name} is required but has not been provided");
}

// For backward compatibility make sure the values is referenced
// TODO: Remove in Joomla 6
// @deprecated: Passing argument by reference is deprecated, and will not work in Joomla 6
if (key($arguments) === 0) {
$this->arguments['installerResult'] = &$arguments[3];
$this->arguments['message'] = &$arguments[4];
} elseif (\array_key_exists('installerResult', $arguments)) {
$this->arguments['installerResult'] = &$arguments['installerResult'];
$this->arguments['message'] = &$arguments['message'];
}
}

/**
* Setter for the installer argument.
*
* @param ExtensionInstaller $value The value to set
*
* @return ExtensionInstaller
*
* @since __DEPLOY_VERSION__
*/
protected function setInstaller(ExtensionInstaller $value): ExtensionInstaller
{
return $value;
}

/**
* Setter for the installerResult argument.
*
* @param bool $value The value to set
*
* @return bool
*
* @since __DEPLOY_VERSION__
*/
protected function setInstallerResult(bool $value): bool
{
return $value;
}

/**
* Setter for the message argument.
*
* @param string $value The value to set
*
* @return string
*
* @since __DEPLOY_VERSION__
*/
protected function setMessage(string $value): string
{
return $value;
}

/**
* Getter for the installer.
*
* @return ExtensionInstaller
*
* @since __DEPLOY_VERSION__
*/
public function getInstaller(): ExtensionInstaller
{
return $this->arguments['installer'];
}

/**
* Getter for the installer result.
*
* @return bool
*
* @since __DEPLOY_VERSION__
*/
public function getInstallerResult(): bool
{
return $this->arguments['installerResult'];
}

/**
* Getter for the message.
*
* @return string
*
* @since __DEPLOY_VERSION__
*/
public function getMessage(): string
{
return $this->arguments['message'];
}

/**
* Update the installerResult.
*
* @param bool $value The value to set
*
* @return static
*
* @since __DEPLOY_VERSION__
*/
public function updateInstallerResult(bool $value): static
{
$this->arguments['installerResult'] = $value;

return $this;
}

/**
* Update the message.
*
* @param string $value The value to set
*
* @return static
*
* @since __DEPLOY_VERSION__
*/
public function updateMessage(string $value): static
{
$this->arguments['message'] = $value;

return $this;
}
}
29 changes: 29 additions & 0 deletions libraries/src/Event/Installer/BeforeInstallationEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Installer;

use Joomla\CMS\Event\Result\ResultAware;
use Joomla\CMS\Event\Result\ResultAwareInterface;
use Joomla\CMS\Event\Result\ResultTypeBooleanAware;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Installer events
*
* @since __DEPLOY_VERSION__
*/
class BeforeInstallationEvent extends InstallerEvent implements ResultAwareInterface
{
use ResultAware;
use ResultTypeBooleanAware;
}
29 changes: 29 additions & 0 deletions libraries/src/Event/Installer/BeforeInstallerEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Installer;

use Joomla\CMS\Event\Result\ResultAware;
use Joomla\CMS\Event\Result\ResultAwareInterface;
use Joomla\CMS\Event\Result\ResultTypeBooleanAware;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Installer events
*
* @since __DEPLOY_VERSION__
*/
class BeforeInstallerEvent extends InstallerEvent implements ResultAwareInterface
{
use ResultAware;
use ResultTypeBooleanAware;
}
Loading