-
Notifications
You must be signed in to change notification settings - Fork 4
/
script.php
78 lines (69 loc) · 2.09 KB
/
script.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
<?php
/**
* @package plg_user_regauth
* @copyright Copyright (C) 2022-2024 RJCreations. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE.txt
* @since 1.5.0
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
class plgUserRegauthInstallerScript
{
protected $minimumJoomla = '4.0';
protected $deleteFiles = ['/plugins/user/regauth/regauth.php'];
public function install ($parent)
{
$this->convertParams();
return true;
}
public function uninstall ($parent)
{
return true;
}
public function update ($parent)
{
$this->convertParams();
// get the version number being installed/updated
if (method_exists($parent,'getManifest')) {
$version = $parent->getManifest()->version;
} else {
$version = $parent->get('manifest')->version;
}
echo '<p>The <em>regauth</em> plugin has been updated to version' . $version . '.</p>';
return true;
}
public function preflight ($type, $parent)
{
return true;
}
public function postflight ($type, $parent)
{
if ($type === 'update') {
$this->removeFiles();
}
return true;
}
// convert any old plugin parameters to new style
private function convertParams ()
{
$db = Factory::getDbo();
$db->setQuery("SELECT params FROM #__extensions WHERE name = 'plg_user_regauth'");
$json = $db->loadResult();
if ($json) {
$prms = json_decode($json, true);
if (isset($prms['authcode1'])) {
$authcodes = [];
foreach (['authcode1','authcode2','authcode3','authcode4','authcode5','authcode6'] as $c) {
if (!empty($prms[$c])) {
$k = substr($c, -1);
$authcodes['authcode'.$k] = ['code'=>$prms[$c]];
if (!empty($prms['groups'.$k])) $authcodes['authcode'.$k]['groups'] = $prms['groups'.$k];
}
}
$db->setQuery("UPDATE #__extensions SET params = ".$db->quote(json_encode(['authcode' => $authcodes]))." WHERE name = 'plg_user_regauth'");
$db->query();
Factory::getApplication()->enqueueMessage('The <em>regauth</em> plugin parameters have been upgraded to a new format. Please ensure that the plugin configuration is correct.', 'warning');
}
}
}
}