-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.php
466 lines (414 loc) · 13.8 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
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
<?php
/**
* @version 3.1
* @package Joomla
* @subpackage Imprint
* @copyright (C) 2011 - 2012 Imprint Team
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/**
* Script file of Imprint component.
*
* @package Joomla
* @subpackage Imprint
* @since 3.0
*/
class com_imprintInstallerScript
{
/**
* Method to install the component.
*
* @author mgebhardt
* @param object $parent Is the class calling this method.
* @since 3.0
*/
function install($parent)
{
$app = JFactory::getApplication();
$app->enqueueMessage(JText::_('COM_IMPRINT_INSTALL_TEXT'));
$parent->getParent()->setRedirectURL('index.php?option=com_imprint');
}
/**
* Method to uninstall the component.
*
* @author mgebhardt
* @param object $parent Is the class calling this method.
* @since 3.0
*/
function uninstall($parent)
{
$app = JFactory::getApplication();
$app->enqueueMessage(JText::_('COM_IMPRINT_UNINSTALL_TEXT'));
}
/**
* Method to update the component.
*
* @author mgebhardt
* @param object $parent Is the class calling this method.
* @since 3.0
*/
function update($parent)
{
$app = JFactory::getApplication();
$app->enqueueMessage(JText::_('COM_IMPRINT_UPDATE_TEXT'));
}
/**
* Method to run before an install/update/uninstall method.
*
* @author mgebhardt
* @param object $parent Is the class calling this method.
* @param string $type Is the type of change (install, update or discover_install).
* @since 3.0.1
*/
function preflight($type, $parent)
{
$newVersion = $parent->get("manifest")->version;
$minJoomla = $parent->get("manifest")->attributes()->version;
$app = JFactory::getApplication();
// Try to get the new imprint version
if($newVersion === false)
{
$app->enqueueMessage(JText::_
('COM_IMPRINT_PREFLIGHT_ERROR_NEW_VERSION'), 'error');
return false;
}
$jversion = new JVersion();
if( version_compare( $jversion->getShortVersion(), $minJoomla, 'lt' ) )
{
// Joomla is to old
$app->enqueueMessage(JText::_
('COM_IMPRINT_PREFLIGHT_ERROR_JOOMLA_VERSION'), 'error');
return false;
}
// abort if the release being installed is not newer than the current installed version
if ( $type == 'update' )
{
$oldVersion = $this->getOldVersion();
$rel = $oldVersion . ' to ' . $newVersion;
if ( version_compare( $newVersion, $oldVersion, 'le' ) )
{
$app->enqueueMessage(JText::_
('COM_IMPRINT_PREFLIGHT_ERROR_IMPRINT_VERSION') . $rel,
'error');
//Incorrect version sequence. Cannot upgrade
return false;
}
}
else
{
$rel = $this->release;
}
//echo '<p>' . JText::_('COM_IMPRINT_PREFLIGHT_' . $type . '_TEXT') . '</p>';
}
/**
* Method to run after an install/update/uninstall method.
*
* @author mgebhardt
* @param string $type Is the type of change (install, update or discover_install).
* @param object $parent Is the class calling this method.
* @since 3.0
*/
function postflight($type, $parent)
{
// Try to migrate from pre 3.1.0
$this->doMigration($type, $parent);
}
/**
* Checks whether the old com_impressum is installed. If com_impressum is
* installed it migrats the data to the newer versions (3.1.0 or later) and
* uninstalls the old version (com_impressum).
*
* You should run this script im postflight function.
*
* @author mgebhardt
* @param string $type Is the type of change (install, update or
* discover_install).
* @param object $parent Is the class calling this method.
* @since 3.1
* @return true if every thing works fine, otherwise flase
*/
function doMigration($type, $parent)
{
// Get application for error messanges, warnings and notice
$app = JFactory::getApplication();
// Check whether an old installation of com_impressum exits
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('extension_id');
$query->from('#__extensions');
$query->where("name LIKE 'com_impressum'");
$db->setQuery($query);
$db->execute();
if($db->getNumRows() == 0)
{
// There is no entry in Joomlas's extensions table.
// You could also check filesystem, admin menu and so on,
// but this would be a bit paranoid. Let's say com_impressum is not
// intalled any more or was not installed.
// So let's stop here.
return true;
}
// Inform admin about the old component
$app->enqueueMessage(JText::_('COM_IMPRINT_MIGRATION_OLD_VERSION_FOUND'));
// Get the id of old version
$oldId = $db->loadResult();
// Get the id of new version
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('extension_id');
$query->from('#__extensions');
$query->where("name LIKE 'com_imprint'");
$db->setQuery($query);
$newId = $db->loadResult();
// 1. delete new default imprint
$query = $db->getQuery(true);
$query->delete('#__imprint_imprints');
$db->setQuery($query);
$db->execute();
// 2. insert all old imprints into new database
// Copy quere must be hard coded without using JDatabaseQuery because
// JDatabaseQuery does not support INSERT - SELECT queries
$db->setQuery('INSERT INTO #__imprint_imprints (`name`, `default`, '
. '`firma`, `name1`, `name2`, `name3`, `name4`, `street`, '
. '`zipcode`, `city`, `country`, `telephone`, `fax`, '
. '`mobilephone`, `website`, `email`, `account_holder`, '
. '`bank_code`, `bank_name`, `account_number`, `iban`, `swift`, '
. '`account_holder2`, `bank_code2`, `bank_name2`, '
. '`account_number2`, `iban2`, `swift2`, `account_holder3`, '
. '`bank_code3`, `bank_name3`, `account_number3`, `iban3`, '
. '`swift3`, `account_holder4`, `bank_code4`, `bank_name4`, '
. '`account_number4`, `iban4`, `swift4`, `vertretertitel`, '
. '`vertreter`, `vertreteremail`, `registergericht`, '
. '`registernummer`, `sales_tax_id`, `economic_id`, '
. '`responsible_for_content`, `responsible_for_content_mail`, '
. '`recht2grund`, `vertretertitel2`, `vertreter2`, '
. '`vertreteremail2`, `registergericht2`, `registernummer2`, '
. '`sales_tax_id2`, `economic_id2`, `responsible_for_content2`, '
. '`responsible_for_content_mail2`, `technikperson`, '
. '`technikwebsite`, `technikemail`, `extra1titel`, '
. '`extra1person`, `extra1website`, `extra1email`, '
. '`extra2titel`, `extra2person`, `extra2website`, '
. '`extra2email`, `extra3titel`, `extra3person`, '
. '`extra3website`, `extra3email`, `template_name`, '
. '`template_creator`, `template_creator_website`, '
. '`template_creator_email`, `contacturl`, `agburl`, '
. '`image`, `misc`, `params`, `image_rights`, `image_sources`, '
. '`adresstitel`, `datenschutztitel`) '
. 'SELECT `name`, `default`, `firma`, `name1`, `name2`, `name3`, '
. '`name4`, `strasse`, `plz`, `ort`, `land`, `telefon`, `fax`, '
. '`handy`, `website`, `email`, `bankinhaber`, `blz`, '
. '`bankname`, `kontonr`, `iban`, `swift`, `bankinhaber2`, '
. '`blz2`, `bankname2`, `kontonr2`, `iban2`, `swift2`, '
. '`bankinhaber3`, `blz3`, `bankname3`, `kontonr3`, `iban3`, '
. '`swift3`, `bankinhaber4`, `blz4`, `bankname4`, `kontonr4`, '
. '`iban4`, `swift4`, `vertretertitel`, `vertreter`, '
. '`vertreteremail`, `registergericht`, `registernummer`, '
. '`ustidnr`, `wirtidnr`, `inhaltperson`, `inhaltemail`, '
. '`recht2grund`, `vertretertitel2`, `vertreter2`, '
. '`vertreteremail2`, `registergericht2`, `registernummer2`, '
. '`ustidnr2`, `wirtidnr2`, `inhaltperson2`, `inhaltemail2`, '
. '`technikperson`, `technikwebsite`, `technikemail`, '
. '`extra1titel`, `extra1person`, `extra1website`, '
. '`extra1email`, `extra2titel`, `extra2person`, '
. '`extra2website`, `extra2email`, `extra3titel`, '
. '`extra3person`, `extra3website`, `extra3email`, '
. '`templatename`, `templatehersteller`, `templatewebsite`, '
. '`templateemail`, `contacturl`, `agburl`, `image`, `misc`, '
. '`params`, `bildrechte`, `bildquellen`, `adresstitel`, '
. '`datenschutztitel` '
. 'FROM #__impressum;');
$db->execute();
// 3. update params and get remark field values
$query = $db->getQuery(true);
$query->select('`id`, `params`');
$query->from('#__imprint_imprints');
$db->setQuery($query);
$imprints = $db->loadAssocList();
if($imprints)
{
foreach ($imprints as $imprint)
{
$remarks = array();
$params = json_decode($imprint['params'], true);
// Convert all old remarks in params to own remark field
if(!isset($params['show_datenschutz']) ||
$params['show_datenschutz'] == 1)
{
$google = false;
$facebook = false;
if(isset($params['show_googleanalytics']) &&
$params['show_googleanalytics'] == 1)
{
$google = true;
}
if(isset($params['show_facebookplugins']) &&
$params['show_facebookplugins'] == 1)
{
$facebook = true;
}
if($google && $facebook)
{
$remarks[] = 'Datenschutz Analytics & Facebook';
}
elseif ($google)
{
$remarks[] = 'Datenschutz Analytics';
}
elseif ($facebook)
{
$remarks[] = 'Datenschutz Facebook';
}
else
{
$remarks[] = 'Datenschutz';
}
}
unset($params['show_datenschutz']);
unset($params['show_googleanalytics']);
unset($params['show_facebookplugins']);
if(!isset($params['show_nutzungsbedingungen']) ||
$params['show_nutzungsbedingungen'] == 1)
{
$remarks[] = 'Nutzungsbedingungen';
}
unset($params['show_nutzungsbedingungen']);
if(isset($params['show_verhaltensregeln']) &&
$params['show_verhaltensregeln'] == 1)
{
$remarks[] = 'Verhaltensregeln';
}
unset($params['show_verhaltensregeln']);
if(isset($params['show_widerrufsrecht']) &&
$params['show_widerrufsrecht'] == 1)
{
$remarks[] = 'Wiederrufsrecht';
}
unset($params['show_widerrufsrecht']);
// Create your own agb
unset($params['show_agb']);
if(!isset($params['show_disclaimer']) ||
$params['show_disclaimer'] == 1)
{
$remarks[] = 'Disclaimer';
}
unset($params['show_disclaimer']);
// Get remark ids
$remarkIds = array();
foreach ($remarks as $remark)
{
$query = $db->getQuery(true);
$query->select('`id`');
$query->from('#__imprint_remarks');
$query->where("name LIKE '$remark'");
$db->setQuery($query);
$remarkIds[] = $db->loadResult();
}
// Write back to database
$params = json_encode($params);
$remarks = implode(';', $remarkIds);
$query = $db->getQuery(true);
$query->update('#__imprint_imprints');
$query->set("params = '$params'");
$query->set("remarks = '$remarks'");
$query->where("id = '" . $imprint['id'] . "'");
$db->setQuery($query);
$db->execute();
}
}
// 4. Update menu item(s)
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__menu');
$query->where("component_id = '$oldId'");
$db->setQuery($query);
$menuItems = $db->loadAssocList();
if($menuItems)
{
foreach ($menuItems as $menuItem)
{
// Only frontend
if($menuItem['menutype'] == 'main')
continue;
$link = str_replace('impressum', 'imprint', $menuItem['link']);
$query = $db->getQuery(true);
$query->update('#__menu');
$query->set("link = '$link'");
$query->set("component_id = '$newId'");
$query->where("id = '" . $menuItem['id'] . "'");
$db->setQuery($query);
$db->execute();
}
}
// 5. Uninstall com_impressum
$installer = JInstaller::getInstance();
if(!$installer->uninstall('component', $oldId))
{
$app->enqueueMessage(JText::_(
'COM_IMPRINT_MIGRATION_CANNOT_UNINSTALL_OLD_VERSION'));
return false;
}
// Every thing works fine
$app->enqueueMessage(JText::_('COM_IMPRINT_MIGRATION_SUCCESS'));
return true;
}
/**
* Method to get the params of the installed version.
*
* @author mgebhardt
* @since 3.0.1
*/
// Does not work. Use getOldVersion to get the version of the installed imprint.
// function getParams()
// {
// $db = JFactory::getDbo();
// $db->setQuery('SELECT manifest_cache FROM #__extensions WHERE name = "com_imprint"');
// $params = new JRegistry();
// $params->loadString($db->loadResult());
// return $params;
// }
/**
* Method to get the version of the install imprint.
*
* @author mgebhardt
* @since 3.0.1
* @return string The version of the installt imprint.
*/
function getOldVersion()
{
$db = JFactory::getDbo();
$db->setQuery('SELECT manifest_cache FROM #__extensions WHERE name = "com_imprint"');
$manifest = json_decode( $db->loadResult(), true );
return $manifest['version'];
}
/**
* Read the new version out of the xml manifestfile
*
* @author chris-schmidt
* @since 3.1
* @return string The version string or
* boolean false if manifestfile or version tag not found.
* @deprecated Use $parent->get("manifest")->version; instead
*/
public static function getCurrentVersion()
{
// Import filesystem libraries
jimport('joomla.filesystem.folder');
// Get folder of this script
$folder = dirname(__FILE__);
// Check whether xml files exsits in this folder;
// otherwhise return null
if (JFolder::exists($folder))
$xmlFilesinDir = JFolder::files($folder, '.xml$');
else
return false;
foreach ($xmlFilesinDir as $xmlfile)
if ($data = JApplicationHelper::parseXMLInstallFile($folder.DS.$xmlfile))
foreach ($data as $key => $value)
if ($key == 'version')
return $value;
// Nothing found?
return null;
}
}