-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathinstall.php
More file actions
346 lines (304 loc) · 13.1 KB
/
install.php
File metadata and controls
346 lines (304 loc) · 13.1 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
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
<?php
/**
* Joom!Fish - Multi Lingual extention and translation manager for Joomla!
* Copyright (C) 2003 - 2013, Think Network GmbH, Konstanz
*
* All rights reserved. The Joom!Fish project is a set of extentions for
* the content management system Joomla!. It enables Joomla!
* to manage multi lingual sites especially in all dynamic information
* which are stored in the database.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
*
* The "GNU General Public License" (GPL) is available at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* -----------------------------------------------------------------------------
* @package joomfish
* @subpackage install
*
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/**
* Install script for Joomfish, inspired by http://itprism.com/blog/multiple-extensions-single-package
*/
class com_JoomfishInstallerScript
{
/**
* method to install the component
*
* @return void
*/
public function install($parent)
{
$manifest = $parent->get("manifest");
$parent = $parent->getParent();
$source = $parent->getPath("source");
$installer = new JInstaller();
$app = JFactory::getApplication();
// Install plugins
foreach($manifest->plugins->plugin as $plugin) {
$attributes = $plugin->attributes();
$plg = $source . DS . $attributes['folder'].DS.$attributes['plugin'];
if ($installer->install($plg) !== false) {
$result = JText::_('COM_JOOMFISH_SUCCESS');
$mtype = 'information';
} else {
$result = JText::_('COM_JOOMFISH_FAIL') ;
$mtype = 'error';
}
$app->enqueueMessage( JText::_('COM_JOOMFISH_INSTALL_EXTENSION') . ' ' . $attributes['name'] . ': ' . $result , $mtype);
}
// Install modules
foreach($manifest->modules->module as $module) {
$attributes = $module->attributes();
$mod = $source . DS . $attributes['folder'].DS.$attributes['module'];
if ($installer->install($mod) !== false) {
$result = JText::_('COM_JOOMFISH_SUCCESS');
$mtype = 'information';
} else {
$result = JText::_('COM_JOOMFISH_FAIL') ;
$mtype = 'error';
}
$app->enqueueMessage( JText::_('COM_JOOMFISH_INSTALL_EXTENSION') . ' ' . $attributes['name'] . ': ' . $result , $mtype);
}
$db = JFactory::getDbo();
$tableExtensions = $db->nameQuote("#__extensions");
$columnElement = $db->nameQuote("element");
$columnType = $db->nameQuote("type");
$columnEnabled = $db->nameQuote("enabled");
// Enable plugins and modules
$query = $db->getQuery(true);
$query->update($tableExtensions);
$query->set($columnEnabled."=1");
$where = null;
// looptest counters
$ltp = 0;
$ltm = 0;
foreach($manifest->plugins->plugin as $plugin) {
if ($ltp ==1 ) $where .= " OR ";
$attributes = $plugin->attributes();
$where .= $columnElement ."='".$attributes['plugin']."'";
$ltp = 1;
}
$query2 = $db->getQuery(true);
$query2->update('#__modules');
$where2 = null;
$query2->set($db->nameQuote("published")."=1");
$query2->set($db->nameQuote("position")."=".$db->quote('position-6'));
$query3 = $db->getQuery(true);
$query3->select('id');
$query3->from('#__modules');
foreach($manifest->modules->module as $module) {
if ($ltp ==1 ) {
$where .= " OR ";
$ltp = 0;
}
if ($ltm ==1 ) {
$where .= " OR ";
$where2 .= " OR ";
$where3 .= " OR ";
}
$attributes = $module->attributes();
$where .= $columnElement ."='".$attributes['module']."'";
$where2 .= $db->nameQuote('module') ."='".$attributes['module']."'";
}
$query->where($where);
$query->where("$columnType='plugin' OR $columnType='module'");
$db->setQuery((string)$query);
$db->query();
$query2->where($where2);
$db->setQuery((string)$query2);
$db->query();
$query3->where($where2);
$db->setQuery((string)$query3);
$moduleids = $db->loadAssocList('id', 'id');
$query4 = $db->getQuery(true);
$insert = '#__modules_menu ('.$db->nameQuote("moduleid").','.$db->nameQuote("menuid").')
VALUES ';
$values = array();
foreach($moduleids AS $moduleid) {
$values[] = '('.$moduleid.',0)';
}
$values = implode(',', $values);
$insert .= $values .' ON DUPLICATE KEY UPDATE '.$db->nameQuote("menuid").'=0;';
$query4->insert($insert);
$db->setQuery($query4);
$db->query();
// Set plugin ordering: first change all plugins with negative ordering numbers to 0
$query = $db->getQuery(true);
$query->update($tableExtensions);
$query->set($db->nameQuote("ordering").'=0');
$query->where($columnType.'='.$db->quote("plugin"));
$query->where($db->nameQuote("folder").'='.$db->quote("system") .'AND '.$db->nameQuote("ordering").'<0');
$db->setQuery((string)$query);
$db->query();
// Set plugin ordering: first increase all plugins ordering numbers
$query = $db->getQuery(true);
$query->update($tableExtensions);
$query->set($db->nameQuote("ordering").'='.$db->nameQuote("ordering").'+4');
$query->where($columnType.'='.$db->quote("plugin"));
$query->where($db->nameQuote("folder").'='.$db->quote("system"));
$db->setQuery((string)$query);
$db->query();
// Now set our plugins to the right order
$query = "UPDATE ".$tableExtensions."
SET ".$db->nameQuote("ordering")." = CASE ".$db->nameQuote("element")."
WHEN ".$db->quote("jfrouter")." THEN 0
WHEN ".$db->quote("jfdatabase")." THEN 1
WHEN ".$db->quote("jfoverrides")." THEN 2
WHEN ".$db->quote("jfinlinemapping")." THEN 3
END
WHERE ".$db->nameQuote("element")." IN (".$db->quote("jfrouter").",".$db->quote("jfdatabase").",".$db->quote("jfoverrides").",".$db->quote("jfinlinemapping").")";
$db->setQuery($query);
$db->query();
// Reorder table #__extensions where type=plugin and folder=system
$table = JTable::getInstance('extension');
$whereOrder = $db->nameQuote("folder").'='.$db->quote("system").' AND '.$columnType.'='.$db->quote("plugin");
$table->reorder($whereOrder);
// Install library
$library = $manifest->library;
$attributes = $library->attributes();
$lib = $source . DS . $attributes['folder'];
if ($installer->install($lib) !== false) {
$result = JText::_('COM_JOOMFISH_SUCCESS');
$mtype = 'information';
} else {
$result = JText::_('COM_JOOMFISH_FAIL') ;
$mtype = 'error';
}
$app->enqueueMessage( JText::_('COM_JOOMFISH_INSTALL_EXTENSION') . ' ' . $attributes['name'] . ': ' . $result , $mtype);
}
/**
* method to uninstall the component
*
* @return void
*/
public function uninstall($parent)
{
$manifest = $parent->get("manifest");
$parent = $parent->getParent();
$source = $parent->getPath("source");
$installer = new JInstaller();
$app = JFactory::getApplication();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$columnElement = $db->nameQuote("element");
$query->select($db->nameQuote("extension_id").",".$columnElement);
$query->from($db->nameQuote("#__extensions"));
$where = null;
// looptest counters
$ltp = 0;
$ltm = 0;
foreach($manifest->plugins->plugin as $plugin) {
if ($ltp ==1 ) $where .= " OR ";
$attributes = $plugin->attributes();
$where .= $columnElement ."='".$attributes['plugin']."'";
$ltp = 1;
}
foreach($manifest->modules->module as $module) {
if ($ltp ==1 ) {
$where .= " OR ";
$ltp = 0;
}
if ($ltm ==1 ) $where .= " OR ";
$attributes = $module->attributes();
$where .= $columnElement ."='".$attributes['module']."'";
}
$attributes = $manifest->library->attributes();
$where .= " OR ".$columnElement ."='".'lib_'.$attributes['library']."'";
$query->where($where);
$db->setQuery((string)$query);
$ids = $db->loadObjectList('element');
// Uninstall plugins
foreach($manifest->plugins->plugin as $plugin) {
$attributes = $plugin->attributes();
$plgID = $ids[(string)$attributes['plugin']]->extension_id;
if ($installer->uninstall('plugin', (int)$plgID) !== false) {
$result = JText::_('COM_JOOMFISH_SUCCESS');
$mtype = 'information';
} else {
$result = JText::_('COM_JOOMFISH_FAIL') ;
$mtype = 'error';
}
$app->enqueueMessage( JText::_('COM_JOOMFISH_UNINSTALL_EXTENSION') . ' ' . $attributes['name'] . ': ' . $result , $mtype);
}
// Uninstall modules
foreach($manifest->modules->module as $module) {
$attributes = $module->attributes();
$modID = $ids[(string)$attributes['module']]->extension_id;
if ($installer->uninstall('module', (int)$modID) !== false) {
$result = JText::_('COM_JOOMFISH_SUCCESS');
$mtype = 'information';
} else {
$result = JText::_('COM_JOOMFISH_FAIL') ;
$mtype = 'error';
}
$app->enqueueMessage( JText::_('COM_JOOMFISH_UNINSTALL_EXTENSION') . ' ' . $attributes['name'] . ': ' . $result , $mtype);
}
// Uninstall library
$library = $manifest->library;
$attributes = $library->attributes();
$libID = $ids[(string)'lib_'.$attributes['library']]->extension_id;
if ($installer->uninstall('library', (int)$libID) !== false) {
$result = JText::_('COM_JOOMFISH_SUCCESS');
$mtype = 'information';
} else {
$result = JText::_('COM_JOOMFISH_FAIL') ;
$mtype = 'error';
}
$app->enqueueMessage( JText::_('COM_JOOMFISH_UNINSTALL_EXTENSION') . ' ' . $attributes['name'] . ': ' . $result , $mtype);
}
/**
* method to update the component
*
* @return void
*/
public function update($parent)
{
$this->install($parent);
}
/**
* method to run before an install/update/uninstall method
*
* @return void
**/
function preflight($type, $parent)
{
if ($type == 'install' || $type == 'update') {
$app = JFactory::getApplication();
$dbtype = JFactory::getConfig()->getValue('dbtype','mysqli');
if ($dbtype != 'mysqli') {
$app->enqueueMessage($dbtype .' '. JText::_('COM_JOOMFISH_DATABASE_DRIVER_NOT_SUPPORTED'));
return false;
}
}
return true;
}
/**
* method to run after an install/update/uninstall method
*
* @return void
**/
public function postflight($type, $parent)
{
// $parent is the class calling this method
// $type is the type of change (install, update or discover_install)
if ($type == 'install' || $type == 'update') {
jimport('joomfish.cache.jfdb');
$result = JCacheStorageJfdb::setupDB();
}
}
}