-
Notifications
You must be signed in to change notification settings - Fork 0
/
com_jecs-install-scipt.php
377 lines (347 loc) · 15.7 KB
/
com_jecs-install-scipt.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?php
/**
* @package Jecs Extensions Installer
* @author Massimo Di Primio <info@diprimio.com>
* @link http://www.diprimio.com
* @copyright Copyright © 2015 Diprimio.Com All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
defined('_JEXEC') or die;
// Potential backward compatibility issues in Joomla 3 and Joomla Platform 12.2
// Please refer to: http://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_3_and_Joomla_Platform_12.2
if(!defined('DS')) {define('DS', DIRECTORY_SEPARATOR);} // For backward compatibility
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
class com_JecsInstallerScript {
private $min_version_joomla = '3.4.1'; /* @var string - Minimum Joomla required version */
private $min_version_php = '5.6.0'; /* @var string - Minimum PHP required version */
private $min_version_mysql = '5.5.1'; /* @var string - Minimum PHP required version */
private $app; /* @var object - Joomla Global Application object */
#
/*
* $subExtensionUninstallMap Array
* ---------------------------------
* Describes what and how to Uninstall subextensions when the Component is Uninstalled
* To be filled with appropriate values for plugins and modules
*
$subExtensionUninstallMap = array (
'Plugins' => array (
array(
'Name' => 'plg_system_jecs', # the name of the plugin as known by Joomla
'Element' => 'jecs', # the plugin element a known by Joomla
'Folder' => 'system' # the plugin 'folder' (i.e. the plugin 'group' as in manifest)
)
)
);
*/
private $subExtensionUninstallMap = array (
'Plugins' => array (
array( 'Name' => 'plg_system_jecs',
'Element' => 'jecs',
'Folder' => 'system'
)
)
);
/*
* $subExtentionInstallMap Array
* -------------------------------
* Describes what and how to Install subextensions when the Component is Installed or updated
* To be filled with appropriate values for plugins and modules
*
$subExtensionInstallMap = array (
"Plugins" => array (
array(
"Dirpath" => 'packages', # the base directory in the distribution zip file for the plugin
"Name" => 'plg_example1', # the name of the subfolder containing the sub-extention to install
"Install" => 1, # 1 = install, <> 1 = ignore
"published" => 1), # 1 = enable the plugin, once installed, <> 1 = ignore
...
),
'Moludes' => array (
array(
"Dirpath" => 'packages', # relative base directory in the distribution zip file
"Name" => 'mod_example3', # the name of the folder containing the sub-extention to install
"Install" => 1, # 1 = install, <> 1 = ignore
"published" => 1), # 1 = enable the plugin, once installed, <> 1 = ignore
...
)
);
*/
private $subExtensionInstallMap = array (
"Plugins" => array (
array( "Dirpath" => 'packages',
"Name" => 'plg_system_jecs',
"Install" => 1,
"published" => 1),
)
);
/**
* Container for component information
*
* @var array component
*/
private $component = array(
'Name' => 'com_jecs'
);
/**
* Class Constructor
*/
function __construct() {
$this->app = JFactory::getApplication();
}
/**
* Trigger function - before installer installation
* @param type type
* @param \stdClass parent
* @return bool
*/
public function preflight($type, $parent) {
#JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_JECS_COMPONENT_PREFLIGHT_START',
$this->app->enqueueMessage("»Component update: Begin Preflight verification for component ".
$parent->get('manifest')->name. ' '. $parent->get('manifest')->version,
'Notice');
// Check Joomla and PHP minimum required version
if (!$this->checkMinRequiredVersion("joomla")) {
$this->uninstallInstaller();
return false;
}
if (!$this->checkMinRequiredVersion("php")) {
$this->uninstallInstaller();
return false;
}
if (!$this->checkMinRequiredVersion("mysql")) {
$this->uninstallInstaller();
return false;
}
#JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_JECS_COMPONENT_PREFLIGHT_END',
$this->app->enqueueMessage("»Component update: End Preflight verification for component ".
$parent->get('manifest')->name. ' '. $parent->get('manifest')->version,
'Notice');
// To prevent XML not found error
# $this->createExtensionRoot(); // No longer needed
return true;
}
/**
* Trigger function - after installer installation
* @param object route
* @param JAdapterInstance adapter
* @return void
*/
public function postflight($type, $parent) {
#JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_JECS_COMPONENT_POSTFLIGHT_START',
$this->app->enqueueMessage("»Component update: Begin Postflight verification for component ".
$parent->get('manifest')->name . ' '. $parent->get('manifest')->version,
'Notice');
// Do something useful here!
#JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_JECS_COMPONENT_POSTFLIGHT_END',
$this->app->enqueueMessage("»Component update: End Postflight verification completed for component ".
$parent->get('manifest')->name. ' '. $parent->get('manifest')->version,
'Notice');
}
/**
* This method is called after a component is installed.
* @param \stdClass $parent - Parent object calling this method.
* @return void
*/
public function install($parent) {
$this->app->enqueueMessage("-»Component install: Begin installation of sub-extensions...", 'Notice');
$this->installSubExtentions($parent); // go ahead installing all needed sub extensions
$this->fixInstalledSubExensions();
$this->app->enqueueMessage("-»Component install: End installation of sub-extensions!", 'Notice');
return;
}
/**
* This method is called after a component is uninstalled.
* @param \stdClass $parent - Parent object calling this method.
* @return void
*/
public function uninstall ($parent) {
#$this->app->enqueueMessage("»Component uninstall procedure started for: ".
# $parent->get('manifest')->name.' '.$parent->get('manifest')->version,
# 'Notice');
$this->app->enqueueMessage("»Component <b>".
$parent->get('manifest')->name.' '.$parent->get('manifest')->version.
"</b> successfully uninstalled. ",
'Notice');
// Uninstall all dependent sub-extensions
$this->uninstallSubExtentions($parent);
$this->app->enqueueMessage("»Component uninstall procedure terminated for: ".
$parent->get('manifest')->name.' '.$parent->get('manifest')->version,
'Notice');
$this->app->enqueueMessage("", 'Notice');
return;
}
/**
* This method is called after a component is updated.
* @param \stdClass $parent - Parent object calling object.
* @return void
*/
public function update($parent) {
#JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_JECS_COMPONENT_UPDATE_START',
$this->app->enqueueMessage("»Component update procedure started for: ".
$parent->get('manifest')->name.' '.$parent->get('manifest')->version,
'Notice');
// update (i.e.install over) all needed sub-extensions
$this->installSubExtentions($parent); // go ahead installing all needed sub extensions
#JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_JECS_COMPONENT_UPDATE_END',
$this->app->enqueueMessage("»Component update procedure terminated for: ".
$parent->get('manifest')->name.' '.$parent->get('manifest')->version,
'Notice');
return;
}
public function installSubExtentions($parent) {
/*
* Following the code excerpt of how to install an extension within Joomla
* # $path = $installer->getPath('source');
* # $plugin_dir = $path.'/my_plugin_dir';
* # $plugin_installer = new JInstaller();
* # $plugin_installer->install($plugin_dir);
*/
//$this->app->enqueueMessage("-»Component install: Begin installation of sub-extensions...", 'Notice');
$package_folders = JFolder::folders(__DIR__ . '/packages' . DS,
$filter='',
$recurse=false,
$full=false,
$exclude=array('.svn','CVS','.DS_Store','__MACOSX',
$excludefilter=array('^\..*'))
);
$packages = array_diff($package_folders, array($this->component['Name'])); #'com_jecs'));
while ($extensionType = current($this->subExtensionInstallMap)){
if (key($this->subExtensionInstallMap) == 'Plugins') {
foreach ($extensionType as $value) {
$src = $parent->getParent()->getPath('source');
$packagePath = $src . DS . $value['Dirpath'] . DS . $value['Name']; #$package;
$installer = new JInstaller;
$installRes = $installer->install($packagePath);
if ($installRes) {
$this->app->enqueueMessage("--»Component install: Installation of sub-extensions successful for <b>".$value['Name']."</b>", 'Notice');
}else {
$this->app->enqueueMessage("--»Component install: Error while installing additional package extention for <b>".$value['Name']."</b>", 'Error');
}
}
}
if (key($this->subExtensionInstallMap) == 'Plugins') {
$a = 1;
}
next($this->subExtensionInstallMap);
}
/*
//$installer = new JInstaller;
$package_folders = JFolder::folders(__DIR__ . '/packages' . DS,
$filter='', $recurse=false, $full=false, $exclude=array('.svn','CVS','.DS_Store','__MACOSX', $excludefilter=array('^\..*')));
$packages = array_diff($package_folders, array('com_jecs'));
foreach ($packages as $package) {
$src = $parent->getParent()->getPath('source');
$packagePath = $src . DS . 'packages' . DS . $package;
$installer = new JInstaller;
$installRes = $installer->install($packagePath);
if ($installRes) {
$this->app->enqueueMessage("--»Component install: Installation of sub-extensions successful for <b>".$package."</b>", 'Notice');
} else {
$this->app->enqueueMessage("--»Component install: Error while installing additional package extention for <b>".$package."</b>", 'Notice');
}
}
//$this->app->enqueueMessage("-»Component install: End installation of sub-extensions!", 'Notice');
*/
return;
}
/**
*
* @param type $parent
* @return type
*/
private function uninstallSubExtentions($parent) {
while ($extensionType = current($this->subExtensionUninstallMap)) {
if (key($this->subExtensionUninstallMap) == 'Plugins') {
foreach ($extensionType as $value) {
$id = $this->queryJoomlaDbPlugin($value['Element'], $value['Folder']);
if ($id) {
$installer = new JInstaller;
$result = $installer->uninstall('plugin', $id, 1);
#$status->plugins[] = array('name' => 'plg_' . $plugin,'group' => $folder,'result' => $result);
}
}
}
if (key($this->subExtensionUninstallMap) == 'Moules') {
foreach ($extensionType as $value) {
$id = $this->queryJoomlaDbModules($value['Element']);
if ($id) {
$installer = new JInstaller;
$result = $installer->uninstall('module', $id, 1);
#$status->plugins[] = array('name' => 'mod_' . $module,'group' => $folder,'result' => $result);
}
}
}
next($this->subExtensionUninstallMap);
}
return;
}
private function queryJoomlaDbPlugin($pluginElement, $pluginFolder) {
$db = JFactory::getDBO();
$sql = $db->getQuery(true)
->select($db->qn('extension_id'))
->from($db->qn('#__extensions'))
->where($db->qn('type') . ' = ' . $db->q('plugin'))
->where($db->qn('element') . ' = ' . $db->q($pluginElement))
->where($db->qn('folder') . ' = ' . $db->q($pluginFolder));
$db->setQuery($sql);
$id = $db->loadResult();
return $id;
}
private function queryJoomlaDbModules($moduleElement) {
$db = JFactory::getDBO();
$sql = $db->getQuery(true)
->select($db->qn('extension_id'))
->from($db->qn('#__extensions'))
->where($db->qn('type') . ' = ' . $db->q('module'))
->where($db->qn('element') . ' = ' . $db->q($$moduleElement));
$db->setQuery($sql);
$id = $db->loadResult();
return $id;
}
/**
* Check minimum requirements
* @param type $type - What to check (i.e. 'joomla', 'php'
* @return boolean
*/
private function checkMinRequiredVersion($type = "joomla") {
switch ($type) {
case 'joomla':
if (version_compare(JVERSION, $this->min_version_joomla, '<')) {
$this->app->enqueueMessage("--»Incompatible Joomla! version",
#JText::sprintf('COM_JECS_COMPONENT_COMPATIBLE_JOOMLA', JVERSION, $this->min_version_joomla),
'error'
);
return false;
}
break;
case 'php':
if (version_compare(PHP_VERSION, $this->min_version_php, 'l')) {
$this->app->enqueueMessage("--»Incompatible PHP version",
'error'
);
return false;
}
break;
case 'mysql':
if (version_compare(PHP_VERSION, $this->min_version_mysql, 'l')) {
$this->app->enqueueMessage("--»Incompatible MySql version",
'error'
);
return false;
}
break;
}
return true;
}
/**
* WARNING! This will be implemented in some future release.
* Take all needed actions on installed sub-extensions
* @return void
*/
private function fixInstalledSubExensions() {
return;
}
}
/* === End-of-file === */
?>