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 Actionlog plugins #43639

Open
wants to merge 6 commits into
base: 5.2-dev
Choose a base branch
from
Open
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
actionlog
  • Loading branch information
Fedik committed Jun 9, 2024
commit 883700f4fb8fa1e2d27077a09b1d01404870668a
80 changes: 46 additions & 34 deletions plugins/actionlog/joomla/src/Extension/Joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
namespace Joomla\Plugin\Actionlog\Joomla\Extension;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Application;
use Joomla\CMS\Event\Extension;
use Joomla\CMS\Event\Model;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\MVC\Factory\MVCFactoryServiceInterface;
use Joomla\CMS\Table\Table;
Expand Down Expand Up @@ -134,16 +137,18 @@ public static function getSubscribedEvents(): array
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called right after the content is saved
*
* @param string $context The context of the content passed to the plugin
* @param object $article A \Joomla\CMS\Table\Table object
* @param boolean $isNew If the content is just about to be created
* @param Model\AfterSaveEvent $event The event instance.
*
* @return void
*
* @since 3.9.0
*/
public function onContentAfterSave($context, $article, $isNew): void
public function onContentAfterSave(Model\AfterSaveEvent $event): void
{
$context = $event->getContext();
$article = $event->getItem();
$isNew = $event->getIsNew();

if (isset($this->contextAliases[$context])) {
$context = $this->contextAliases[$context];
}
Expand Down Expand Up @@ -192,16 +197,17 @@ public function onContentAfterSave($context, $article, $isNew): void
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called right after the content is deleted
*
* @param string $context The context of the content passed to the plugin
* @param object $article A \Joomla\CMS\Table\Table object
* @param Model\AfterDeleteEvent $event The event instance.
*
* @return void
*
* @since 3.9.0
*/
public function onContentAfterDelete($context, $article): void
public function onContentAfterDelete(Model\AfterDeleteEvent $event): void
{
$option = $this->getApplication()->getInput()->get('option');
$context = $event->getContext();
$article = $event->getItem();
$option = $this->getApplication()->getInput()->get('option');

if (!$this->checkLoggable($option)) {
return;
Expand Down Expand Up @@ -238,17 +244,18 @@ public function onContentAfterDelete($context, $article): void
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called when the status of the article is changed
*
* @param string $context The context of the content passed to the plugin
* @param array $pks An array of primary key ids of the content that has changed state.
* @param integer $value The value of the state that the content has been changed to.
* @param Model\AfterChangeStateEvent $event The event instance.
*
* @return void
*
* @since 3.9.0
*/
public function onContentChangeState($context, $pks, $value)
public function onContentChangeState(Model\AfterChangeStateEvent $event): void
{
$option = $this->getApplication()->getInput()->getCmd('option');
$context = $event->getContext();
$pks = $event->getPks();
$value = $event->getValue();
$option = $this->getApplication()->getInput()->getCmd('option');

if (!$this->checkLoggable($option)) {
return;
Expand Down Expand Up @@ -327,16 +334,16 @@ public function onContentChangeState($context, $pks, $value)
}

/**
* On Saving application configuration logging method
* On Saving application configuration logging method.
* Method is called when the application config is being saved
*
* @param \Joomla\Registry\Registry $config Registry object with the new config
* @param Application\AfterSaveConfigurationEvent $event The event instance.
*
* @return void
*
* @since 3.9.0
*/
public function onApplicationAfterSave($config): void
public function onApplicationAfterSave(Application\AfterSaveConfigurationEvent $event): void
{
$option = $this->getApplication()->getInput()->getCmd('option');

Expand All @@ -362,16 +369,17 @@ public function onApplicationAfterSave($config): void
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called when an extension is installed
*
* @param Installer $installer Installer object
* @param integer $eid Extension Identifier
* @param Extension\AfterInstallEvent $event The event instance.
*
* @return void
*
* @since 3.9.0
*/
public function onExtensionAfterInstall($installer, $eid)
public function onExtensionAfterInstall(Extension\AfterInstallEvent $event): void
{
$context = $this->getApplication()->getInput()->get('option');
$installer = $event->getInstaller();
$eid = $event->getEid();
$context = $this->getApplication()->getInput()->get('option');

if (!$this->checkLoggable($context)) {
return;
Expand Down Expand Up @@ -408,17 +416,18 @@ public function onExtensionAfterInstall($installer, $eid)
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called when an extension is uninstalled
*
* @param Installer $installer Installer instance
* @param integer $eid Extension id
* @param integer $result Installation result
* @param Extension\AfterUninstallEvent $event The event instance.
*
* @return void
*
* @since 3.9.0
*/
public function onExtensionAfterUninstall($installer, $eid, $result)
public function onExtensionAfterUninstall(Extension\AfterUninstallEvent $event): void
{
$context = $this->getApplication()->getInput()->get('option');
$installer = $event->getInstaller();
$eid = $event->getEid();
$result = $event->getRemoved();
$context = $this->getApplication()->getInput()->get('option');

if (!$this->checkLoggable($context)) {
return;
Expand Down Expand Up @@ -460,16 +469,17 @@ public function onExtensionAfterUninstall($installer, $eid, $result)
* This method adds a record to #__action_logs contains (message, date, context, user)
* Method is called when an extension is updated
*
* @param Installer $installer Installer instance
* @param integer $eid Extension id
* @param Extension\AfterUpdateEvent $event The event instance.
*
* @return void
*
* @since 3.9.0
*/
public function onExtensionAfterUpdate($installer, $eid)
public function onExtensionAfterUpdate(Extension\AfterUpdateEvent $event): void
{
$context = $this->getApplication()->getInput()->get('option');
$installer = $event->getInstaller();
$eid = $event->getEid();
$context = $this->getApplication()->getInput()->get('option');

if (!$this->checkLoggable($context)) {
return;
Expand Down Expand Up @@ -502,19 +512,21 @@ public function onExtensionAfterUpdate($installer, $eid)
}

/**
* On Saving extensions logging method
* On Saving extensions logging method.
* Method is called when an extension is being saved
*
* @param string $context The extension
* @param Table $table DataBase Table object
* @param boolean $isNew If the extension is new or not
* @param Model\AfterSaveEvent $event The event instance.
*
* @return void
*
* @since 3.9.0
*/
public function onExtensionAfterSave($context, $table, $isNew): void
public function onExtensionAfterSave(Model\AfterSaveEvent $event): void
{
$context = $event->getContext();
$table = $event->getItem();
$isNew = $event->getIsNew();

$option = $this->getApplication()->getInput()->getCmd('option');

if ($table->get('module') != null) {
Expand Down