-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.php
103 lines (87 loc) · 2.9 KB
/
updater.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* CleanTalk joomla updater file
*
* @since 2.2
* @package Cleantalk
* @subpackage Joomla
* @author CleanTalk (welcome@cleantalk.org)
* @copyright (C) 2021 СleanTalk team (http://cleantalk.org)
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
*
*/
defined('_JEXEC') or die('Restricted access');
class plgsystemcleantalkantispamInstallerScript
{
public function preflight($type, $parent)
{
}
public function install($parent)
{
}
public function update($parent)
{
}
public function postflight($type, $parent)
{
// Updating roles_exclusion
$excluded_roles = $this->getParam('roles_exclusions');
if (is_array($excluded_roles)) {
$default_roles = self::getGroups();
$new_data_roles_excluded = array();
foreach ($default_roles as $default_role) {
if (in_array(strtolower($default_role->id), $excluded_roles)) {
$new_data_roles_excluded[] = strtolower($default_role->title);
}
}
$params['roles_exclusions'] = implode(',', $new_data_roles_excluded);
$this->setParams($params);
}
}
public function uninstall($parent)
{
}
/**
* Get all user groups
*/
static private function getGroups()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query
->select(array('*'))
->from($db->quoteName('#__usergroups'));
$db->setQuery($query);
return $db->loadObjectList();
}
/*
* get a variable from the manifest file (actually, from the manifest cache).
*/
function getParam( $name ) {
$db = JFactory::getDbo();
$db->setQuery('SELECT params FROM #__extensions WHERE element = "cleantalkantispam"');
$params = json_decode( $db->loadResult(), true );
return $params[ $name ];
}
/*
* sets parameter values in the component's row of the extension table
*/
function setParams($param_array) {
if ( count($param_array) > 0 ) {
// read the existing component value(s)
$db = JFactory::getDbo();
$db->setQuery('SELECT params FROM #__extensions WHERE element = "cleantalkantispam"');
$params = json_decode( $db->loadResult(), true );
// add the new variable(s) to the existing one(s)
foreach ( $param_array as $name => $value ) {
$params[ (string) $name ] = (string) $value;
}
// store the combined new and existing values back as a JSON string
$paramsString = json_encode( $params );
$db->setQuery('UPDATE #__extensions SET params = ' .
$db->quote( $paramsString ) .
' WHERE element = "cleantalkantispam"' );
$db->query();
}
}
}