first commit
This commit is contained in:
21
plugins/privacy/actionlogs/actionlogs.xml
Normal file
21
plugins/privacy/actionlogs/actionlogs.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="privacy" method="upgrade">
|
||||
<name>plg_privacy_actionlogs</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2018-07</creationDate>
|
||||
<copyright>(C) 2018 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>3.9.0</version>
|
||||
<description>PLG_PRIVACY_ACTIONLOGS_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Privacy\Actionlogs</namespace>
|
||||
<files>
|
||||
<folder plugin="actionlogs">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_privacy_actionlogs.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_privacy_actionlogs.sys.ini</language>
|
||||
</languages>
|
||||
</extension>
|
||||
48
plugins/privacy/actionlogs/services/provider.php
Normal file
48
plugins/privacy/actionlogs/services/provider.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Privacy.actionlogs
|
||||
*
|
||||
* @copyright (C) 2023 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\Factory;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Database\DatabaseInterface;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
use Joomla\Plugin\Privacy\Actionlogs\Extension\Actionlogs;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
public function register(Container $container): void
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$plugin = new Actionlogs(
|
||||
$container->get(DispatcherInterface::class),
|
||||
(array) PluginHelper::getPlugin('privacy', 'actionlogs')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
$plugin->setDatabase($container->get(DatabaseInterface::class));
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
96
plugins/privacy/actionlogs/src/Extension/Actionlogs.php
Normal file
96
plugins/privacy/actionlogs/src/Extension/Actionlogs.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Privacy.actionlogs
|
||||
*
|
||||
* @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\Privacy\Actionlogs\Extension;
|
||||
|
||||
use Joomla\CMS\Event\Privacy\ExportRequestEvent;
|
||||
use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper;
|
||||
use Joomla\Component\Privacy\Administrator\Plugin\PrivacyPlugin;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\Event\SubscriberInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Privacy plugin managing Joomla actionlogs data
|
||||
*
|
||||
* @since 3.9.0
|
||||
*/
|
||||
final class Actionlogs extends PrivacyPlugin implements SubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Returns an array of events this subscriber will listen to.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'onPrivacyExportRequest' => 'onPrivacyExportRequest',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes an export request for Joomla core actionlog data
|
||||
*
|
||||
* @param ExportRequestEvent $event The request event
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.9.0
|
||||
*/
|
||||
public function onPrivacyExportRequest(ExportRequestEvent $event)
|
||||
{
|
||||
$user = $event->getUser();
|
||||
|
||||
// RequestTable $request, User $user = null
|
||||
if (!$user) {
|
||||
return;
|
||||
}
|
||||
|
||||
$domain = $this->createDomain('user_action_logs', 'joomla_user_action_logs_data');
|
||||
$db = $this->getDatabase();
|
||||
$userId = (int) $user->id;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select(['a.*', $db->quoteName('u.name')])
|
||||
->from($db->quoteName('#__action_logs', 'a'))
|
||||
->join('INNER', $db->quoteName('#__users', 'u'), $db->quoteName('a.user_id') . ' = ' . $db->quoteName('u.id'))
|
||||
->where($db->quoteName('a.user_id') . ' = :id')
|
||||
->bind(':id', $userId, ParameterType::INTEGER);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
$data = $db->loadObjectList();
|
||||
|
||||
if (!\count($data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = ActionlogsHelper::getCsvData($data);
|
||||
$isFirst = true;
|
||||
|
||||
foreach ($data as $item) {
|
||||
if ($isFirst) {
|
||||
$isFirst = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$domain->addItem($this->createItemFromArray($item));
|
||||
}
|
||||
|
||||
$event->addResult([$domain]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user