-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.php
115 lines (92 loc) · 3.83 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
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
<?php
/**
* @package DPMedia
* @copyright Copyright (C) 2021 Digital Peak GmbH. <https://www.digital-peak.com>
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
*/
\defined('_JEXEC') or die();
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\DatabaseAwareInterface;
use Joomla\Database\DatabaseAwareTrait;
return new class () implements InstallerScriptInterface, DatabaseAwareInterface {
use DatabaseAwareTrait;
private string $minimumPhp = '8.1.0';
private string $minimumJoomla = '4.4.0';
public function install(InstallerAdapter $adapter): bool
{
return true;
}
public function update(InstallerAdapter $adapter): bool
{
$file = $adapter->getParent()->getPath('source') . '/deleted.php';
if (file_exists($file)) {
require $file;
}
$path = JPATH_ADMINISTRATOR . '/manifests/packages/pkg_dpmedia.xml';
$version = null;
if (file_exists($path)) {
$manifest = simplexml_load_file($path);
$version = $manifest instanceof SimpleXMLElement ? (string)$manifest->version : null;
}
if ($version === null || $version === '' || $version === '0' || $version === 'DP_DEPLOY_VERSION') {
return true;
}
if (version_compare($version, '1.10.0') == -1) {
$this->run("update #__extensions set package_id = 0
where package_id = (select * from (select extension_id from #__extensions where element ='pkg_dpmedia') as e)
and name not in ('lib_dpmedia', 'plg_content_dpmedia', 'plg_installer_dpmedia', 'plg_user_dpmedia')");
}
if (version_compare($version, '1.14.0') == -1) {
$this->run(
"UPDATE `#__update_sites` SET location=replace(location,'&ext=extension.xml','') where location like 'https://joomla.digital-peak.com/index.php?option=com_ars&view=update&task=stream&format=xml&id=%'"
);
$this->run(
"UPDATE `#__update_sites` SET location=replace(location,'https://joomla.digital-peak.com/index.php?option=com_ars&view=update&task=stream&format=xml&id=','https://cdn.digital-peak.com/update/stream.php?id=') where location like 'https://joomla.digital-peak.com/index.php?option=com_ars&view=update&task=stream&format=xml&id=%'"
);
}
return true;
}
public function uninstall(InstallerAdapter $adapter): bool
{
return true;
}
public function preflight(string $type, InstallerAdapter $adapter): bool
{
if (version_compare(PHP_VERSION, $this->minimumPhp, '<')) {
Log::add(\sprintf(Text::_('JLIB_INSTALLER_MINIMUM_PHP'), $this->minimumPhp), Log::WARNING, 'jerror');
return false;
}
if (version_compare(JVERSION, $this->minimumJoomla, '<')) {
Log::add(\sprintf(Text::_('JLIB_INSTALLER_MINIMUM_JOOMLA'), $this->minimumJoomla), Log::WARNING, 'jerror');
return false;
}
return true;
}
public function postflight(string $type, InstallerAdapter $adapter): bool
{
// Perform some post install tasks
if ($type === 'install' || $type === 'discover_install') {
$this->run("update `#__extensions` set enabled=1 where type = 'plugin' and element like 'dp%' and folder like 'media-action'");
$this->run("update `#__extensions` set enabled=1 where type = 'plugin' and name = 'plg_filesystem_dprestricted'");
$this->run("update `#__extensions` set enabled=1 where type = 'plugin' and name = 'plg_content_dpmedia'");
$this->run("update `#__extensions` set enabled=1 where type = 'plugin' and name = 'plg_user_dpmedia'");
}
// Make sure the installer plugin is enabled
$this->run("update `#__extensions` set enabled = 1 where name = 'plg_installer_dpmedia'");
return true;
}
private function run(string $query): void
{
try {
$db = $this->getDatabase();
$db->setQuery($query);
$db->execute();
} catch (Exception $exception) {
Factory::getApplication()->enqueueMessage($exception->getMessage(), 'error');
}
}
};