forked from redCOMPONENT-COM/redCORE
/
install.php
1684 lines (1447 loc) · 40.5 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
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @package Redcore
* @subpackage Model
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('_JEXEC') or die;
/**
* Custom installation of redCORE
*
* @package Redcore
* @subpackage Install
* @since 1.0
*/
class Com_RedcoreInstallerScript
{
/**
* Status of the installation
*
* @var stdClass
*/
public $status = null;
/**
* Show component info after install / update
*
* @var boolean
*/
public $showComponentInfo = true;
/**
* Installer instance
*
* @var JInstaller
*/
public $installer = null;
/**
* Extension element name
*
* @var string
*/
protected $extensionElement = '';
/**
* Manifest of the extension being processed
*
* @var SimpleXMLElement
*/
protected $manifest;
/**
* Old version according to manifest
*
* @var string
*/
protected $oldVersion = '0.0.0';
/**
* Get the common JInstaller instance used to install all the extensions
*
* @return JInstaller The JInstaller object
*/
public function getInstaller()
{
if (is_null($this->installer))
{
$this->installer = new JInstaller;
}
return $this->installer;
}
/**
* Getter with manifest cache support
*
* @param JInstallerAdapter $parent Parent object
*
* @return SimpleXMLElement
*/
protected function getManifest($parent)
{
if (null === $this->manifest)
{
$this->loadManifest($parent);
}
return $this->manifest;
}
/**
* Method to run before an install/update/uninstall method
*
* @param object $type type of change (install, update or discover_install)
* @param JInstallerAdapter $parent class calling this method
*
* @return bool
*/
public function preflight($type, $parent)
{
$this->installRedcore($type, $parent);
$this->loadRedcoreLibrary();
$this->loadRedcoreLanguage();
$manifest = $this->getManifest($parent);
$extensionType = $manifest->attributes()->type;
$this->extensionElement = $this->getElement($parent, $manifest);
if ($extensionType == 'component' && in_array($type, array('install', 'update', 'discover_install')))
{
// Update SQL pre-processing
if ($type == 'update')
{
// Reads current (old) version from manifest
$db = JFactory::getDbo();
$version = $db->setQuery(
$db->getQuery(true)
->select($db->qn('s.version_id'))
->from($db->qn('#__schemas', 's'))
->join('inner', $db->qn('#__extensions', 'e') . ' ON ' . $db->qn('e.extension_id') . ' = ' . $db->qn('s.extension_id'))
->where('e.element = ' . $db->q($this->extensionElement))
)
->loadResult();
if (!empty($version))
{
$this->oldVersion = (string) $version;
}
if (!$this->preprocessUpdates($parent))
{
return false;
}
}
// In case we are installing redcore
if (get_called_class() == 'Com_RedcoreInstallerScript')
{
if (!$this->checkComponentVersion($this->getRedcoreComponentFolder(), dirname(__FILE__), 'redcore.xml'))
{
JFactory::getApplication()->enqueueMessage(
JText::_('COM_REDCORE_INSTALL_ERROR_OLDER_VERSION'),
'error'
);
return false;
}
if (!class_exists('RComponentHelper'))
{
$searchPaths = array(
// Discover install
JPATH_LIBRARIES . '/redcore/component',
// Install
dirname(__FILE__) . '/redCORE/libraries/redcore/component',
dirname(__FILE__) . '/libraries/redcore/component',
);
if ($componentHelper = JPath::find($searchPaths, 'helper.php'))
{
require_once $componentHelper;
}
}
}
$requirements = array();
if (method_exists('RComponentHelper', 'checkComponentRequirements'))
{
$requirements = RComponentHelper::checkComponentRequirements($manifest->requirements);
}
if (!empty($requirements))
{
foreach ($requirements as $key => $requirement)
{
foreach ($requirement as $checked)
{
if (!$checked['status'])
{
// In case redCORE cannot be installed we do not have the language string
if (get_called_class() == 'Com_RedcoreInstallerScript')
{
$this->loadRedcoreLanguage(dirname(__FILE__));
$checked['name'] = JText::_($checked['name']);
}
$messageKey = $key == 'extensions' ? 'COM_REDCORE_INSTALL_ERROR_REQUIREMENTS_EXTENSIONS' : 'COM_REDCORE_INSTALL_ERROR_REQUIREMENTS';
JFactory::getApplication()->enqueueMessage(
JText::sprintf($messageKey, $checked['name'], $checked['required'], $checked['current']),
'error'
);
return false;
}
}
}
}
}
return true;
}
/**
* Method to install the component
*
* @param JInstallerAdapter $parent Class calling this method
*
* @return boolean True on success
*/
public function install($parent)
{
// Common tasks for install or update
$this->installOrUpdate($parent);
return true;
}
/**
* Method to install the component
*
* @param JInstallerAdapter $parent Class calling this method
*
* @return boolean True on success
*/
public function installOrUpdate($parent)
{
// Install extensions
// We have already installed redCORE library on preflight so we will not do it again
if ((get_called_class() != 'Com_RedcoreInstallerScript'))
{
$this->installLibraries($parent);
}
$this->loadRedcoreLibrary();
$this->installMedia($parent);
$this->installWebservices($parent);
$this->installModules($parent);
$this->installPlugins($parent);
$this->installTemplates($parent);
$this->installCli($parent);
return true;
}
/**
* Method to process SQL updates previous to the install process
*
* @param JInstallerAdapter $parent Class calling this method
*
* @return boolean True on success
*/
public function preprocessUpdates($parent)
{
$manifest = $parent->get('manifest');
if (isset($manifest->update))
{
if (isset($manifest->update->attributes()->folder))
{
$path = $manifest->update->attributes()->folder;
if (isset($manifest->update->pre) && isset($manifest->update->pre->schemas))
{
$schemapaths = $manifest->update->pre->schemas->children();
if (count($schemapaths))
{
$sourcePath = $parent->getParent()->getPath('source');
// If it just upgraded redCORE to a newer version using RFactory for database, it forces using the redCORE database drivers
if (substr(get_class(JFactory::$database), 0, 1) == 'J' && $this->extensionElement != 'com_redcore')
{
RFactory::$database = null;
JFactory::$database = null;
JFactory::$database = RFactory::getDbo();
}
$db = JFactory::getDbo();
$dbDriver = strtolower($db->name);
$schemapath = '';
if ($dbDriver == 'mysqli')
{
$dbDriver = 'mysql';
}
foreach ($schemapaths as $entry)
{
if (isset($entry->attributes()->type))
{
$uDriver = strtolower($entry->attributes()->type);
if ($uDriver == 'mysqli')
{
$uDriver = 'mysql';
}
if ($uDriver == $dbDriver)
{
$schemapath = (string) $entry;
break;
}
}
}
if ($schemapath != '')
{
$files = str_replace('.sql', '', JFolder::files($sourcePath . '/' . $path . '/' . $schemapath, '\.sql$'));
usort($files, 'version_compare');
if (count($files))
{
foreach ($files as $file)
{
if (version_compare($file, $this->oldVersion) > 0)
{
$buffer = file_get_contents($sourcePath . '/' . $path . '/' . $schemapath . '/' . $file . '.sql');
$queries = RHelperDatabase::splitSQL($buffer);
if (count($queries))
{
foreach ($queries as $query)
{
if ($query != '' && $query{0} != '#')
{
$db->setQuery($query);
if (!$db->execute(true))
{
JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)), JLog::WARNING, 'jerror');
return false;
}
}
}
}
}
}
}
}
}
}
}
}
return true;
}
/**
* Method to process PHP update files defined in the manifest file
*
* @param JInstallerAdapter $parent Class calling this method
* @param bool $executeAfterUpdate The name of the function to execute
*
* @return boolean True on success
*/
public function phpUpdates($parent, $executeAfterUpdate)
{
$manifest = $parent->get('manifest');
if (isset($manifest->update))
{
if (isset($manifest->update->php) && isset($manifest->update->php->path))
{
$updatePath = (string) $manifest->update->php->path;
if ($updatePath != '')
{
$sourcePath = JPATH_ADMINISTRATOR . '/components/' . $this->extensionElement;
if (is_dir($sourcePath . '/' . $updatePath))
{
$files = str_replace('.php', '', JFolder::files($sourcePath . '/' . $updatePath, '\.php$'));
if (!empty($files))
{
usort($files, 'version_compare');
if (count($files))
{
foreach ($files as $file)
{
if (version_compare($file, $this->oldVersion) > 0)
{
if (!$this->processPHPUpdateFile($parent, $sourcePath . '/' . $updatePath . '/' . $file . '.php', $file, $executeAfterUpdate))
{
return false;
}
}
}
}
}
}
}
}
}
return true;
}
/**
* Method to process a single PHP update file
*
* @param JInstallerAdapter $parent Class calling this method
* @param string $file File to process
* @param string $version File version
* @param bool $executeAfterUpdate The name of the function to execute
*
* @return boolean True on success
*/
public function processPHPUpdateFile($parent, $file, $version, $executeAfterUpdate)
{
static $upgradeClasses;
if (!isset($upgradeClasses))
{
$upgradeClasses = array();
}
require_once $file;
$class = ucfirst($this->extensionElement) . 'UpdateScript_' . str_replace('.', '_', $version);
$methodName = $executeAfterUpdate ? 'executeAfterUpdate' : 'execute';
if (class_exists($class))
{
if (!isset($upgradeClasses[$class]))
{
$upgradeClasses[$class] = new $class;
}
if (method_exists($upgradeClasses[$class], $methodName))
{
if (!$upgradeClasses[$class]->{$methodName}($parent))
{
return false;
}
}
}
return true;
}
/**
* Install the package libraries
*
* @param JInstallerAdapter $parent class calling this method
*
* @return void
*/
private function installLibraries($parent)
{
// Required objects
$installer = $this->getInstaller();
$manifest = $this->getManifest($parent);
$src = $parent->getParent()->getPath('source');
if ($nodes = $manifest->libraries->library)
{
foreach ($nodes as $node)
{
$extName = $node->attributes()->name;
$extPath = $src . '/libraries/' . $extName;
$result = 0;
// Standard install
if (is_dir($extPath))
{
$result = $installer->install($extPath);
}
// Discover install
elseif ($extId = $this->searchExtension($extName, 'library', '-1'))
{
$result = $installer->discover_install($extId);
}
$this->_storeStatus('libraries', array('name' => $extName, 'result' => $result));
}
}
}
/**
* Install the media folder
*
* @param JInstallerAdapter $parent class calling this method
*
* @return void
*/
private function installMedia($parent)
{
$installer = $this->getInstaller();
$manifest = $this->getManifest($parent);
$src = $parent->getParent()->getPath('source');
if ($manifest && $manifest->attributes()->type == 'package')
{
$installer->setPath('source', $src);
$installer->parseMedia($manifest->media);
}
}
/**
* Install the package modules
*
* @param JInstallerAdapter $parent class calling this method
*
* @return void
*/
protected function installModules($parent)
{
// Required objects
$installer = $this->getInstaller();
$manifest = $parent->get('manifest');
$src = $parent->getParent()->getPath('source');
if ($nodes = $manifest->modules->module)
{
foreach ($nodes as $node)
{
$extName = $node->attributes()->name;
$extClient = $node->attributes()->client;
$extPath = $src . '/modules/' . $extClient . '/' . $extName;
$result = 0;
// Standard install
if (is_dir($extPath))
{
$installer->setAdapter('module');
$result = $installer->install($extPath);
}
elseif ($extId = $this->searchExtension($extName, 'module', '-1'))
// Discover install
{
$result = $installer->discover_install($extId);
}
$this->_storeStatus('modules', array('name' => $extName, 'client' => $extClient, 'result' => $result));
}
}
}
/**
* Install the package libraries
*
* @param JInstallerAdapter $parent class calling this method
*
* @return void
*/
protected function installPlugins($parent)
{
// Required objects
$installer = $this->getInstaller();
$manifest = $parent->get('manifest');
$src = $parent->getParent()->getPath('source');
if ($nodes = $manifest->plugins->plugin)
{
foreach ($nodes as $node)
{
$extName = $node->attributes()->name;
$extGroup = $node->attributes()->group;
$disabled = !empty($node->attributes()->disabled) ? true : false;
$extPath = $src . '/plugins/' . $extGroup . '/' . $extName;
$result = 0;
// Standard install
if (is_dir($extPath))
{
$installer->setAdapter('plugin');
$result = $installer->install($extPath);
}
elseif ($extId = $this->searchExtension($extName, 'plugin', '-1', $extGroup))
// Discover install
{
$result = $installer->discover_install($extId);
}
// Store the result to show install summary later
$this->_storeStatus('plugins', array('name' => $extName, 'group' => $extGroup, 'result' => $result));
// Enable the installed plugin
if ($result && !$disabled)
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->update($db->quoteName("#__extensions"));
$query->set("enabled=1");
$query->set('state = 0');
$query->where("type='plugin'");
$query->where("element=" . $db->quote($extName));
$query->where("folder=" . $db->quote($extGroup));
$db->setQuery($query);
$db->execute();
}
}
}
}
/**
* Install the package translations
*
* @param JInstallerAdapter $parent class calling this method
*
* @return void
*/
protected function installTranslations($parent)
{
// Required objects
$manifest = $parent->get('manifest');
if (method_exists('RTranslationTable', 'batchContentElements'))
{
if ($nodes = $manifest->translations->translation)
{
foreach ($nodes as $node)
{
$extName = (string) $node->attributes()->name;
try
{
RTranslationTable::batchContentElements($extName, 'install', false);
}
catch (Exception $e)
{
// We are already setting message queue so we don't need to set it here as well
}
$this->_storeStatus('translations', array('name' => $extName, 'result' => true));
}
}
}
}
/**
* Function to install redCORE for components
*
* @param object $type type of change (install, update or discover_install)
* @param JInstallerAdapter $parent class calling this method
*
* @return void
*/
protected function installRedcore($type, $parent)
{
// If it's installing redcore as dependency
if (get_called_class() != 'Com_RedcoreInstallerScript' && $type != 'discover_install')
{
$manifest = $this->getManifest($parent);
if ($manifest->redcore)
{
$installer = $this->getInstaller();
$redcoreFolder = dirname(__FILE__);
$redcoreComponentFolder = $this->getRedcoreComponentFolder();
if (is_dir($redcoreFolder) && JPath::clean($redcoreFolder) != JPath::clean($redcoreComponentFolder))
{
$install = $this->checkComponentVersion($redcoreComponentFolder, $redcoreFolder, 'redcore.xml');
if ($install)
{
$installer->install($redcoreFolder);
$this->loadRedcoreLibrary();
}
}
}
}
// If it is installing redCORE we want to make sure it installs redCORE library first
elseif (get_called_class() == 'Com_RedcoreInstallerScript' && in_array($type, array('install', 'update', 'discover_install')))
{
$install = $this->checkComponentVersion(JPATH_LIBRARIES . '/redcore', dirname(__FILE__) . '/libraries/redcore', 'redcore.xml');
// Only install if installation in the package is newer version
if ($install)
{
$this->installLibraries($parent);
}
}
}
/**
* Function to install redCORE for components
*
* @param JInstallerAdapter $parent class calling this method
*
* @return void
*/
protected function postInstallRedcore($parent)
{
$manifest = $this->getManifest($parent);
$type = $manifest->attributes()->type;
if ($type == 'component')
{
if ($redcoreNode = $manifest->redcore)
{
$redcoreFolder = dirname(__FILE__);
if (!empty($redcoreFolder))
{
$version = $redcoreNode->attributes()->version;
$class = get_called_class();
$option = strtolower(strstr($class, 'Installer', true));
$db = JFactory::getDBO();
$query = $db->getQuery(true)
->select('params')
->from($db->quoteName("#__extensions"))
->where("type=" . $db->quote($type))
->where("element=" . $db->quote($option));
$db->setQuery($query);
$comParams = new JRegistry($db->loadResult());
$comParams->set('redcore',
array(
'version' => (string) $version)
);
$query = $db->getQuery(true);
$query->update($db->quoteName("#__extensions"));
$query->set('params = ' . $db->quote($comParams->toString()));
$query->where("type=" . $db->quote($type));
$query->where("element=" . $db->quote($option));
$db->setQuery($query);
$db->execute();
}
}
}
}
/**
* Install the package templates
*
* @param JInstallerAdapter $parent class calling this method
*
* @return void
*/
private function installTemplates($parent)
{
// Required objects
$installer = $this->getInstaller();
$manifest = $parent->get('manifest');
$src = $parent->getParent()->getPath('source');
if ($nodes = $manifest->templates->template)
{
foreach ($nodes as $node)
{
$extName = $node->attributes()->name;
$extClient = $node->attributes()->client;
$extPath = $src . '/templates/' . $extClient . '/' . $extName;
$result = 0;
// Standard install
if (is_dir($extPath))
{
$installer->setAdapter('template');
$result = $installer->install($extPath);
}
// Discover install
elseif ($extId = $this->searchExtension($extName, 'template', '-1'))
{
$result = $installer->discover_install($extId);
}
$this->_storeStatus('templates', array('name' => $extName, 'client' => $extClient, 'result' => $result));
}
}
}
/**
* Install the package Cli scripts
*
* @param JInstallerAdapter $parent class calling this method
*
* @return void
*/
private function installCli($parent)
{
// Required objects
$installer = $this->getInstaller();
$manifest = $parent->get('manifest');
$src = $parent->getParent()->getPath('source');
if (!$manifest)
{
return;
}
$installer->setPath('source', $src);
$element = $manifest->cli;
if (!$element || !count($element->children()))
{
// Either the tag does not exist or has no children therefore we return zero files processed.
return;
}
$nodes = $element->children();
foreach ($nodes as $node)
{
// Here we set the folder name we are going to copy the files to.
$name = (string) $node->attributes()->name;
// Here we set the folder we are going to copy the files to.
$destination = JPath::clean(JPATH_ROOT . '/cli/' . $name);
// Here we set the folder we are going to copy the files from.
$folder = (string) $node->attributes()->folder;
if ($folder && file_exists($src . '/' . $folder))
{
$source = $src . '/' . $folder;
}
else
{
// Cli folder does not exist
continue;
}
$copyFiles = $this->prepareFilesForCopy($element, $source, $destination);
$installer->copyFiles($copyFiles, true);
}
}
/**
* Method to parse through a webservices element of the installation manifest and take appropriate
* action.
*
* @param JInstallerAdapter $parent class calling this method
*
* @return boolean True on success
*
* @since 1.3
*/
public function installWebservices($parent)
{
$installer = $this->getInstaller();
$manifest = $this->getManifest($parent);
$src = $parent->getParent()->getPath('source');
if (!$manifest)
{
return false;
}
$installer->setPath('source', $src);
$element = $manifest->webservices;
if (!$element || !count($element->children()))
{
// Either the tag does not exist or has no children therefore we return zero files processed.
return false;
}
// Here we set the folder we are going to copy the files from.
$folder = (string) $element->attributes()->folder;
// This prevents trying to install webservice from other extension directory if webservice folder is not set
if (!$folder || !is_dir($src . '/' . $folder))
{
return false;
}
// Here we set the folder we are going to copy the files to.
$destination = JPath::clean(RApiHalHelper::getWebservicesPath());
$source = $src . '/' . $folder;
$copyFiles = $this->prepareFilesForCopy($element, $source, $destination);
// Copy the webservice XML files
$return = $installer->copyFiles($copyFiles, true);
// Recreate or create new SOAP WSDL files
if (method_exists('RApiSoapHelper', 'generateWsdlFromFolder'))
{
foreach ($element->children() as $file)
{
RApiSoapHelper::generateWsdlFromFolder($destination . '/' . $file);
}
}
return $return;
}
/**
* Method to parse through a xml element of the installation manifest and take appropriate action.
*
* @param SimpleXMLElement $element Element to iterate
* @param string $source Source location of the files
* @param string $destination Destination location of the files
*
* @return array
*
* @since 1.4
*/
public function prepareFilesForCopy($element, $source, $destination)
{
$copyFiles = array();
// Process each file in the $files array (children of $tagName).
foreach ($element->children() as $file)
{
$path = array();
$path['src'] = $source . '/' . $file;
$path['dest'] = $destination . '/' . $file;
// Is this path a file or folder?
$path['type'] = ($file->getName() == 'folder') ? 'folder' : 'file';
if (basename($path['dest']) != $path['dest'])
{
$newdir = dirname($path['dest']);
if (!JFolder::create($newdir))
{
JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_CREATE_DIRECTORY', $newdir), JLog::WARNING, 'jerror');
return false;
}
}
// Add the file to the copyfiles array
$copyFiles[] = $path;
}
return $copyFiles;
}
/**
* Method to run after an install/update/uninstall method
*
* @param object $type type of change (install, update or discover_install)
* @param JInstallerAdapter $parent class calling this method
*
* @return boolean
*/
public function postflight($type, $parent)
{
// If it's installing redcore as dependency
if (get_called_class() != 'Com_RedcoreInstallerScript' && $type != 'discover_install')
{
$this->postInstallRedcore($parent);
}
// Execute the postflight tasks from the manifest
$this->postFlightFromManifest($type, $parent);
$this->installTranslations($parent);
if (in_array($type, array('install', 'update', 'discover_install')))
{
/** @var JXMLElement $manifest */
$manifest = $parent->get('manifest');
$attributes = current($manifest->attributes());
// If it's a component
if (isset($attributes['type']) && (string) $attributes['type'] == 'component')
{
$this->loadRedcoreLanguage();
$this->displayComponentInfo($parent);
}
}
return true;
}
/**
* Execute the postflight tasks from the manifest if there is any.
*
* @param object $type type of change (install, update or discover_install)
* @param JInstallerAdapter $parent class calling this method
*
* @return void
*/
protected function postFlightFromManifest($type, $parent)
{
$manifest = $parent->get('manifest');
if ($tasks = $manifest->postflight->task)
{
/** @var JXMLElement $task */
foreach ($tasks as $task)
{
$attributes = current($task->attributes());
// No task name
if (!isset($attributes['name']))
{
continue;
}