forked from JoomFish/joomfish-2.5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.php
233 lines (203 loc) · 8.62 KB
/
install.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
<?php
// 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
*/
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['plugin'] . ': ' . $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['module'] . ': ' . $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;
}
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']."'";
}
$query->where($where);
$query->where("$columnType='plugin' OR $columnType='module'");
$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").'+3');
$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
END
WHERE ".$db->nameQuote("element")." IN (".$db->quote("jfrouter").",".$db->quote("jfdatabase").",".$db->quote("jfoverrides").")";
$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);
}
/**
* method to uninstall the component
*
* @return void
*/
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']."'";
}
$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['plugin'] . ': ' . $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['module'] . ': ' . $result , $mtype);
}
}
/**
* method to update the component
*
* @return void
*
function update($parent)
{
// $parent is the class calling this method
echo '<p>' . JText::_('COM_JOOMFISH_UPDATE_TEXT') . '</p>';
}*/
/**
* method to run before an install/update/uninstall method
*
* @return void
*
function preflight($type, $parent)
{
// $parent is the class calling this method
// $type is the type of change (install, update or discover_install)
echo '<p>' . JText::_('COM_JOOMFISH_PREFLIGHT_' . $type . '_TEXT') . '</p>';
}*/
/**
* method to run after an install/update/uninstall method
*
* @return void
**/
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') {
JLoader::import( 'classes.JCacheStorageJFDB',JPATH_ADMINISTRATOR.'/components/com_joomfish');
$result = JCacheStorageJfdb::setupDB();
}
}
}