-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.php
313 lines (275 loc) · 9.29 KB
/
script.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
<?php
/**
* Installation file for stockablecustomfields
*
* @package stockablecustomfields.install
* @author Sakis Terzis
* @copyright Copyright (c) 2017-2020 breakdesigns.net. All rights reserved.
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
// Check to ensure this file is included in Joomla!
defined( '_JEXEC' ) or die;
/**
* Load the ePahali installer
*
* @copyright
* @author Sakis Terz
* @see http://docs.joomla.org/Developing_a_Model-View-Controller_%28MVC%29_Component_for_Joomla!1.6_-_Part_15
* @access public
* @param
* @return
* @since 1.5.3
*/
class plgVmCustomStockablecustomfieldsInstallerScript {
/**
* Installation routine
*
* @copyright
* @author Sakis Terz
* @access public
* @param
* @return
* @since 2.0
*/
public function install($parent) {
}
/**
* Update routine
*
* @copyright
* @author Sakis Terzis
* @todo
* @see
* @access public
* @param
* @return
* @since 2.0
*/
public function update($parent) {
}
/**
* Preflight routine executed before install and update
*
* @copyright
* @author Sakis Terzis
* @todo
* @see
* @access public
* @param $type string type of change (install, update or discover_install)
* @return
* @since 2.0
*/
public function preflight($type, $parent) {
jimport('joomla.filesystem.file');
if($type=='update'){
//store the milestone versions and the messages that each 1 will print
$milestone_versions=array();
$messages=array();
//E.G. $messages['1.8.0']='New feature: Result page is now based on menu items.';
$this->printed_messages=array();
$oldRelease=$this->getParam('version');
$new_release=$parent->get( "manifest" )->version;
foreach ($milestone_versions as $m_v){
if(version_compare($oldRelease, $m_v)==-1){
$this->printed_messages[]=$messages[$m_v];
}
}
}
}
/**
* Postflight routine executed after install and update
*
* @copyright
* @author Sakis Terzis
* @todo
* @see
* @access public
* @param $type string type of change (install, update or discover_install)
* @return
* @since 2.0
*/
public function postflight($type, $parent) {
$db = JFactory::getDbo();
$status = new stdClass;
$status->modules = array();
$status->plugins = array();
$status->templateoverrides=array();
$src = $parent->getParent()->getPath('source');
$manifest = $parent->getParent()->manifest;
$plugins = $manifest->xpath('plugins/plugin');
foreach ($plugins as $plugin)
{
$name = (string)$plugin->attributes()->plugin;
$group = (string)$plugin->attributes()->group;
if($name!='stockablecustomfields'){
$path = $src.'/plugins/'.$group;
if (JFolder::exists($src.'/plugins/'.$group.'/'.$name))
{
$path = $src.'/plugins/'.$group.'/'.$name;
}
$installer = new JInstaller;
$result = $installer->install($path);
}else $result=true; //installed by the current manifest
$query = "UPDATE #__extensions SET enabled=1 WHERE type='plugin' AND element=".$db->Quote($name)." AND folder=".$db->Quote($group);
$db->setQuery($query);
$db->query();
$status->plugins[] = array('name' => $name, 'group' => $group, 'result' => $result);
}
$modules = $manifest->xpath('modules/module');
foreach ($modules as $module)
{
$name = (string)$module->attributes()->module;
$client = (string)$module->attributes()->client;
if (is_null($client))
{
$client = 'site';
}
($client == 'administrator') ? $path = $src.'/administrator/modules/'.$name : $path = $src.'/modules/'.$name;
if($client == 'administrator')
{
$db->setQuery("SELECT id FROM #__modules WHERE `module` = ".$db->quote($name));
$isUpdate = (int)$db->loadResult();
}
$installer = new JInstaller;
$result = $installer->install($path);
$status->modules[] = array('name' => $name, 'client' => $client, 'result' => $result);
if($client == 'administrator' && !$isUpdate)
{
$position ='cpanel';
$db->setQuery("UPDATE #__modules SET `position`=".$db->quote($position).",`published`='1' WHERE `module`=".$db->quote($name));
$db->query();
$db->setQuery("SELECT id FROM #__modules WHERE `module` = ".$db->quote($name));
$id = (int)$db->loadResult();
$db->setQuery("INSERT IGNORE INTO #__modules_menu (`moduleid`,`menuid`) VALUES (".$id.", 0)");
$db->query();
}
}
$template_overrides = $manifest->xpath('templateoverrides/templateoverride');
foreach($template_overrides as $template_override){
$name = (string)$template_override->attributes()->name;
$client = (string)$template_override->attributes()->client;
$source=$src.DIRECTORY_SEPARATOR.'templateoverrides'.DIRECTORY_SEPARATOR.$name;
if (is_null($client))$client = 'site';
($client == 'administrator') ? $destination = JPATH_ADMINISTRATOR.DIRECTORY_SEPARATOR.'templates' : $path =JPATH_SITE.DIRECTORY_SEPARATOR.'templates';
$templates=JFolder::folders($destination);
foreach ($templates as $tmpl){
$final_destination=$destination.DIRECTORY_SEPARATOR.$tmpl.DIRECTORY_SEPARATOR.'html';
$this->recurse_copy($source,$final_destination);
}
}
$this->installationResults($status,$type);
}
/**
* copy all $src to $dst folder and remove it
*
* @author Max Milbers-Sakis Terz
* @param String $src path
* @param String $dst path
* @param String $type modules, plugins, languageBE, languageFE
*/
private function recurse_copy($src,$dst,$last=false ) {
$dst_exist=JFolder::exists($dst);
jimport( 'joomla.filesystem.folder' );
if(!$dst_exist)$dst_exist=JFolder::create($dst);
$dir = opendir($src);
if(is_resource($dir) && $dst_exist){
jimport( 'joomla.filesystem.file' );
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src .DIRECTORY_SEPARATOR. $file) ) {
$this->recurse_copy($src .DIRECTORY_SEPARATOR. $file,$dst .DIRECTORY_SEPARATOR. $file);
}
else {
if(JFile::exists($dst .DIRECTORY_SEPARATOR. $file)){
}
if(!JFile::copy($src .DIRECTORY_SEPARATOR. $file,$dst .DIRECTORY_SEPARATOR. $file)){
//$app = JFactory::getApplication();
//$app -> enqueueMessage('Couldnt copy '.$src .DIRECTORY_SEPARATOR. $file.' to '.$dst .DIRECTORY_SEPARATOR. $file);
}
}
}
}
}
if(is_resource($dir))closedir($dir);
if (is_dir($src) && $last) JFolder::delete($src);
}
/**
* get a variable from the manifest file (actually, from the manifest cache).
*/
function getParam( $name ) {
$db = JFactory::getDbo();
$db->setQuery('SELECT manifest_cache FROM #__extensions WHERE element = "stockablecustomfields"');
$manifest = json_decode( $db->loadResult(), true );
return $manifest[ $name ];
}
private function installationResults($status,$type)
{
$language = JFactory::getLanguage();
$language->load('plg_vmcustom_stockablecustomfields');
$rows = 0;
if($type=='update'){
$status_type=JText::_('PLG_STOCKABLECUSTOMFIELDS_UPDATE_STATUS');
$success_msg='<span style="color:#5cb85c">'.JText::_('PLG_STOCKABLECUSTOMFIELDS_SUCEESS').'<span>';
$fail_msg='<span style="color:#ff0000">'.JText::_('PLG_STOCKABLECUSTOMFIELDS_NOT_UPDATED').'</span>';
} else{
$status_type=JText::_('PLG_STOCKABLECUSTOMFIELDS_INSTALLATION_STATUS');
$success_msg='<span style="color:#5cb85c">'.JText::_('PLG_STOCKABLECUSTOMFIELDS_SUCEESS').'<span>';
$fail_msg='<span style="color:#ff0000">'.JText::_('PLG_STOCKABLECUSTOMFIELDS_NOT_INSTALLED').'<span>';
}
?>
<?php
//if update messages
if(!empty($this->printed_messages)){?>
<div class="clr"></div>
<h3><?php echo JText::_('PLG_STOCKABLECUSTOMFIELDS_UPDATE_MESSAGES');?></h3>
<div id="system-message-container">
<dl id="system-message">
<dt class="message">Message</dt>
<dd class="message message">
<ul>
<?php
foreach ($this->printed_messages as $message){?>
<li><?php echo $message?></li>
<?php }?>
</ul>
</dd>
</dl>
</div>
<?php }?>
<table class="adminlist table table-striped">
<thead>
<tr>
<th class="title"><?php echo JText::_('PLG_STOCKABLECUSTOMFIELDS_EXTENSION'); ?></th>
<th><?php echo JText::_('PLG_STOCKABLECUSTOMFIELDS_GROUP'); ?></th>
<th width="30%"><?php echo $status_type; ?></th></tr>
</thead>
<tfoot>
<tr>
<td colspan="3"></td>
</tr>
</tfoot>
<tbody>
<?php if (count($status->modules)): ?>
<?php foreach ($status->modules as $module): ?>
<tr class="row<?php echo(++$rows % 2); ?>">
<td class="key"><?php echo $module['name']; ?> - module</td>
<td class="key"><?php echo ucfirst($module['client']); ?></td>
<td><strong><?php echo ($module['result'])?$success_msg:$fail_msg; ?></strong></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<?php if (count($status->plugins)): ?>
<?php foreach ($status->plugins as $plugin): ?>
<tr class="row<?php echo(++$rows % 2); ?>">
<td class="key"><?php echo ucfirst($plugin['name']); ?> - plugin</td>
<td class="key"><?php echo ucfirst($plugin['group']); ?></td>
<td><strong><?php echo ($plugin['result'])?$success_msg:$fail_msg; ?></strong></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<?php
}
}
?>