-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.php
111 lines (89 loc) · 2.6 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
<?php
use Joomla\CMS\Factory;
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.installer.installer');
jimport('joomla.installer.helper');
class com_scalerInstallerScript {
/**
* Constructor
*
* @param JAdapterInstance $adapter The object responsible for running this script
*/
public function __constructor(JAdapterInstance $adapter) {
}
private $oldRelease = 0;
/**
* Method to install the component
*
* @param mixed $parent The class calling this method
* @return void
*/
function install(JAdapterInstance $parent) {
echo JText::_('COM_RAIL_INSTALL_SUCCESS');
}
/**
* Method to update the component
*
* @param mixed $parent The class calling this method
* @return void
*/
function update(JAdapterInstance $parent) {
jimport( 'joomla.filesystem.file' );
jimport( 'joomla.application.component.controller' );
Factory::getApplication()->enqueueMessage('Updating com_scaler to version '.
$parent->get('manifest')->version);
return true;
}
/**
* method to run before an install/update/uninstall method
*
* @param mixed $parent The class calling this method
* @return void
*/
function preflight($route, JAdapterInstance $parent) {
$this->oldRelease = $this->getParam ( 'version' );
$files = array ();
//example of how to clean up files. If the old version is before
//a specified version, list files that are no longer wanted
// if (version_compare ( $this->oldRelease, "0.1.2" ) < 0) {
// $files []= JPATH_ADMINISTRATOR . "/components/com_rail/file/path.php";
// }
$this->cleanUpFiles ( $files );
return true;
}
/**
* method to run after an install/update/uninstall method
*
* @param mixed $parent The class calling this method
* @return void
*/
function postflight($route, JAdapterInstance $parent) {
return true;
}
/**
* get a variable from the manifest file (actually, from the manifest cache).
*/
function getParam( $name ) {
$db = Factory::getDbo();
$db->setQuery('SELECT `manifest_cache` FROM #__extensions WHERE `name` = "rail" AND `type` = "component"');
$manifest = json_decode( $db->loadResult(), true );
return $manifest[ $name ];
}
/**
* Removes the files in the given array. Use in preflight to clean up files that
* are no longer needed.
* @param array $files
*/
function cleanUpFiles( $files ) {
foreach ($files as $file) {
if (!file_exists($file))
continue;
if (filetype($file) === 'dir')
JFolder::delete($file);
else
JFile::delete($file);
Factory::getApplication()->enqueueMessage('Deleted '.$file);
}
}
}