forked from techjoomla/com_hierarchy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.hierarchy.php
executable file
·297 lines (260 loc) · 6.64 KB
/
script.hierarchy.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
<?php
/**
* @version SVN: <svn_id>
* @package Com_Tjlms
* @copyright Copyright (C) 2005 - 2014. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Shika is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/
// No direct access
defined('_JEXEC') or die;
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
/**
* Hierarchy Installer
*
* @since 1.0.0
*/
class Com_HierarchyInstallerScript
{
/** @var array The list of extra modules and plugins to install */
private $oldversion = "";
private $installation_queue = array(
'plugins' => array(
'privacy' => array(
'hierarchy' => 1,
),
'actionlog' => array(
'hierarchy' => 1,
)
)
);
private $uninstall_queue = array(
'plugins' => array(
'privacy' => array(
'hierarchy' => 1
),
'actionlog' => array(
'hierarchy' => 1
)
)
);
/**
* method to run before an install/update/uninstall method
*
* @param JInstaller $type type
* @param JInstaller $parent parent
*
* @return void
*/
public function preflight($type, $parent)
{
}
/**
* method to install the component
*
* @param JInstaller $parent parent
*
* @return void
*/
public function install($parent)
{
}
/**
* method to update the component
*
* @param JInstaller $parent Parent
*
* @return void
*/
public function update($parent)
{
$this->installSqlFiles($parent);
}
/**
* installSqlFiles
*
* @param JInstaller $parent parent
*
* @return void
*/
public function installSqlFiles($parent)
{
$db = JFactory::getDBO();
// Obviously you may have to change the path and name if your installation SQL file ;)
if (method_exists($parent, 'extension_root'))
{
$sqlfile = $parent->getPath('extension_root') . DS . 'admin' . DS . 'sql' . DS . 'install.mysql.utf8.sql';
}
else
{
$sqlfile = $parent->getParent()->getPath('extension_root') . DS . 'sql' . DS . 'install.mysql.utf8.sql';
}
// Don't modify below this line
$buffer = file_get_contents($sqlfile);
if ($buffer !== false)
{
jimport('joomla.installer.helper');
$queries = JInstallerHelper::splitSql($buffer);
if (count($queries) != 0)
{
foreach ($queries as $query)
{
$query = trim($query);
if ($query != '' && $query{0} != '#')
{
$db->setQuery($query);
if (!$db->query())
{
JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)));
return false;
}
}
}
}
}
}
/**
* Runs after install, update or discover_update
*
* @param string $type install, update or discover_update
*
* @param JInstaller $parent parent
*
* @return void
*/
public function postflight($type, $parent)
{
// Install subextensions
$status = $this->_installSubextensions($parent);
}
/**
* Installs subextensions (modules, plugins) bundled with the main extension
*
* @param JInstaller $parent parent
*
* @return JObject The subextension installation status
*/
private function _installSubextensions($parent)
{
$src = $parent->getParent()->getPath('source');
$db = JFactory::getDbo();
$status = new JObject;
$status->modules = array();
// Plugins installation
if (count($this->installation_queue['plugins']))
{
foreach ($this->installation_queue['plugins'] as $folder => $plugins)
{
if (count($plugins))
{
foreach ($plugins as $plugin => $published)
{
$path = "$src/plugins/$folder/$plugin";
if (!is_dir($path))
{
$path = "$src/plugins/$folder/plg_$plugin";
}
if (!is_dir($path))
{
$path = "$src/plugins/$plugin";
}
if (!is_dir($path))
{
$path = "$src/plugins/plg_$plugin";
}
if (!is_dir($path))
{
continue;
}
// Was the plugin already installed?
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->qn('#__extensions'))
->where('( ' . ($db->qn('name') . ' = ' . $db->q($plugin)) . ' OR ' . ($db->qn('element') . ' = ' . $db->q($plugin)) . ' )')
->where($db->qn('folder') . ' = ' . $db->q($folder));
$db->setQuery($query);
$count = $db->loadResult();
$installer = new JInstaller;
$result = $installer->install($path);
$status->plugins[] = array('name' => $plugin, 'group' => $folder, 'result' => $result, 'status' => $published);
if ($published && !$count)
{
$query = $db->getQuery(true)
->update($db->qn('#__extensions'))
->set($db->qn('enabled') . ' = ' . $db->q('1'))
->where('( ' . ($db->qn('name') . ' = ' . $db->q($plugin)) . ' OR ' . ($db->qn('element') . ' = ' . $db->q($plugin)) . ' )')
->where($db->qn('folder') . ' = ' . $db->q($folder));
$db->setQuery($query);
$db->execute();
}
}
}
}
}
return $status;
}
/**
* Runs on uninstallation
*
* @param JInstaller $parent parent
*
* @return void
*/
public function uninstall($parent)
{
// Uninstall subextensions
$status = $this->_uninstallSubextensions($parent);
}
/**
* Uninstalls subextensions (modules, plugins) bundled with the main extension
*
* @param JInstaller $parent parent
*
* @return JObject The subextension uninstallation status
*/
private function _uninstallSubextensions($parent)
{
jimport('joomla.installer.installer');
$db = JFactory::getDbo();
$status = new JObject;
$status->modules = array();
$status->plugins = array();
$src = $parent->getParent()->getPath('source');
// Plugins uninstallation
if (count($this->uninstall_queue['plugins']))
{
foreach ($this->uninstall_queue['plugins'] as $folder => $plugins)
{
if (count($plugins))
{
foreach ($plugins as $plugin => $published)
{
$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($plugin))
->where($db->qn('folder') . ' = ' . $db->q($folder));
$db->setQuery($sql);
$id = $db->loadResult();
if ($id)
{
$installer = new JInstaller;
$result = $installer->uninstall('plugin', $id);
$status->plugins[] = array(
'name' => 'plg_' . $plugin,
'group' => $folder,
'result' => $result
);
}
}
}
}
}
return $status;
}
}