-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathscript.php
More file actions
133 lines (112 loc) · 4.03 KB
/
Copy pathscript.php
File metadata and controls
133 lines (112 loc) · 4.03 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* @package Joomla.JEDChecker
*
* @author Daniel Dimitrov <daniel@compojoom.com>
* @copyright Copyright (C) 2017 - 2026 Open Source Matters, Inc. All rights reserved.
* Copyright (C) 2008 - 2016 compjoom.com All rights reserved.
*
* @license GNU General Public Licence version 2 or later; see LICENCE.txt
*/
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\Adapter\ComponentAdapter;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Folder;
/**
* Class Com_JedcheckerInstallerScript
*
* @since 1.5
*/
class Com_JedcheckerInstallerScript
{
protected $extension = 'com_jedchecker';
protected $min_php = '8.1.0';
protected $min_joomla = '4.3.0';
protected $parent;
/**
* Function executed before the the installation
*
* @param string $type - the installation type
* @param ComponentAdapter $parent - the parent class
*/
public function preflight($type, $parent)
{
$this->parent = $parent;
if (version_compare(PHP_VERSION, $this->min_php, '<')) {
$this->loadLanguage();
$msg = Text::sprintf('COM_JEDCHECKER_PHP_VERSION_INCOMPATIBLE', PHP_VERSION, $this->min_php);
Log::add($msg, Log::WARNING, 'jerror');
return false;
}
if (version_compare(JVERSION, $this->min_joomla, '<')) {
$this->loadLanguage();
$msg = Text::sprintf('COM_JEDCHECKER_JOOMLA_VERSION_INCOMPATIBLE', JVERSION, $this->min_joomla);
Log::add($msg, Log::WARNING, 'jerror');
return false;
}
}
/**
* Load language necessary during the installation
*
* @return void
*/
public function loadLanguage()
{
$extension = $this->extension;
$jlang = Factory::getApplication()->getLanguage();
$path = $this->parent->getParent()->getPath('source') . '/administrator/components/' . $extension;
$jlang->load($extension, $path, 'en-GB', true);
$jlang->load($extension, $path, $jlang->getDefault(), true);
$jlang->load($extension, $path, null, true);
$jlang->load($extension . '.sys', $path, 'en-GB', true);
$jlang->load($extension . '.sys', $path, $jlang->getDefault(), true);
$jlang->load($extension . '.sys', $path, null, true);
}
/**
* Update cleans out legacy directories and old rules.
*
* @param ComponentAdapter $parent Is the class calling this method.
*
* @return bool|null If this returns false, Joomla will abort the update and undo everything already done.
*/
public function update($parent)
{
$this->loadLanguage();
$componentPath = JPATH_ADMINISTRATOR . '/components/' . $this->extension;
// Remove legacy top-level files replaced by src/ structure
$legacyFiles = [
$componentPath . '/controller.php',
$componentPath . '/jedchecker.php',
];
foreach ($legacyFiles as $legacyFile) {
if (file_exists($legacyFile)) {
File::delete($legacyFile);
}
}
// Remove legacy directories replaced by src/ structure
$legacyDirs = [
$componentPath . '/controllers',
$componentPath . '/models',
$componentPath . '/libraries',
$componentPath . '/views',
];
foreach ($legacyDirs as $legacyDir) {
if (is_dir($legacyDir)) {
Folder::delete($legacyDir);
}
}
// Remove any old individual rules that are no longer included
$oldRules = ['htmlindexes'];
foreach ($oldRules as $rule) {
$rulePhpFile = $componentPath . '/src/Rule/Rules/' . ucfirst($rule) . 'Rule.php';
if (file_exists($rulePhpFile)) {
File::delete($rulePhpFile);
}
}
}
}