-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscriptfile.php
137 lines (117 loc) · 3.11 KB
/
scriptfile.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
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
// No direct access to this file
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\Filesystem\Folder;
use Joomla\CMS\Version;
use Joomla\Filesystem\File;
class plgContentAutoreadmoreInstallerScript {
private $extname = 'autoreadmore';
private $min_joomla_version = '3.10.0';
private $min_php_version = '7.2';
private $dir;
private $lang;
public function __construct()
{
$this->dir = __DIR__;
$this->lang = Factory::getLanguage();
$this->lang->load($this->extname);
}
/**
* method to run before an install/update/uninstall method
*
* @return void
*/
function preflight($type, $parent) {
if ( ! $this->passMinimumJoomlaVersion())
{
$this->uninstallInstaller();
return false;
}
if ( ! $this->passMinimumPHPVersion())
{
$this->uninstallInstaller();
return false;
}
}
/**
* method to run after an install/update/uninstall method
*
* @return void
*/
function postflight($type, $parent) {
if (($type=='install') || ($type == 'update')) { // remove obsolete dir/files
$this->postinstall_cleanup();
$this->enable_plugin();
}
return true;
}
private function postinstall_cleanup() {
$obsloteFolders = ['extensions', 'images','language','helpers'];
// Remove plugins' files which load outside of the component. If any is not fully updated your site won't crash.
foreach ($obsloteFolders as $folder)
{
$f = JPATH_SITE . '/plugins/content/'.$this->extname.'/' . $folder;
if (!@file_exists($f) || !is_dir($f) || is_link($f))
{
continue;
}
Folder::delete($f);
}
$obsloteFiles = [sprintf("%s/plugins/content/%s/scriptary.php", JPATH_SITE, $this->extname)];
foreach ($obsloteFiles as $file)
{
if (@is_file($file))
{
File::delete($file);
}
}
}
private function enable_plugin() {
$db = Factory::getDbo();
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('enabled') . ' = ' . $db->quote(1))
->where($db->quoteName('element') . ' = ' . $db->quote($this->extname));
$db->setQuery($query);
try
{
$db->execute();
}
catch (RuntimeException $e)
{
echo Text::_('Error while enabling '.$this->extname);
return;
}
}
// Check if Joomla version passes minimum requirement
private function passMinimumJoomlaVersion()
{
$j = new Version();
$version=$j->getShortVersion();
if (version_compare($version, $this->min_joomla_version, '<'))
{
Factory::getApplication()->enqueueMessage(
'Incompatible Joomla version : found <strong>' . $version . '</strong>, Minimum : <strong>' . $this->min_joomla_version . '</strong>',
'error'
);
return false;
}
return true;
}
// Check if PHP version passes minimum requirement
private function passMinimumPHPVersion()
{
if (version_compare(PHP_VERSION, $this->min_php_version, '<'))
{
Factory::getApplication()->enqueueMessage(
'Incompatible PHP version : found <strong>' . PHP_VERSION . '</strong>, Minimum <strong>' . $this->min_php_version . '</strong>',
'error'
);
return false;
}
return true;
}
}
?>