Skip to content

Commit c6158f4

Browse files
Fediklaoneo
andauthored
[5.3] [Events] Use event classes for Privacy plugins (#43602)
* privacy consents * privacy contact * privacy content * privacy message * privacy actionlogs --------- Co-authored-by: Allon Moritz <[email protected]>
1 parent 4621c14 commit c6158f4

File tree

5 files changed

+98
-37
lines changed

5 files changed

+98
-37
lines changed

plugins/privacy/actionlogs/src/Extension/Actionlogs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function getSubscribedEvents(): array
5050
*
5151
* @since 3.9.0
5252
*/
53-
public function onPrivacyExportRequest(ExportRequestEvent $event)
53+
public function onPrivacyExportRequest(ExportRequestEvent $event): void
5454
{
5555
$user = $event->getUser();
5656

plugins/privacy/consents/src/Extension/Consents.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
namespace Joomla\Plugin\Privacy\Consents\Extension;
1212

13-
use Joomla\CMS\User\User;
13+
use Joomla\CMS\Event\Privacy\ExportRequestEvent;
1414
use Joomla\Component\Privacy\Administrator\Plugin\PrivacyPlugin;
15-
use Joomla\Component\Privacy\Administrator\Table\RequestTable;
1615
use Joomla\Database\ParameterType;
16+
use Joomla\Event\SubscriberInterface;
1717

1818
// phpcs:disable PSR1.Files.SideEffects
1919
\defined('_JEXEC') or die;
@@ -24,24 +24,39 @@
2424
*
2525
* @since 3.9.0
2626
*/
27-
final class Consents extends PrivacyPlugin
27+
final class Consents extends PrivacyPlugin implements SubscriberInterface
2828
{
29+
/**
30+
* Returns an array of events this subscriber will listen to.
31+
*
32+
* @return array
33+
*
34+
* @since __DEPLOY_VERSION__
35+
*/
36+
public static function getSubscribedEvents(): array
37+
{
38+
return [
39+
'onPrivacyExportRequest' => 'onPrivacyExportRequest',
40+
];
41+
}
42+
2943
/**
3044
* Processes an export request for Joomla core user consent data
3145
*
3246
* This event will collect data for the core `#__privacy_consents` table
3347
*
34-
* @param RequestTable $request The request record being processed
35-
* @param ?User $user The user account associated with this request if available
48+
* @param ExportRequestEvent $event The request event
3649
*
37-
* @return \Joomla\Component\Privacy\Administrator\Export\Domain[]
50+
* @return void
3851
*
3952
* @since 3.9.0
4053
*/
41-
public function onPrivacyExportRequest(RequestTable $request, ?User $user = null)
54+
public function onPrivacyExportRequest(ExportRequestEvent $event): void
4255
{
56+
$user = $event->getUser();
57+
4358
if (!$user) {
44-
return [];
59+
return;
4560
}
4661

4762
$domain = $this->createDomain('consents', 'joomla_consent_data');
@@ -60,6 +75,6 @@ public function onPrivacyExportRequest(RequestTable $request, ?User $user = null
6075
$domain->addItem($this->createItemFromArray($item));
6176
}
6277

63-
return [$domain];
78+
$event->addResult([$domain]);
6479
}
6580
}

plugins/privacy/contact/src/Extension/Contact.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
namespace Joomla\Plugin\Privacy\Contact\Extension;
1212

13-
use Joomla\CMS\User\User;
13+
use Joomla\CMS\Event\Privacy\ExportRequestEvent;
1414
use Joomla\Component\Privacy\Administrator\Plugin\PrivacyPlugin;
15-
use Joomla\Component\Privacy\Administrator\Table\RequestTable;
1615
use Joomla\Database\ParameterType;
16+
use Joomla\Event\SubscriberInterface;
1717

1818
// phpcs:disable PSR1.Files.SideEffects
1919
\defined('_JEXEC') or die;
@@ -24,26 +24,42 @@
2424
*
2525
* @since 3.9.0
2626
*/
27-
final class Contact extends PrivacyPlugin
27+
final class Contact extends PrivacyPlugin implements SubscriberInterface
2828
{
29+
/**
30+
* Returns an array of events this subscriber will listen to.
31+
*
32+
* @return array
33+
*
34+
* @since __DEPLOY_VERSION__
35+
*/
36+
public static function getSubscribedEvents(): array
37+
{
38+
return [
39+
'onPrivacyExportRequest' => 'onPrivacyExportRequest',
40+
];
41+
}
42+
2943
/**
3044
* Processes an export request for Joomla core user contact data
3145
*
3246
* This event will collect data for the contact core tables:
3347
*
3448
* - Contact custom fields
3549
*
36-
* @param RequestTable $request The request record being processed
37-
* @param ?User $user The user account associated with this request if available
50+
* @param ExportRequestEvent $event The request event
3851
*
39-
* @return \Joomla\Component\Privacy\Administrator\Export\Domain[]
52+
* @return void
4053
*
4154
* @since 3.9.0
4255
*/
43-
public function onPrivacyExportRequest(RequestTable $request, ?User $user = null)
56+
public function onPrivacyExportRequest(ExportRequestEvent $event): void
4457
{
58+
$request = $event->getRequest();
59+
$user = $event->getUser();
60+
4561
if (!$user && !$request->email) {
46-
return [];
62+
return;
4763
}
4864

4965
$domains = [];
@@ -72,6 +88,6 @@ public function onPrivacyExportRequest(RequestTable $request, ?User $user = null
7288

7389
$domains[] = $this->createCustomFieldsDomain('com_contact.contact', $items);
7490

75-
return $domains;
91+
$event->addResult($domains);
7692
}
7793
}

plugins/privacy/content/src/Extension/Content.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
namespace Joomla\Plugin\Privacy\Content\Extension;
1212

13-
use Joomla\CMS\User\User;
13+
use Joomla\CMS\Event\Privacy\ExportRequestEvent;
1414
use Joomla\Component\Privacy\Administrator\Plugin\PrivacyPlugin;
15-
use Joomla\Component\Privacy\Administrator\Table\RequestTable;
15+
use Joomla\Event\SubscriberInterface;
1616

1717
// phpcs:disable PSR1.Files.SideEffects
1818
\defined('_JEXEC') or die;
@@ -23,26 +23,41 @@
2323
*
2424
* @since 3.9.0
2525
*/
26-
final class Content extends PrivacyPlugin
26+
final class Content extends PrivacyPlugin implements SubscriberInterface
2727
{
28+
/**
29+
* Returns an array of events this subscriber will listen to.
30+
*
31+
* @return array
32+
*
33+
* @since __DEPLOY_VERSION__
34+
*/
35+
public static function getSubscribedEvents(): array
36+
{
37+
return [
38+
'onPrivacyExportRequest' => 'onPrivacyExportRequest',
39+
];
40+
}
41+
2842
/**
2943
* Processes an export request for Joomla core user content data
3044
*
3145
* This event will collect data for the content core table
3246
*
3347
* - Content custom fields
3448
*
35-
* @param RequestTable $request The request record being processed
36-
* @param ?User $user The user account associated with this request if available
49+
* @param ExportRequestEvent $event The request event
3750
*
38-
* @return \Joomla\Component\Privacy\Administrator\Export\Domain[]
51+
* @return void
3952
*
4053
* @since 3.9.0
4154
*/
42-
public function onPrivacyExportRequest(RequestTable $request, ?User $user = null)
55+
public function onPrivacyExportRequest(ExportRequestEvent $event): void
4356
{
57+
$user = $event->getUser();
58+
4459
if (!$user) {
45-
return [];
60+
return;
4661
}
4762

4863
$domains = [];
@@ -64,6 +79,6 @@ public function onPrivacyExportRequest(RequestTable $request, ?User $user = null
6479

6580
$domains[] = $this->createCustomFieldsDomain('com_content.article', $items);
6681

67-
return $domains;
82+
$event->addResult($domains);
6883
}
6984
}

plugins/privacy/message/src/Extension/Message.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
namespace Joomla\Plugin\Privacy\Message\Extension;
1212

13-
use Joomla\CMS\User\User;
13+
use Joomla\CMS\Event\Privacy\ExportRequestEvent;
1414
use Joomla\Component\Privacy\Administrator\Plugin\PrivacyPlugin;
15-
use Joomla\Component\Privacy\Administrator\Table\RequestTable;
1615
use Joomla\Database\ParameterType;
16+
use Joomla\Event\SubscriberInterface;
1717

1818
// phpcs:disable PSR1.Files.SideEffects
1919
\defined('_JEXEC') or die;
@@ -24,24 +24,39 @@
2424
*
2525
* @since 3.9.0
2626
*/
27-
final class Message extends PrivacyPlugin
27+
final class Message extends PrivacyPlugin implements SubscriberInterface
2828
{
29+
/**
30+
* Returns an array of events this subscriber will listen to.
31+
*
32+
* @return array
33+
*
34+
* @since __DEPLOY_VERSION__
35+
*/
36+
public static function getSubscribedEvents(): array
37+
{
38+
return [
39+
'onPrivacyExportRequest' => 'onPrivacyExportRequest',
40+
];
41+
}
42+
2943
/**
3044
* Processes an export request for Joomla core user message
3145
*
3246
* This event will collect data for the message table
3347
*
34-
* @param RequestTable $request The request record being processed
35-
* @param ?User $user The user account associated with this request if available
48+
* @param ExportRequestEvent $event The request event
3649
*
37-
* @return \Joomla\Component\Privacy\Administrator\Export\Domain[]
50+
* @return void
3851
*
3952
* @since 3.9.0
4053
*/
41-
public function onPrivacyExportRequest(RequestTable $request, ?User $user = null)
54+
public function onPrivacyExportRequest(ExportRequestEvent $event): void
4255
{
56+
$user = $event->getUser();
57+
4358
if (!$user) {
44-
return [];
59+
return;
4560
}
4661

4762
$domain = $this->createDomain('user_messages', 'joomla_user_messages_data');
@@ -61,6 +76,6 @@ public function onPrivacyExportRequest(RequestTable $request, ?User $user = null
6176
$domain->addItem($this->createItemFromArray($item));
6277
}
6378

64-
return [$domain];
79+
$event->addResult([$domain]);
6580
}
6681
}

0 commit comments

Comments
 (0)