InstallerAdapter.php
24.5 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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Installer;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Installer\Manifest\PackageManifest;
use Joomla\CMS\Table\Extension;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Table\TableInterface;
\JLoader::import('joomla.base.adapterinstance');
/**
* Abstract adapter for the installer.
*
* @method Installer getParent() Retrieves the parent object.
* @property-read Installer $parent Parent object
*
* @since 3.4
* @note As of 4.0, this class will no longer extend from JAdapterInstance
*/
abstract class InstallerAdapter extends \JAdapterInstance
{
/**
* ID for the currently installed extension if present
*
* @var integer
* @since 3.4
*/
protected $currentExtensionId = null;
/**
* The unique identifier for the extension (e.g. mod_login)
*
* @var string
* @since 3.4
* */
protected $element = null;
/**
* Extension object.
*
* @var Extension
* @since 3.4
* */
protected $extension = null;
/**
* Messages rendered by custom scripts
*
* @var string
* @since 3.4
*/
protected $extensionMessage = '';
/**
* Copy of the XML manifest file.
*
* Making this object public allows extensions to customize the manifest in custom scripts.
*
* @var string
* @since 3.4
*/
public $manifest = null;
/**
* A path to the PHP file that the scriptfile declaration in the manifest refers to.
*
* @var string
* @since 3.4
*/
protected $manifest_script = null;
/**
* Name of the extension
*
* @var string
* @since 3.4
*/
protected $name = null;
/**
* Install function routing
*
* @var string
* @since 3.4
*/
protected $route = 'install';
/**
* Flag if the adapter supports discover installs
*
* Adapters should override this and set to false if discover install is unsupported
*
* @var boolean
* @since 3.4
*/
protected $supportsDiscoverInstall = true;
/**
* The type of adapter in use
*
* @var string
* @since 3.4
*/
protected $type;
/**
* Constructor
*
* @param Installer $parent Parent object
* @param \JDatabaseDriver $db Database object
* @param array $options Configuration Options
*
* @since 3.4
*/
public function __construct(Installer $parent, \JDatabaseDriver $db, array $options = array())
{
parent::__construct($parent, $db, $options);
// Get a generic TableExtension instance for use if not already loaded
if (!($this->extension instanceof TableInterface))
{
$this->extension = Table::getInstance('extension');
}
// Sanity check, make sure the type is set by taking the adapter name from the class name
if (!$this->type)
{
// This assumes the adapter short class name in its namespace is `<foo>Adapter`, replace this logic in subclasses if needed
$reflection = new \ReflectionClass(get_called_class());
$this->type = str_replace('Adapter', '', $reflection->getShortName());
}
// Extension type is stored as lowercase in the database
$this->type = strtolower($this->type);
}
/**
* Check if a package extension allows its child extensions to be uninstalled individually
*
* @param integer $packageId The extension ID of the package to check
*
* @return boolean
*
* @since 3.7.0
* @note This method defaults to true to emulate the behavior of 3.6 and earlier which did not support this lookup
*/
protected function canUninstallPackageChild($packageId)
{
$package = Table::getInstance('extension');
// If we can't load this package ID, we have a corrupt database
if (!$package->load((int) $packageId))
{
return true;
}
$manifestFile = JPATH_MANIFESTS . '/packages/' . $package->element . '.xml';
$xml = $this->parent->isManifest($manifestFile);
// If the manifest doesn't exist, we've got some major issues
if (!$xml)
{
return true;
}
$manifest = new PackageManifest($manifestFile);
return $manifest->blockChildUninstall === false;
}
/**
* Method to check if the extension is already present in the database
*
* @return void
*
* @since 3.4
* @throws \RuntimeException
*/
protected function checkExistingExtension()
{
try
{
$this->currentExtensionId = $this->extension->find(
array('element' => $this->element, 'type' => $this->type)
);
// If it does exist, load it
if ($this->currentExtensionId)
{
$this->extension->load(array('element' => $this->element, 'type' => $this->type));
}
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
throw new \RuntimeException(
\JText::sprintf(
'JLIB_INSTALLER_ABORT_ROLLBACK',
\JText::_('JLIB_INSTALLER_' . $this->route),
$e->getMessage()
),
$e->getCode(),
$e
);
}
}
/**
* Method to check if the extension is present in the filesystem, flags the route as update if so
*
* @return void
*
* @since 3.4
* @throws \RuntimeException
*/
protected function checkExtensionInFilesystem()
{
if (file_exists($this->parent->getPath('extension_root')) && (!$this->parent->isOverwrite() || $this->parent->isUpgrade()))
{
// Look for an update function or update tag
$updateElement = $this->getManifest()->update;
// Upgrade manually set or update function available or update tag detected
if ($updateElement || $this->parent->isUpgrade()
|| ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'update')))
{
// Force this one
$this->parent->setOverwrite(true);
$this->parent->setUpgrade(true);
if ($this->currentExtensionId)
{
// If there is a matching extension mark this as an update
$this->setRoute('update');
}
}
elseif (!$this->parent->isOverwrite())
{
// We didn't have overwrite set, find an update function or find an update tag so lets call it safe
throw new \RuntimeException(
\JText::sprintf(
'JLIB_INSTALLER_ABORT_DIRECTORY',
\JText::_('JLIB_INSTALLER_' . $this->route),
$this->type,
$this->parent->getPath('extension_root')
)
);
}
}
}
/**
* Method to copy the extension's base files from the `<files>` tag(s) and the manifest file
*
* @return void
*
* @since 3.4
* @throws \RuntimeException
*/
abstract protected function copyBaseFiles();
/**
* Method to create the extension root path if necessary
*
* @return void
*
* @since 3.4
* @throws \RuntimeException
*/
protected function createExtensionRoot()
{
// If the extension directory does not exist, lets create it
$created = false;
if (!file_exists($this->parent->getPath('extension_root')))
{
if (!$created = \JFolder::create($this->parent->getPath('extension_root')))
{
throw new \RuntimeException(
\JText::sprintf(
'JLIB_INSTALLER_ABORT_CREATE_DIRECTORY',
\JText::_('JLIB_INSTALLER_' . $this->route),
$this->parent->getPath('extension_root')
)
);
}
}
/*
* Since we created the extension directory and will want to remove it if
* we have to roll back the installation, let's add it to the
* installation step stack
*/
if ($created)
{
$this->parent->pushStep(
array(
'type' => 'folder',
'path' => $this->parent->getPath('extension_root'),
)
);
}
}
/**
* Generic discover_install method for extensions
*
* @return boolean True on success
*
* @since 3.4
*/
public function discover_install()
{
// Get the extension's description
$description = (string) $this->getManifest()->description;
if ($description)
{
$this->parent->message = \JText::_($description);
}
else
{
$this->parent->message = '';
}
// Set the extension's name and element
$this->name = $this->getName();
$this->element = $this->getElement();
/*
* ---------------------------------------------------------------------------------------------
* Extension Precheck and Setup Section
* ---------------------------------------------------------------------------------------------
*/
// Setup the install paths and perform other prechecks as necessary
try
{
$this->setupInstallPaths();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
/*
* ---------------------------------------------------------------------------------------------
* Installer Trigger Loading
* ---------------------------------------------------------------------------------------------
*/
$this->setupScriptfile();
try
{
$this->triggerManifestScript('preflight');
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
/*
* ---------------------------------------------------------------------------------------------
* Database Processing Section
* ---------------------------------------------------------------------------------------------
*/
try
{
$this->storeExtension();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
try
{
$this->parseQueries();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
// Run the custom install method
try
{
$this->triggerManifestScript('install');
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
/*
* ---------------------------------------------------------------------------------------------
* Finalization and Cleanup Section
* ---------------------------------------------------------------------------------------------
*/
try
{
$this->finaliseInstall();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
// And now we run the postflight
try
{
$this->triggerManifestScript('postflight');
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
return $this->extension->extension_id;
}
/**
* Method to handle database transactions for the installer
*
* @return boolean True on success
*
* @since 3.4
* @throws \RuntimeException
*/
protected function doDatabaseTransactions()
{
$route = $this->route === 'discover_install' ? 'install' : $this->route;
// Let's run the install queries for the component
if (isset($this->getManifest()->{$route}->sql))
{
$result = $this->parent->parseSQLFiles($this->getManifest()->{$route}->sql);
if ($result === false)
{
// Only rollback if installing
if ($route === 'install')
{
throw new \RuntimeException(
\JText::sprintf(
'JLIB_INSTALLER_ABORT_SQL_ERROR',
\JText::_('JLIB_INSTALLER_' . strtoupper($this->route)),
$this->parent->getDbo()->stderr(true)
)
);
}
return false;
}
// If installing with success and there is an uninstall script, add an installer rollback step to rollback if needed
if ($route === 'install' && isset($this->getManifest()->uninstall->sql))
{
$this->parent->pushStep(array('type' => 'query', 'script' => $this->getManifest()->uninstall->sql));
}
}
return true;
}
/**
* Load language files
*
* @param string $extension The name of the extension
* @param string $source Path to the extension
* @param string $base Base path for the extension language
*
* @return void
*
* @since 3.4
*/
protected function doLoadLanguage($extension, $source, $base = JPATH_ADMINISTRATOR)
{
$lang = \JFactory::getLanguage();
$lang->load($extension . '.sys', $source, null, false, true) || $lang->load($extension . '.sys', $base, null, false, true);
}
/**
* Checks if the adapter supports discover_install
*
* @return boolean
*
* @since 3.4
*/
public function getDiscoverInstallSupported()
{
return $this->supportsDiscoverInstall;
}
/**
* Get the filtered extension element from the manifest
*
* @param string $element Optional element name to be converted
*
* @return string The filtered element
*
* @since 3.4
*/
public function getElement($element = null)
{
if (!$element)
{
// Ensure the element is a string
$element = (string) $this->getManifest()->element;
}
if (!$element)
{
$element = $this->getName();
}
// Filter the name for illegal characters
return strtolower(\JFilterInput::getInstance()->clean($element, 'cmd'));
}
/**
* Get the manifest object.
*
* @return \SimpleXMLElement Manifest object
*
* @since 3.4
*/
public function getManifest()
{
return $this->manifest;
}
/**
* Get the filtered component name from the manifest
*
* @return string The filtered name
*
* @since 3.4
*/
public function getName()
{
// Ensure the name is a string
$name = (string) $this->getManifest()->name;
// Filter the name for illegal characters
$name = \JFilterInput::getInstance()->clean($name, 'string');
return $name;
}
/**
* Get the install route being followed
*
* @return string The install route
*
* @since 3.4
*/
public function getRoute()
{
return $this->route;
}
/**
* Get the class name for the install adapter script.
*
* @return string The class name.
*
* @since 3.4
*/
protected function getScriptClassName()
{
// Support element names like 'en-GB'
$className = \JFilterInput::getInstance()->clean($this->element, 'cmd') . 'InstallerScript';
// Cannot have - in class names
$className = str_replace('-', '', $className);
return $className;
}
/**
* Generic install method for extensions
*
* @return boolean|integer The extension ID on success, boolean false on failure
*
* @since 3.4
*/
public function install()
{
// Get the extension's description
$description = (string) $this->getManifest()->description;
if ($description)
{
$this->parent->message = \JText::_($description);
}
else
{
$this->parent->message = '';
}
// Set the extension's name and element
$this->name = $this->getName();
$this->element = $this->getElement();
/*
* ---------------------------------------------------------------------------------------------
* Extension Precheck and Setup Section
* ---------------------------------------------------------------------------------------------
*/
// Setup the install paths and perform other prechecks as necessary
try
{
$this->setupInstallPaths();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
// Check to see if an extension by the same name is already installed.
try
{
$this->checkExistingExtension();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
// Check if the extension is present in the filesystem
try
{
$this->checkExtensionInFilesystem();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
// If we are on the update route, run any custom setup routines
if ($this->route === 'update')
{
try
{
$this->setupUpdates();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
}
/*
* ---------------------------------------------------------------------------------------------
* Installer Trigger Loading
* ---------------------------------------------------------------------------------------------
*/
$this->setupScriptfile();
try
{
$this->triggerManifestScript('preflight');
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
/*
* ---------------------------------------------------------------------------------------------
* Filesystem Processing Section
* ---------------------------------------------------------------------------------------------
*/
// If the extension directory does not exist, lets create it
try
{
$this->createExtensionRoot();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
// Copy all necessary files
try
{
$this->copyBaseFiles();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
// Parse optional tags
$this->parseOptionalTags();
/*
* ---------------------------------------------------------------------------------------------
* Database Processing Section
* ---------------------------------------------------------------------------------------------
*/
try
{
$this->storeExtension();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
try
{
$this->parseQueries();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
// Run the custom method based on the route
try
{
$this->triggerManifestScript($this->route);
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
/*
* ---------------------------------------------------------------------------------------------
* Finalization and Cleanup Section
* ---------------------------------------------------------------------------------------------
*/
try
{
$this->finaliseInstall();
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
// And now we run the postflight
try
{
$this->triggerManifestScript('postflight');
}
catch (\RuntimeException $e)
{
// Install failed, roll back changes
$this->parent->abort($e->getMessage());
return false;
}
return $this->extension->extension_id;
}
/**
* Method to parse the queries specified in the `<sql>` tags
*
* @return void
*
* @since 3.4
* @throws \RuntimeException
*/
protected function parseQueries()
{
// Let's run the queries for the extension
if (in_array($this->route, array('install', 'discover_install', 'uninstall')))
{
// This method may throw an exception, but it is caught by the parent caller
if (!$this->doDatabaseTransactions())
{
throw new \RuntimeException(
\JText::sprintf(
'JLIB_INSTALLER_ABORT_SQL_ERROR',
\JText::_('JLIB_INSTALLER_' . strtoupper($this->route)),
$this->db->stderr(true)
)
);
}
// Set the schema version to be the latest update version
if ($this->getManifest()->update)
{
$this->parent->setSchemaVersion($this->getManifest()->update->schemas, $this->extension->extension_id);
}
}
elseif ($this->route === 'update')
{
if ($this->getManifest()->update)
{
$result = $this->parent->parseSchemaUpdates($this->getManifest()->update->schemas, $this->extension->extension_id);
if ($result === false)
{
// Install failed, rollback changes
throw new \RuntimeException(
\JText::sprintf(
'JLIB_INSTALLER_ABORT_SQL_ERROR',
\JText::_('JLIB_INSTALLER_' . strtoupper($this->route)),
$this->db->stderr(true)
)
);
}
}
}
}
/**
* Method to parse optional tags in the manifest
*
* @return void
*
* @since 3.1
*/
protected function parseOptionalTags()
{
// Some extensions may not have optional tags
}
/**
* Prepares the adapter for a discover_install task
*
* @return void
*
* @since 3.4
*/
public function prepareDiscoverInstall()
{
// Adapters may not support discover install or may have overridden the default task and aren't using this
}
/**
* Set the manifest object.
*
* @param object $manifest The manifest object
*
* @return InstallerAdapter Instance of this class to support chaining
*
* @since 3.4
*/
public function setManifest($manifest)
{
$this->manifest = $manifest;
return $this;
}
/**
* Set the install route being followed
*
* @param string $route The install route being followed
*
* @return InstallerAdapter Instance of this class to support chaining
*
* @since 3.4
*/
public function setRoute($route)
{
$this->route = $route;
return $this;
}
/**
* Method to do any prechecks and setup the install paths for the extension
*
* @return void
*
* @since 3.4
*/
abstract protected function setupInstallPaths();
/**
* Setup the manifest script file for those adapters that use it.
*
* @return void
*
* @since 3.4
*/
protected function setupScriptfile()
{
// If there is a manifest class file, lets load it; we'll copy it later (don't have dest yet)
$manifestScript = (string) $this->getManifest()->scriptfile;
if ($manifestScript)
{
$manifestScriptFile = $this->parent->getPath('source') . '/' . $manifestScript;
$classname = $this->getScriptClassName();
\JLoader::register($classname, $manifestScriptFile);
if (class_exists($classname))
{
// Create a new instance
$this->parent->manifestClass = new $classname($this);
// And set this so we can copy it later
$this->manifest_script = $manifestScript;
}
}
}
/**
* Method to setup the update routine for the adapter
*
* @return void
*
* @since 3.4
*/
protected function setupUpdates()
{
// Some extensions may not have custom setup routines for updates
}
/**
* Method to store the extension to the database
*
* @return void
*
* @since 3.4
* @throws \RuntimeException
*/
abstract protected function storeExtension();
/**
* Executes a custom install script method
*
* @param string $method The install method to execute
*
* @return boolean True on success
*
* @since 3.4
* @throws \RuntimeException
*/
protected function triggerManifestScript($method)
{
ob_start();
ob_implicit_flush(false);
if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, $method))
{
switch ($method)
{
// The preflight and postflight take the route as a param
case 'preflight' :
case 'postflight' :
if ($this->parent->manifestClass->$method($this->route, $this) === false)
{
if ($method !== 'postflight')
{
// Clean and close the output buffer
ob_end_clean();
// The script failed, rollback changes
throw new \RuntimeException(
\JText::sprintf(
'JLIB_INSTALLER_ABORT_INSTALL_CUSTOM_INSTALL_FAILURE',
\JText::_('JLIB_INSTALLER_' . $this->route)
)
);
}
}
break;
// The install, uninstall, and update methods only pass this object as a param
case 'install' :
case 'uninstall' :
case 'update' :
if ($this->parent->manifestClass->$method($this) === false)
{
if ($method !== 'uninstall')
{
// Clean and close the output buffer
ob_end_clean();
// The script failed, rollback changes
throw new \RuntimeException(
\JText::sprintf(
'JLIB_INSTALLER_ABORT_INSTALL_CUSTOM_INSTALL_FAILURE',
\JText::_('JLIB_INSTALLER_' . $this->route)
)
);
}
}
break;
}
}
// Append to the message object
$this->extensionMessage .= ob_get_clean();
// If in postflight or uninstall, set the message for display
if (($method === 'uninstall' || $method === 'postflight') && $this->extensionMessage !== '')
{
$this->parent->set('extension_message', $this->extensionMessage);
}
return true;
}
/**
* Generic update method for extensions
*
* @return boolean|integer The extension ID on success, boolean false on failure
*
* @since 3.4
*/
public function update()
{
// Set the overwrite setting
$this->parent->setOverwrite(true);
$this->parent->setUpgrade(true);
// And make sure the route is set correctly
$this->setRoute('update');
// Now jump into the install method to run the update
return $this->install();
}
}