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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 6 commits into
base: 5.2-dev
Choose a base branch
from
Open
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 joomla
  • Loading branch information
Fedik committed Jun 4, 2024
commit 5b96e476ba2ba6599389c31fe6041e9766a05bc8
1 change: 0 additions & 1 deletion plugins/extension/finder/src/Extension/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Joomla\CMS\Event\Extension\AfterInstallEvent;
use Joomla\CMS\Event\Extension\AfterUninstallEvent;
use Joomla\CMS\Event\Extension\AfterUpdateEvent;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Finder\Administrator\Indexer\Helper;
use Joomla\Database\DatabaseAwareTrait;
Expand Down
49 changes: 36 additions & 13 deletions plugins/extension/joomla/src/Extension/Joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@

namespace Joomla\Plugin\Extension\Joomla\Extension;

use Joomla\CMS\Event\Extension\AfterInstallEvent;
use Joomla\CMS\Event\Extension\AfterUninstallEvent;
use Joomla\CMS\Event\Extension\AfterUpdateEvent;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\ParameterType;
use Joomla\Event\SubscriberInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -25,7 +29,7 @@
*
* @since 1.6
*/
final class Joomla extends CMSPlugin
final class Joomla extends CMSPlugin implements SubscriberInterface
{
use DatabaseAwareTrait;

Expand All @@ -52,6 +56,22 @@ final class Joomla extends CMSPlugin
*/
protected $autoloadLanguage = true;

/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
return [
'onExtensionAfterInstall' => 'onExtensionAfterInstall',
'onExtensionAfterUpdate' => 'onExtensionAfterUpdate',
'onExtensionAfterUninstall' => 'onExtensionAfterUninstall',
];
}

/**
* Adds an update site to the table if it doesn't exist.
*
Expand Down Expand Up @@ -138,17 +158,18 @@ private function addUpdateSite($name, $type, $location, $enabled, $extraQuery =
/**
* Handle post extension install update sites
*
* @param Installer $installer Installer object
* @param integer $eid Extension Identifier
* @param AfterInstallEvent $event Event instance.
*
* @return void
*
* @since 1.6
*/
public function onExtensionAfterInstall($installer, $eid)
public function onExtensionAfterInstall(AfterInstallEvent $event): void
{
$eid = $event->getEid();

if ($eid) {
$this->installer = $installer;
$this->installer = $event->getInstaller();
$this->eid = (int) $eid;

// After an install we only need to do update sites
Expand All @@ -159,16 +180,17 @@ public function onExtensionAfterInstall($installer, $eid)
/**
* Handle extension uninstall
*
* @param Installer $installer Installer instance
* @param integer $eid Extension id
* @param boolean $removed Installation result
* @param AfterUninstallEvent $event Event instance.
*
* @return void
*
* @since 1.6
*/
public function onExtensionAfterUninstall($installer, $eid, $removed)
public function onExtensionAfterUninstall(AfterUninstallEvent $event): void
{
$eid = $event->getEid();
$removed = $event->getRemoved();

// If we have a valid extension ID and the extension was successfully uninstalled wipe out any
// update sites for it
if ($eid && $removed) {
Expand Down Expand Up @@ -240,17 +262,18 @@ public function onExtensionAfterUninstall($installer, $eid, $removed)
/**
* After update of an extension
*
* @param Installer $installer Installer object
* @param integer $eid Extension identifier
* @param AfterUpdateEvent $event Event instance.
*
* @return void
*
* @since 1.6
*/
public function onExtensionAfterUpdate($installer, $eid)
public function onExtensionAfterUpdate(AfterUpdateEvent $event): void
{
$eid = $event->getEid();

if ($eid) {
$this->installer = $installer;
$this->installer = $event->getInstaller();
$this->eid = (int) $eid;

// Handle any update sites
Expand Down