-
Notifications
You must be signed in to change notification settings - Fork 5
/
script.php
123 lines (102 loc) · 4.04 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
116
117
118
119
120
121
122
123
<?php
/**
* @package DPCalendar
* @copyright Copyright (C) 2015 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\Application\CMSWebApplicationInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Installer\InstallerScript;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\Database\DatabaseAwareInterface;
use Joomla\Database\DatabaseAwareTrait;
class Pkg_DPCalendarInstallerScript extends InstallerScript implements DatabaseAwareInterface
{
use DatabaseAwareTrait;
protected $minimumPhp = '8.1.0';
protected $minimumJoomla = '4.4.4';
protected $allowDowngrades = true;
public function preflight($type, $parent): bool
{
if (!parent::preflight($type, $parent)) {
return false;
}
// Check for the minimum Joomla 5 version before continuing
if (version_compare(JVERSION, '5.0.0', '>=') && version_compare(JVERSION, '5.1.0', '<')) {
Log::add(Text::sprintf('JLIB_INSTALLER_MINIMUM_JOOMLA', '5.1.0'), Log::WARNING, 'jerror');
return false;
}
$version = null;
$this->run("select * from `#__extensions` where element = 'pkg_dpcalendar'");
$package = $this->getDatabase()->loadObject();
if ($package) {
$info = json_decode((string)$package->manifest_cache);
if (isset($info->version)) {
$version = $info->version;
}
}
if ($version && $version != 'DP_DEPLOY_VERSION' && version_compare($version, '9.0.0') < 0) {
$app = Factory::getApplication();
if (!$app instanceof CMSWebApplicationInterface) {
return false;
}
$app->enqueueMessage(
'You have DPCalendar version ' . $version . ' installed. For this version is no automatic update available anymore, you need to have at least version 9.0.0 running. Please install the latest release from version 9 first.',
'error'
);
$app->redirect('index.php?option=com_installer&view=install');
return false;
}
return true;
}
public function update(InstallerAdapter $parent): void
{
$file = $parent->getParent()->getPath('source') . '/deleted.php';
if (file_exists($file)) {
require $file;
}
$path = JPATH_ADMINISTRATOR . '/manifests/packages/pkg_dpcalendar.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;
}
if (version_compare($version, '9.0.5') == -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=%'"
);
}
}
public function postflight(string $type): void
{
// Perform some post install tasks
if ($type === 'install') {
$this->run("update `#__extensions` set enabled = 1 where type = 'plugin' and element = 'dpcalendar'");
$this->run("update `#__extensions` set enabled = 1 where type = 'plugin' and element = 'manual'");
$this->run(
"insert ignore into `#__modules_menu` (menuid, moduleid) select 0 as menuid, id as moduleid from `#__modules` where module like 'mod_dpcalendar%'"
);
}
// Make sure the installer plugin is enabled
$this->run("update `#__extensions` set enabled = 1 where name = 'plg_installer_dpcalendar'");
}
private function run(string $query): void
{
try {
$db = $this->getDatabase();
$db->setQuery($query);
$db->execute();
} catch (Exception $exception) {
Factory::getApplication()->enqueueMessage($exception->getMessage(), 'error');
}
}
}