Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2][Events] Use event classes for Extension plugins #43617

Merged
merged 8 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
extension missing events
  • Loading branch information
Fedik committed Jun 4, 2024
commit 479637bb88cc398937357632abae113d13938d86
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use Joomla\CMS\Authentication\Authentication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Extension\AfterJoomlaUpdateEvent;
use Joomla\CMS\Event\Extension\BeforeJoomlaUpdateEvent;
use Joomla\CMS\Extension\ExtensionHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File as FileCMS;
Expand Down Expand Up @@ -576,7 +578,7 @@ public function createUpdateFile($basename = null): bool
$app = Factory::getApplication();

// Trigger event before joomla update.
$app->triggerEvent('onJoomlaBeforeUpdate');
$app->getDispatcher()->dispatch('onJoomlaBeforeUpdate', new BeforeJoomlaUpdateEvent('onJoomlaBeforeUpdate'));

// Get the absolute path to site's root.
$siteroot = JPATH_SITE;
Expand Down Expand Up @@ -882,7 +884,8 @@ public function cleanUp()
$app = Factory::getApplication();

// Trigger event after joomla update.
$app->triggerEvent('onJoomlaAfterUpdate');
// @TODO: The event dispatched twice, here and at the end of current method. One of it should be removed.
$app->getDispatcher()->dispatch('onJoomlaAfterUpdate', new AfterJoomlaUpdateEvent('onJoomlaAfterUpdate'));

// Remove the update package.
$tempdir = $app->get('tmp_path');
Expand All @@ -909,7 +912,9 @@ public function cleanUp()
$oldVersion = $app->getUserState('com_joomlaupdate.oldversion');

// Trigger event after joomla update.
$app->triggerEvent('onJoomlaAfterUpdate', [$oldVersion]);
$app->getDispatcher()->dispatch('onJoomlaAfterUpdate', new AfterJoomlaUpdateEvent('onJoomlaAfterUpdate', [
'oldVersion' => $oldVersion ?: '',
]));
$app->setUserState('com_joomlaupdate.oldversion', null);

try {
Expand Down
2 changes: 2 additions & 0 deletions libraries/src/Event/CoreEventAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ trait CoreEventAware
'onExtensionAfterSave' => Model\AfterSaveEvent::class,
'onExtensionAfterDelete' => Model\AfterDeleteEvent::class,
'onExtensionChangeState' => Model\BeforeChangeStateEvent::class,
'onJoomlaBeforeUpdate' => Extension\BeforeJoomlaUpdateEvent::class,
'onJoomlaAfterUpdate' => Extension\AfterJoomlaUpdateEvent::class,
// Installer
'onInstallerAddInstallationTab' => Installer\AddInstallationTabEvent::class,
'onInstallerBeforeInstallation' => Installer\BeforeInstallationEvent::class,
Expand Down
55 changes: 55 additions & 0 deletions libraries/src/Event/Extension/AbstractJoomlaUpdateEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\Extension;

use Joomla\CMS\Event\AbstractImmutableEvent;
use Joomla\CMS\Event\ReshapeArgumentsAware;

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

/**
* Base class for Joomla Update events
*
* @since __DEPLOY_VERSION__
*/
abstract class AbstractJoomlaUpdateEvent extends AbstractImmutableEvent
{
use ReshapeArgumentsAware;

/**
* The argument names, in order expected by legacy plugins.
*
* @var array
*
* @since __DEPLOY_VERSION__
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
*/
protected $legacyArgumentsOrder = [];

/**
* Constructor.
*
* @param string $name The event name.
* @param array $arguments The event arguments.
*
* @since __DEPLOY_VERSION__
*/
public function __construct($name, array $arguments = [])
{
// Reshape the arguments array to preserve b/c with legacy listeners
if ($this->legacyArgumentsOrder) {
$arguments = $this->reshapeArguments($arguments, $this->legacyArgumentsOrder);
}

parent::__construct($name, $arguments);
}
}
58 changes: 58 additions & 0 deletions libraries/src/Event/Extension/AfterJoomlaUpdateEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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\Extension;

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

/**
* Class for Joomla Update events
*
* @since __DEPLOY_VERSION__
*/
class AfterJoomlaUpdateEvent extends AbstractJoomlaUpdateEvent
{
/**
* The argument names, in order expected by legacy plugins.
*
* @var array
*
* @since __DEPLOY_VERSION__
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
*/
protected $legacyArgumentsOrder = ['oldVersion'];

/**
* Pre-setter for the oldVersion argument.
*
* @param ?string $value The value to set
*
* @return string
*
* @since __DEPLOY_VERSION__
*/
protected function onSetOldVersion(?string $value): string
{
return $value ?? '';
}

/**
* Getter for the oldVersion.
*
* @return string
*
* @since __DEPLOY_VERSION__
*/
public function getOldVersion(): string
{
return $this->arguments['oldVersion'] ?? '';
}
}
23 changes: 23 additions & 0 deletions libraries/src/Event/Extension/BeforeJoomlaUpdateEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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\Extension;

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

/**
* Class for Joomla Update events
*
* @since __DEPLOY_VERSION__
*/
class BeforeJoomlaUpdateEvent extends AbstractJoomlaUpdateEvent
{
}