-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathupdatescript.php
More file actions
116 lines (107 loc) · 3.92 KB
/
Copy pathupdatescript.php
File metadata and controls
116 lines (107 loc) · 3.92 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/*
* @package BFStop Plugin (bfstop) for Joomla!
* @author Bernhard Froehler
* @copyright (C) Bernhard Froehler
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
**/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
class PlgsystembfstopInstallerScript
{
public function __construct(InstallerAdapter $adapter) {}
public function install(InstallerAdapter $adapter)
{
// plugins install disabled by default, but bfstop only does anything
// useful while running, and all its settings now live in the
// component - so there's nothing left to configure before enabling it.
$db = Factory::getDbo();
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('enabled') . ' = 1')
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('bfstop'));
$db->setQuery($query);
$db->execute();
}
public function uninstall(InstallerAdapter $adapter) {}
public function preflight($type, InstallerAdapter $adapter) {}
public function postflight($type, InstallerAdapter $adapter)
{
if ($type === 'update')
{
$lang = Factory::getLanguage();
$lang->load('plg_system_bfstop', JPATH_ADMINISTRATOR);
Factory::getApplication()->enqueueMessage(
Text::sprintf('PLG_SYSTEM_BFSTOP_UPDATE_2_0_0_HINT', Route::_('index.php?option=com_bfstop&view=settings', false)),
'warning'
);
}
}
public function update(InstallerAdapter $adapter)
{
// for version 1.4.2, whitelist was renamed to allowlist, but only for updates;
// for new installs, the old name remained, so let's fix this for all installations:
$db = Factory::getDbo();
try
{
$sql = "SELECT COUNT(*) FROM `#__bfstop_whitelist`";
$db->setQuery($sql);
$numEntries = ((int)$db->loadResult());
$sql = "RENAME TABLE `#__bfstop_whitelist` TO `#__bfstop_allowlist`";
$db->setQuery($sql);
$db->execute();
}
catch (Exception $e)
{
// if table doesn't exist, there's nothing we need to do
// Log::add("Update ERROR: ".$e->getMessage(), Log::ERROR, 'Update');
}
// for 2.0.0, the previously separate blockEnabled/useHtaccess switches
// and the (never released) two-value blockMode were unified into a
// single four-value blockMode setting (#187); every real install still
// has the old pre-2.0 config, so migrate it once into the equivalent
// unified value
try
{
$query = $db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('bfstop'));
$db->setQuery($query);
$params = json_decode((string) $db->loadResult(), true);
if (is_array($params) && !array_key_exists('blockMode', $params))
{
$newMode = 'full';
if (array_key_exists('blockEnabled', $params) && (string) $params['blockEnabled'] === '0')
{
$newMode = 'off';
}
elseif (array_key_exists('useHtaccess', $params) && (string) $params['useHtaccess'] === '1')
{
$newMode = 'htaccess';
}
$params['blockMode'] = $newMode;
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = ' . $db->quote(json_encode($params)))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('bfstop'));
$db->setQuery($query);
$db->execute();
}
}
catch (Exception $e)
{
// if the extension row can't be found/updated, there's nothing we can do
// Log::add("Update ERROR: ".$e->getMessage(), Log::ERROR, 'Update');
}
}
}