-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.php
More file actions
101 lines (91 loc) · 3.97 KB
/
script.php
File metadata and controls
101 lines (91 loc) · 3.97 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
<?php
/**
* @package plg_system_extensiontools
* @subpackage System.Extensiontools
* @version 24.02.01
* @copyright 2024 - 2025 Bram Brambring (https://brambring.nl)
* @license GNU General Public License version 3 or later;
*/
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Installer\InstallerScriptInterface;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
// phpcs:disable PSR12.Classes.AnonClassDeclaration
return new class () implements
ServiceProviderInterface {
// phpcs:enable PSR12.Classes.AnonClassDeclaration
public function register(Container $container)
{
$container->set(
InstallerScriptInterface::class,
// phpcs:disable PSR12.Classes.AnonClassDeclaration
new class () implements
InstallerScriptInterface {
// phpcs:enable PSR12.Classes.AnonClassDeclaration
private readonly DatabaseInterface $db;
private $minimumJoomlaVersion = '5.1';
private $minimumPHPVersion = '8.1';
public function __construct()
{
$this->db = Factory::getContainer()->get(DatabaseInterface::class);
}
public function install(InstallerAdapter $adapter): bool
{
$query = $this->db->getquery(true);
$query->update($this->db->quoteName('#__extensions'))
->set($this->db->quoteName('enabled') . ' = 1')
->where($this->db->quoteName('type') . ' = ' . $this->db->quote('plugin'))
->where($this->db->quoteName('folder') . ' = ' . $this->db->quote($adapter->group))
->where($this->db->quoteName('element') . ' = ' . $this->db->quote($adapter->element));
$this->db->setQuery($query)->execute();
return true;
}
public function update(InstallerAdapter $adapter): bool
{
return true;
}
public function uninstall(InstallerAdapter $adapter): bool
{
return true;
}
public function preflight(string $type, InstallerAdapter $adapter): bool
{
if ($type !== 'uninstall') {
// Check for the minimum PHP version before continuing
if (version_compare(PHP_VERSION, $this->minimumPHPVersion, '<')) {
Log::add(
Text::sprintf('JLIB_INSTALLER_MINIMUM_PHP', $this->minimumPHPVersion),
Log::ERROR,
'jerror'
);
return false;
}
// Check for the minimum Joomla version before continuing
if (version_compare(JVERSION, $this->minimumJoomlaVersion, '<')) {
Log::add(
Text::sprintf('JLIB_INSTALLER_MINIMUM_JOOMLA', $this->minimumJoomlaVersion)
. '<br><br>' .
Text::_('PLG_SYSTEM_EXTENSIONTOOLS_OLDER', $this->minimumJoomlaVersion),
Log::ERROR,
'jerror'
);
return false;
}
}
return true;
}
public function postflight(string $type, InstallerAdapter $adapter): bool
{
return true;
}
}
);
}
};