Skip to content

Commit a32ee0a

Browse files
authored
[5.3] Convert mod_privacy_status to service provider (#44752)
* mod_privacy_status converted to service provider * load lang files and helpers in dispatch function * docblock fixed * mod_privacy_status functions order in helper * redundand get of db object removed * use db in PrivacyStatusHelper.php * application as parameter * boot module in deprecated methods * $app variable removed
1 parent efffa86 commit a32ee0a

File tree

5 files changed

+222
-54
lines changed

5 files changed

+222
-54
lines changed

administrator/modules/mod_privacy_status/mod_privacy_status.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

administrator/modules/mod_privacy_status/mod_privacy_status.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<description>MOD_PRIVACY_STATUS_XML_DESCRIPTION</description>
1212
<namespace path="src">Joomla\Module\PrivacyStatus</namespace>
1313
<files>
14-
<filename module="mod_privacy_status">mod_privacy_status.php</filename>
14+
<folder module="mod_privacy_status">services</folder>
1515
<folder>src</folder>
1616
<folder>tmpl</folder>
1717
</files>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Administrator
5+
* @subpackage mod_privacy_status
6+
*
7+
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
\defined('_JEXEC') or die;
12+
13+
use Joomla\CMS\Extension\Service\Provider\HelperFactory;
14+
use Joomla\CMS\Extension\Service\Provider\Module;
15+
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
16+
use Joomla\DI\Container;
17+
use Joomla\DI\ServiceProviderInterface;
18+
19+
/**
20+
* The privacy status module service provider.
21+
*
22+
* @since __DEPLOY_VERSION__
23+
*/
24+
return new class () implements ServiceProviderInterface {
25+
/**
26+
* Registers the service provider with a DI container.
27+
*
28+
* @param Container $container The DI container.
29+
*
30+
* @return void
31+
*
32+
* @since __DEPLOY_VERSION__
33+
*/
34+
public function register(Container $container)
35+
{
36+
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\PrivacyStatus'));
37+
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\PrivacyStatus\\Administrator\\Helper'));
38+
39+
$container->registerServiceProvider(new Module());
40+
}
41+
};
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Administrator
5+
* @subpackage mod_privacy_status
6+
*
7+
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
namespace Joomla\Module\PrivacyStatus\Administrator\Dispatcher;
12+
13+
use Joomla\CMS\Component\ComponentHelper;
14+
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
15+
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
16+
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
17+
use Joomla\Component\Privacy\Administrator\Helper\PrivacyHelper;
18+
19+
// phpcs:disable PSR1.Files.SideEffects
20+
\defined('_JEXEC') or die;
21+
// phpcs:enable PSR1.Files.SideEffects
22+
23+
/**
24+
* Dispatcher class for mod_privacy_status
25+
*
26+
* @since __DEPLOY_VERSION__
27+
*/
28+
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
29+
{
30+
use HelperFactoryAwareTrait;
31+
32+
/**
33+
* Runs the dispatcher.
34+
*
35+
* @return void
36+
*
37+
* @since __DEPLOY_VERSION__
38+
*/
39+
public function dispatch()
40+
{
41+
$app = $this->getApplication();
42+
43+
// Only super user can view this data
44+
if (!$app->getIdentity()->authorise('core.admin')) {
45+
return;
46+
}
47+
48+
// Boot component to ensure HTML helpers are loaded
49+
$app->bootComponent('com_privacy');
50+
51+
// Load the privacy component language file.
52+
$lang = $app->getLanguage();
53+
$lang->load('com_privacy', JPATH_ADMINISTRATOR)
54+
|| $lang->load('com_privacy', JPATH_ADMINISTRATOR . '/components/com_privacy');
55+
56+
parent::dispatch();
57+
}
58+
59+
/**
60+
* Returns the layout data.
61+
*
62+
* @return array
63+
*
64+
* @since __DEPLOY_VERSION__
65+
*/
66+
protected function getLayoutData()
67+
{
68+
$data = parent::getLayoutData();
69+
70+
$app = $this->getApplication();
71+
$privacyStatusHelper = $this->getHelperFactory()->getHelper('PrivacyStatusHelper');
72+
73+
$data['privacyPolicyInfo'] = $privacyStatusHelper->getPrivacyPolicyInformation($app);
74+
$data['requestFormPublished'] = $privacyStatusHelper->getRequestFormMenuStatus($app);
75+
$data['privacyConsentPluginId'] = PrivacyHelper::getPrivacyConsentPluginId();
76+
$data['sendMailEnabled'] = (bool) $app->get('mailonline', 1);
77+
$data['numberOfUrgentRequests'] = $privacyStatusHelper->getNumberOfUrgentRequests();
78+
$data['urgentRequestDays'] = (int) ComponentHelper::getParams('com_privacy')->get('notify', 14);
79+
$data['databaseConnectionEncryption'] = $privacyStatusHelper->getDatabaseConnectionEncryption();
80+
81+
return $data;
82+
}
83+
}

administrator/modules/mod_privacy_status/src/Helper/PrivacyStatusHelper.php

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010

1111
namespace Joomla\Module\PrivacyStatus\Administrator\Helper;
1212

13+
use Joomla\CMS\Application\CMSApplicationInterface;
1314
use Joomla\CMS\Component\ComponentHelper;
1415
use Joomla\CMS\Event\Privacy\CheckPrivacyPolicyPublishedEvent;
1516
use Joomla\CMS\Factory;
1617
use Joomla\CMS\Language\Multilanguage;
1718
use Joomla\CMS\Plugin\PluginHelper;
1819
use Joomla\CMS\Router\Route;
20+
use Joomla\Database\DatabaseAwareInterface;
21+
use Joomla\Database\DatabaseAwareTrait;
1922

2023
// phpcs:disable PSR1.Files.SideEffects
2124
\defined('_JEXEC') or die;
@@ -26,18 +29,22 @@
2629
*
2730
* @since 4.0.0
2831
*/
29-
class PrivacyStatusHelper
32+
class PrivacyStatusHelper implements DatabaseAwareInterface
3033
{
34+
use DatabaseAwareTrait;
35+
3136
/**
3237
* Get the information about the published privacy policy
3338
*
39+
* @param CMSApplicationInterface $app The application
40+
*
3441
* @return array Array containing a status of whether a privacy policy is set and a link to the policy document for editing
3542
*
36-
* @since 4.0.0
43+
* @since __DEPLOY_VERSION__
3744
*/
38-
public static function getPrivacyPolicyInfo()
45+
public function getPrivacyPolicyInformation(CMSApplicationInterface $app)
3946
{
40-
$dispatcher = Factory::getApplication()->getDispatcher();
47+
$dispatcher = $app->getDispatcher();
4148
$policy = [
4249
'published' => false,
4350
'articlePublished' => false,
@@ -62,11 +69,14 @@ public static function getPrivacyPolicyInfo()
6269
/**
6370
* Check whether there is a menu item for the request form
6471
*
72+
* @param CMSApplicationInterface $app The application
73+
*
6574
* @return array Array containing a status of whether a menu is published for the request form and its current link
6675
*
67-
* @since 4.0.0
76+
* @since __DEPLOY_VERSION__
77+
*
6878
*/
69-
public static function getRequestFormPublished()
79+
public function getRequestFormMenuStatus(CMSApplicationInterface $app)
7080
{
7181
$status = [
7282
'exists' => false,
@@ -75,7 +85,7 @@ public static function getRequestFormPublished()
7585
];
7686
$lang = '';
7787

78-
$db = Factory::getDbo();
88+
$db = $this->getDatabase();
7989
$query = $db->getQuery(true)
8090
->select(
8191
[
@@ -111,15 +121,14 @@ public static function getRequestFormPublished()
111121
}
112122
}
113123

114-
$linkMode = Factory::getApplication()->get('force_ssl', 0) == 2 ? Route::TLS_FORCE : Route::TLS_IGNORE;
124+
$linkMode = $app->get('force_ssl', 0) == 2 ? Route::TLS_FORCE : Route::TLS_IGNORE;
115125

116126
if (!$menuItem) {
117127
if (Multilanguage::isEnabled()) {
118128
// Find the Itemid of the home menu item tagged to the site default language
119129
$params = ComponentHelper::getParams('com_languages');
120130
$defaultSiteLanguage = $params->get('site');
121131

122-
$db = Factory::getDbo();
123132
$query = $db->getQuery(true)
124133
->select($db->quoteName('id'))
125134
->from($db->quoteName('#__menu'))
@@ -153,17 +162,17 @@ public static function getRequestFormPublished()
153162
*
154163
* @return integer
155164
*
156-
* @since 4.0.0
165+
* @since __DEPLOY_VERSION__
157166
*/
158-
public static function getNumberUrgentRequests()
167+
public function getNumberOfUrgentRequests()
159168
{
160169
// Load the parameters.
161170
$params = ComponentHelper::getComponent('com_privacy')->getParams();
162171
$notify = (int) $params->get('notify', 14);
163172
$now = Factory::getDate()->toSql();
164173
$period = '-' . $notify;
165174

166-
$db = Factory::getDbo();
175+
$db = $this->getDatabase();
167176
$query = $db->getQuery(true);
168177
$query->select('COUNT(*)')
169178
->from($db->quoteName('#__privacy_requests'))
@@ -177,4 +186,80 @@ public static function getNumberUrgentRequests()
177186

178187
return (int) $db->loadResult();
179188
}
189+
190+
/**
191+
* Method to return database encryption details
192+
*
193+
* @return string The database encryption details
194+
*
195+
* @since __DEPLOY_VERSION__
196+
*/
197+
public function getDatabaseConnectionEncryption()
198+
{
199+
return $this->getDatabase()->getConnectionEncryption();
200+
}
201+
202+
/**
203+
* Get the information about the published privacy policy
204+
*
205+
* @return array Array containing a status of whether a privacy policy is set and a link to the policy document for editing
206+
*
207+
* @since 4.0.0
208+
*
209+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
210+
* Use the non-static method getPrivacyPolicyInformation
211+
* Example: Factory::getApplication()->bootModule('mod_privacy_status', 'administrator')
212+
* ->getHelper('PrivacyStatusHelper')
213+
* ->getPrivacyPolicyInformation(Factory::getApplication())
214+
*/
215+
public static function getPrivacyPolicyInfo()
216+
{
217+
$app = Factory::getApplication();
218+
219+
return $app->bootModule('mod_privacy_status', 'administrator')
220+
->getHelper('PrivacyStatusHelper')
221+
->getPrivacyPolicyInformation($app);
222+
}
223+
224+
/**
225+
* Check whether there is a menu item for the request form
226+
*
227+
* @return array Array containing a status of whether a menu is published for the request form and its current link
228+
*
229+
* @since 4.0.0
230+
*
231+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
232+
* Use the non-static method getRequestFormMenuStatus
233+
* Example: Factory::getApplication()->bootModule('mod_privacy_status', 'administrator')
234+
* ->getHelper('PrivacyStatusHelper')
235+
* ->getRequestFormMenuStatus(Factory::getApplication())
236+
*/
237+
public static function getRequestFormPublished()
238+
{
239+
$app = Factory::getApplication();
240+
241+
return $app->bootModule('mod_privacy_status', 'administrator')
242+
->getHelper('PrivacyStatusHelper')
243+
->getRequestFormMenuStatus($app);
244+
}
245+
246+
/**
247+
* Method to return number privacy requests older than X days.
248+
*
249+
* @return integer
250+
*
251+
* @since 4.0.0
252+
*
253+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
254+
* Use the non-static method getNumberOfUrgentRequests
255+
* Example: Factory::getApplication()->bootModule('mod_privacy_status', 'administrator')
256+
* ->getHelper('PrivacyStatusHelper')
257+
* ->getNumberOfUrgentRequests()
258+
*/
259+
public static function getNumberUrgentRequests()
260+
{
261+
return Factory::getApplication()->bootModule('mod_privacy_status', 'administrator')
262+
->getHelper('PrivacyStatusHelper')
263+
->getNumberOfUrgentRequests();
264+
}
180265
}

0 commit comments

Comments
 (0)