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

[4.2] Convert joomla action log plugin to services #37788

Merged
merged 27 commits into from May 30, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8ec1661
Merge action log DB changes
laoneo May 13, 2022
02b0b6e
Convert joomla action log plugin to services
laoneo May 13, 2022
3b1b366
import
laoneo May 14, 2022
a4aee09
cs
laoneo May 14, 2022
24753a2
Merge branch '4.2-dev' into j4/plugins/actionlog/joomla
laoneo May 14, 2022
8c6937a
doc
laoneo May 14, 2022
bc8beb2
Merge branch 'j4/plugins/actionlog/joomla' of github.com:Digital-Peak…
laoneo May 14, 2022
f74f563
Merge branch '4.2-dev' into j4/plugins/actionlog/joomla
laoneo May 15, 2022
35acc88
cs
laoneo May 15, 2022
4f54dcc
Move to root
laoneo May 15, 2022
b987c1a
Update plugins/actionlog/joomla/services/provider.php
laoneo May 16, 2022
495be7e
doc
laoneo May 16, 2022
f74643c
Merge branch 'j4/plugins/actionlog/joomla' of github.com:Digital-Peak…
laoneo May 16, 2022
96dead5
more doc
laoneo May 16, 2022
f36344c
Merge branch '4.2-dev' into j4/plugins/actionlog/joomla
laoneo May 23, 2022
2c1a2d3
Merge branch '4.2-dev' into j4/plugins/actionlog/joomla
laoneo May 23, 2022
c49d860
Merge branch '4.2-dev' into j4/plugins/actionlog/joomla
laoneo May 24, 2022
1f03ed3
Update plugins/actionlog/joomla/services/provider.php
laoneo May 30, 2022
afaca09
Update plugins/actionlog/joomla/services/provider.php
laoneo May 30, 2022
713a149
moved to extension
laoneo May 30, 2022
fb8f8bf
Merge remote-tracking branch 'upstream/4.2-dev' into j4/plugins/actio…
laoneo May 30, 2022
12dce3a
Merge branch '4.2-dev' into j4/plugins/actionlog/joomla
laoneo May 30, 2022
a97b0f9
cs
laoneo May 30, 2022
a4aae75
Update plugins/actionlog/joomla/services/provider.php
laoneo May 30, 2022
051abe3
lower case
laoneo May 30, 2022
a878b87
Merge branch 'j4/plugins/actionlog/joomla' of github.com:Digital-Peak…
laoneo May 30, 2022
7010457
Merge branch '4.2-dev' into j4/plugins/actionlog/joomla
roland-d May 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugins/actionlog/joomla/joomla.xml
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.9.0</version>
<description>PLG_ACTIONLOG_JOOMLA_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Actionlog\Joomla</namespace>
<files>
<filename plugin="joomla">joomla.php</filename>
<folder plugin="joomla">services</folder>
laoneo marked this conversation as resolved.
Show resolved Hide resolved
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_actionlog_joomla.ini</language>
Expand Down
46 changes: 46 additions & 0 deletions plugins/actionlog/joomla/services/provider.php
@@ -0,0 +1,46 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage System.Actionlog
laoneo marked this conversation as resolved.
Show resolved Hide resolved
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Actionlog\Joomla\Joomla;

return new class implements ServiceProviderInterface {
/**
laoneo marked this conversation as resolved.
Show resolved Hide resolved
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
laoneo marked this conversation as resolved.
Show resolved Hide resolved
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container)
{
$plugin = new Joomla(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'cache'),
laoneo marked this conversation as resolved.
Show resolved Hide resolved
);
$plugin->setDatabase($container->get(DatabaseInterface::class));

return $plugin;
}
);
}
};
@@ -1,14 +1,17 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage System.actionlogs
* @subpackage System.actionlog
laoneo marked this conversation as resolved.
Show resolved Hide resolved
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Plugin\Actionlog\Joomla;

defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\Installer;
Expand All @@ -17,15 +20,30 @@
use Joomla\CMS\User\User;
use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper;
use Joomla\Component\Actionlogs\Administrator\Plugin\ActionLogPlugin;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\Exception\ExecutionFailureException;
use Joomla\Event\DispatcherInterface;
use Joomla\Utilities\ArrayHelper;
use RuntimeException;
use stdClass;

/**
* Joomla! Users Actions Logging Plugin.
*
* @since 3.9.0
*/
class PlgActionlogJoomla extends ActionLogPlugin
final class Joomla extends ActionLogPlugin
{
use DatabaseAwareTrait;

/**
* Application object.
*
* @var CMSApplicationInterface
* @since __DEPLOY_VERSION__
*/
protected $app;

/**
* Array of loggable extensions.
*
Expand Down Expand Up @@ -61,14 +79,14 @@ class PlgActionlogJoomla extends ActionLogPlugin
/**
* Constructor.
*
* @param object &$subject The object to observe.
* @param array $config An optional associative array of configuration settings.
* @param DispatcherInterface $dispatcher The dispatcher
* @param array $config An optional associative array of configuration settings
*
* @since 3.9.0
*/
public function __construct(&$subject, $config)
public function __construct(DispatcherInterface $dispatcher, array $config)
{
parent::__construct($subject, $config);
parent::__construct($dispatcher, $config);

$params = ComponentHelper::getComponent('com_actionlogs')->getParams();

Expand Down Expand Up @@ -262,7 +280,7 @@ public function onContentChangeState($context, $pks, $value)
$messageLanguageKey = $defaultLanguageKey;
}

$db = $this->db;
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName([$params->title_holder, $params->id_holder]))
->from($db->quoteName($params->table_name))
Expand Down Expand Up @@ -458,7 +476,7 @@ public function onExtensionAfterUpdate($installer, $eid)
return;
}

$manifest = $installer->get('manifest');
$manifest = $installer->get('manifest');

if ($manifest === null)
{
Expand Down Expand Up @@ -840,17 +858,18 @@ public function onUserLoginFailure($response)
}

// Get the user id for the given username
$query = $this->db->getQuery(true)
->select($this->db->quoteName(array('id', 'username')))
->from($this->db->quoteName('#__users'))
->where($this->db->quoteName('username') . ' = ' . $this->db->quote($response['username']));
$this->db->setQuery($query);
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName(array('id', 'username')))
->from($db->quoteName('#__users'))
->where($db->quoteName('username') . ' = ' . $db->quote($response['username']));
laoneo marked this conversation as resolved.
Show resolved Hide resolved
$db->setQuery($query);

try
{
$loggedInUser = $this->db->loadObject();
$loggedInUser = $db->loadObject();
}
catch (\Joomla\Database\Exception\ExecutionFailureException $e)
catch (ExecutionFailureException $e)
{
return;
}
Expand Down Expand Up @@ -993,7 +1012,7 @@ public function onAfterCheckin($table)
'userid' => $user->id,
'username' => $user->username,
'accountlink' => 'index.php?option=com_users&task=user.edit&id=' . $user->id,
'table' => str_replace($this->db->getPrefix(), '#__', $table),
'table' => str_replace($this->getDatabase()->getPrefix(), '#__', $table),
);

$this->addLog(array($message), 'PLG_ACTIONLOG_JOOMLA_USER_CHECKIN', $context, $user->id);
Expand Down Expand Up @@ -1154,7 +1173,7 @@ public function onJoomlaAfterUpdate($oldVersion = null)

if (empty($oldVersion))
{
$oldVersion = \Joomla\CMS\Language\Text::_('JLIB_UNKNOWN');
$oldVersion = $this->app->getLanguage()->_('JLIB_UNKNOWN');
}

$message = array(
Expand Down