-
Notifications
You must be signed in to change notification settings - Fork 8
/
script.php
196 lines (174 loc) · 6.63 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/**
* @package Joomla.Site
* @subpackage Templates.nature
*
* @copyright (C) 2021 Dr. Menzel IT. <https://www.dr-menzel-it.de>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Installer\InstallerScript;
use Joomla\CMS\Language\Text;
/**
* Installation class to perform additional changes during install/uninstall/update
*
* @since 1.0.6v1
*/
class NatureInstallerScript extends InstallerScript
{
/**
* Move nature template (s)css or js or image files which are left after deleting
* obsolete core files to the right place in media folder.
*
* @return void
*
* @since 4.1.0
*/
protected function moveTemplateFiles()
{
$folders = [
'/templates/nature/css' => '/media/templates/site/nature/css',
'/templates/nature/images' => '/media/templates/site/nature/images',
'/templates/nature/js' => '/media/templates/site/nature/js',
'/templates/nature/fonts' => '/media/templates/site/nature/fonts',
];
foreach ($folders as $oldFolder => $newFolder)
{
if (Folder::exists(JPATH_ROOT . $oldFolder))
{
$oldPath = realpath(JPATH_ROOT . $oldFolder);
$newPath = realpath(JPATH_ROOT . $newFolder);
$directory = new \RecursiveDirectoryIterator($oldPath);
$directory->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
$iterator = new \RecursiveIteratorIterator($directory);
// Handle all files in this folder and all sub-folders
foreach ($iterator as $oldFile)
{
if ($oldFile->isDir())
{
continue;
}
$newFile = $newPath . substr($oldFile, strlen($oldPath));
// Create target folder and parent folders if they don't exist yet
if (is_dir(dirname($newFile)) || @mkdir(dirname($newFile), 0755, true))
{
File::move($oldFile, $newFile);
}
}
}
}
}
/**
* Ensure the core templates are correctly moved to the new mode.
*
* @return void
*
* @since 4.1.0
*/
protected function fixTemplateMode(): void
{
$db = Factory::getContainer()->get('DatabaseDriver');
$template = 'nature';
$clientId = 0;
$query = $db->getQuery(true)
->update($db->quoteName('#__template_styles'))
->set($db->quoteName('inheritable') . ' = 1')
->where($db->quoteName('template') . ' = ' . $db->quote($template))
->where($db->quoteName('client_id') . ' = ' . $clientId);
try
{
$db->setQuery($query)->execute();
}
catch (Exception $e)
{
echo Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br>';
return;
}
}
/**
* Function to perform changes during postflight
*
* @param string $type The action being performed
* @param Installer $installer The class calling this method
*
* @return void
*
* @since 1.0.6v1
*/
public function postflight($type, $installer)
{
if ($type == 'update')
{
$foldersBefore = array(
'/templates/nature/css/global',
'/templates/nature/css/system',
'/templates/nature/css/vendor',
'/templates/nature/images'
);
$folders = array(
'/templates/nature/css',
'/templates/nature/fonts',
'/templates/nature/js',
);
$files = array(
'/templates/nature/css/bootstrap-icons.css',
'/templates/nature/css/bootstrap-icons.min.css',
'/templates/nature/css/icons.css',
'/templates/nature/css/icons.min.css',
'/templates/nature/css/metismenu.css',
'/templates/nature/css/metismenu.min.css',
'/templates/nature/css/offline.css',
'/templates/nature/css/offline.min.css',
'/templates/nature/css/quotes.css',
'/templates/nature/css/quotes.min.css',
'/templates/nature/css/template.css',
'/templates/nature/css/template.min.css',
'/templates/nature/css/timeline.css',
'/templates/nature/css/timeline.min.css',
'/templates/nature/fonts/bootstrap-icons.woff',
'/templates/nature/fonts/bootstrap-icons.woff2',
'/templates/nature/fonts/palanquin-v6-latin-300.eot',
'/templates/nature/fonts/palanquin-v6-latin-300.svg',
'/templates/nature/fonts/palanquin-v6-latin-300.ttf',
'/templates/nature/fonts/palanquin-v6-latin-300.woff',
'/templates/nature/fonts/palanquin-v6-latin-300.woff2',
'/templates/nature/fonts/palanquin-v6-latin-600.eot',
'/templates/nature/fonts/palanquin-v6-latin-600.svg',
'/templates/nature/fonts/palanquin-v6-latin-600.ttf',
'/templates/nature/fonts/palanquin-v6-latin-600.woff',
'/templates/nature/fonts/palanquin-v6-latin-600.woff2',
'/templates/nature/js/template.js',
'/templates/nature/template_preview.png',
'/templates/nature/template_thumbnail.png',
'/templates/nature/html/mod_articles_news/timelinelink.zip'
);
foreach ($files as $file)
{
if ($fileExists = File::exists(JPATH_ROOT . $file))
{
File::delete(JPATH_ROOT . $file);
}
}
foreach ($foldersBefore as $folder)
{
if ($folderExists = Folder::exists(JPATH_ROOT . $folder))
{
Folder::delete(JPATH_ROOT . $folder);
}
}
$this->moveTemplateFiles();
foreach ($folders as $folder)
{
if ($folderExists = Folder::exists(JPATH_ROOT . $folder))
{
Folder::delete(JPATH_ROOT . $folder);
}
}
// Ensure templates are moved to the correct mode
$this->fixTemplateMode();
}
}
}