-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.installer.php
250 lines (214 loc) · 7.39 KB
/
script.installer.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/**
* @author Guillermo Vargas <[email protected]>
* @author Branko Wilhelm <[email protected]>
* @link http://www.z-index.net
* @copyright (c) 2005 - 2009 Joomla! Vargas. All rights reserved.
* @copyright (c) 2015 Branko Wilhelm. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Class com_xmapInstallerScript
*/
class com_xmapInstallerScript
{
/**
* required Joomla! version
*/
const JVERSION = 3.4;
/**
* @var array outdated files from previous xmap version
*/
protected $outdated_files = array(
// Backend
'/administrator/components/com_xmap/views/sitemap/tmpl/edit_legacy.php',
'/administrator/components/com_xmap/views/sitemap/tmpl/navigator.php',
'/administrator/components/com_xmap/views/sitemap/tmpl/navigator_class.php',
'/administrator/components/com_xmap/views/sitemap/tmpl/navigator_links.php',
'/administrator/components/com_xmap/views/sitemaps/tmpl/default_legacy.php',
'/administrator/components/com_xmap/views/sitemaps/tmpl/form.php',
'/administrator/components/com_xmap/views/sitemaps/tmpl/modal.php',
'/administrator/components/com_xmap/models/fields/xmapmenus.php',
'/administrator/components/com_xmap/models/forms/extension.xml',
'/administrator/components/com_xmap/manifest.xml',
// Site
'/components/com_xmap/views/html/tmpl/default_class.php',
'/components/com_xmap/views/html/tmpl/default_items.php',
'/components/com_xmap/views/xml/tmpl/default_class.php',
'/components/com_xmap/views/xml/tmpl/default_items.php',
'/components/com_xmap/views/xml/tmpl/default_xsl.php',
'/components/com_xmap/controllers/ajax.json.php',
);
/**
* @var array outdated folders from previous xmap version
*/
protected $outdated_folders = array(
// Backend
'/administrator/components/com_xmap/css',
'/administrator/components/com_xmap/elements',
'/administrator/components/com_xmap/images',
'/administrator/components/com_xmap/install',
'/administrator/components/com_xmap/models/fields/modal',
// Site
'/components/com_xmap/assets',
);
/**
* @return bool
*/
public function preflight()
{
if (!version_compare(JVERSION, self::JVERSION, '>='))
{
$link = JHtml::_('link', 'index.php?option=com_joomlaupdate', 'Joomla! ' . self::JVERSION);
JFactory::getApplication()->enqueueMessage(sprintf('You need %s or newer to install this extension', $link), 'error');
return false;
}
return true;
}
/**
* install all integrated third party plugins and the xmap system plugin
*
* @param JAdapterInstance $adapter
*/
public function install(JAdapterInstance $adapter)
{
$path = $adapter->getParent()->getPath('source');
$folders = JFolder::folders($path . '/plugins/xmap/');
$plugins = array();
foreach ($folders as $component)
{
$plugins[$component] = $path . '/plugins/xmap/' . $component;
}
// install each third party plugin if component installed
foreach ($plugins as $component => $plugin)
{
if (JComponentHelper::isInstalled($component))
{
$installer = new JInstaller;
$installer->install($plugin);
}
}
// install xmap system plugin
// TODO implement plugin features in XmapDisplayerHtml
//$installer = new JInstaller;
//$installer->install($path . '/plugins/system/xmap/');
}
/**
* @param JAdapterInstance $adapter
*/
public function update(JAdapterInstance $adapter)
{
$this->install($adapter);
}
/**
* uninstall all installed xmap plugins
* @return bool
*/
public function uninstall(JAdapterInstance $adapter)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('e.extension_id')
->from('#__extensions AS e')
->where('e.type = ' . $db->Quote('plugin'))
->where('e.folder = ' . $db->quote('xmap') . 'OR (e.element = ' . $db->quote('xmap') . ' AND e.folder = ' . $db->quote('system') . ')');
$db->setQuery($query);
try
{
$plugins = $db->loadColumn();
} catch (RuntimeException $e)
{
return false;
}
if (!empty($plugins))
{
foreach ($plugins as $plugin)
{
$installer = new JInstaller;
$installer->uninstall('plugin', $plugin);
}
}
return true;
}
/**
* enable all installed xmap plugins
*/
public function postflight()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->update('#__extensions AS e')
->set('e.enabled = ' . $db->quote(1))
->where('e.type = ' . $db->quote('plugin'))
->where('e.folder = ' . $db->quote('xmap') . 'OR (e.element = ' . $db->quote('xmap') . ' AND e.folder = ' . $db->quote('system') . ')');
$db->setQuery($query);
$db->execute();
$this->postflightDeletePackage();
$this->postflightDeleteUpdateserver();
$this->postflightDeleteOutdatedFilesAndFolders();
}
/**
* delete old package installation set
*/
protected function postflightDeletePackage()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->delete('#__extensions')
->where($db->quoteName('type') . ' = ' . $db->quote('package'))
->where($db->quoteName('element') . ' = ' . $db->quote('pkg_xmap'));
$db->setQuery($query);
try
{
$db->execute();
} catch (RuntimeException $e)
{
// do nothing
}
}
/**
* delete old outdated update server
*/
protected function postflightDeleteUpdateserver()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->delete('#__update_sites')
->where($db->quoteName('name') . ' = ' . $db->quote('Xmap Update Site'));
$db->setQuery($query);
try
{
$db->execute();
} catch (RuntimeException $e)
{
// do nothing
}
}
/**
* delete outdated/unused files and folders from previous installation
*/
protected function postflightDeleteOutdatedFilesAndFolders()
{
$failed = array('outdated/unused file/folder deletion failed:'); // TODO JText
foreach ($this->outdated_files as $file)
{
if (JFile::exists(JPATH_ROOT . $file) && !JFile::delete(JPATH_ROOT . $file))
{
$failed[] = $file;
}
}
foreach ($this->outdated_folders as $folder)
{
if (JFolder::exists(JPATH_ROOT . $folder) && !JFolder::delete(JPATH_ROOT . $folder))
{
$failed[] = $folder;
}
}
if (count($failed) > 1)
{
$failed[] = 'please delete this files/folder manually'; // TODO JText
JFactory::getApplication()->enqueueMessage(implode('<br/>', $failed), 'warning');
}
}
}