PluginProbe
CSS & JavaScript Toolbox / 10
CSS & JavaScript Toolbox v10
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
← All changes | models/installer.php +81 -48 6.010 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 -*
3 +*
4 4 */
5 5
6 6 // Disallow direct access.
7 7 defined('ABSPATH') or die("Access denied");
@@ -6,52 +6,52 @@
6 6 // Disallow direct access.
7 7 defined('ABSPATH') or die("Access denied");
8 8
9 9 /**
10 -*
10 +*
11 11 */
12 12 class CJTInstallerModel {
13 -
13 +
14 14 /**
15 - *
15 + *
16 16 */
17 17 const OPERATION_STATE_INSTALLED = 'installed';
18 -
18 +
19 19 /**
20 - *
20 + *
21 21 */
22 22 const INSTALLATION_STATE = 'state.CJTInstallerModel.operations';
23 -
23 +
24 24 /**
25 - *
25 + *
26 26 */
27 27 const NOTICED_DISMISSED_OPTION_NAME = 'settings.CJTInstallerModel.noticeDismissed';
28 -
28 +
29 29 /**
30 30 * put your comment there...
31 - *
31 + *
32 32 * @var mixed
33 33 */
34 34 protected $input;
35 -
35 +
36 36 /**
37 37 * put your comment there...
38 - *
38 + *
39 39 * @var mixed
40 40 */
41 41 protected $installedDbVersion;
42 -
42 +
43 43 /**
44 44 * put your comment there...
45 - *
45 + *
46 46 */
47 47 public function __construct() {
48 48 $this->installedDbVersion = get_option(CJTPlugin::DB_VERSION_OPTION_NAME);
49 49 }
50 -
50 +
51 51 /**
52 52 * put your comment there...
53 - *
53 + *
54 54 * @param mixed $dismiss
55 55 */
56 56 public function dismissNotice($dismiss = null) {
57 57 // Read current value!
@@ -61,52 +61,60 @@
61 61 update_user_option(get_current_user_id(), self::NOTICED_DISMISSED_OPTION_NAME, true);
62 62 }
63 63 return $currentValue;
64 64 }
65 -
65 +
66 66 /**
67 67 * put your comment there...
68 - *
68 + *
69 69 */
70 70 public function getInstalledDbVersion() {
71 71 return $this->installedDbVersion;
72 72 }
73 -
73 +
74 74 /**
75 75 * put your comment there...
76 - *
76 + *
77 77 */
78 78 public function getInternalVersionName() {
79 - return str_replace('.', '', $this->installedDbVersion);
79 + return str_replace(array('.', '-'), '', $this->installedDbVersion);
80 80 }
81 -
81 +
82 82 /**
83 - * put your comment there...
84 - *
83 + * Get installer operations for current CJT version!
84 + *
85 + * @return array Operations list metadata.
85 86 */
86 87 public function getOperations() {
87 - // If installation is didn't never run before thise would be unset!
88 - if (!($operations = get_option(self::INSTALLATION_STATE))) {
88 + // Read all install/upgrade operations for all versions!
89 + $operations = get_option(self::INSTALLATION_STATE);
90 + $operations = is_array($operations) ? $operations : array();
91 + // Check if cached: Use only installer cache for 'current' CJT version.
92 + if (!isset($operations[CJTPlugin::DB_VERSION])) {
89 93 // Import installer reflection!
90 94 cssJSToolbox::import('framework:installer:reflection.class.php');
91 95 // Get Installer operations.
92 96 cssJSToolbox::import('includes:installer:installer:installer.class.php');
93 - $operations['operations']['install'] = CJTInstallerReflection::getInstance('CJTInstaller', 'CJTInstaller')->getOperations();
97 + $operations[CJTPlugin::DB_VERSION]['operations']['install'] = CJTInstallerReflection::getInstance('CJTInstaller', 'CJTInstaller')->getOperations();
94 98 if ($this->isUpgrade()) {
95 99 // Get upgrade operations , Also cache upgrader info for later use!
96 - $operations['upgrader'] = $upgrader = $this->getUpgrader();
100 + $operations[CJTPlugin::DB_VERSION]['upgrader'] = $upgrader = $this->getUpgrader();
101 + // Check if upgrader exists!
102 + if (!file_exists(cssJSToolbox::resolvePath($upgrader['file']))) {
103 + throw new Exception("Could not find upgrade/downgrade agent for installer '{$this->installedDbVersion}'! Incompatible version numbers! Upgrader/Downgrwader is no being supported by current versions!!");
104 + }
105 + // Import upgrader + reflect its operations!
97 106 cssJSToolbox::import($upgrader['file']);
98 - $operations['operations']['upgrade'] = CJTInstallerReflection::getInstance($upgrader['class'], 'CJTUpgradeNonTabledVersions')->getOperations();
107 + $operations[CJTPlugin::DB_VERSION]['operations']['upgrade'] = CJTInstallerReflection::getInstance($upgrader['class'], 'CJTUpgradeNonTabledVersions')->getOperations();
99 108 }
100 - // Cache operations!
101 109 update_option(self::INSTALLATION_STATE, $operations);
102 110 }
103 - return $operations;
111 + return $operations[CJTPlugin::DB_VERSION];
104 112 }
105 -
113 +
106 114 /**
107 115 * put your comment there...
108 - *
116 + *
109 117 */
110 118 public function getUpgrader() {
111 119 // Upgrader file.
112 120 $upgrader['file'] = "includes:installer:upgrade:{$this->getInstalledDbVersion()}:upgrade.class.php";
@@ -113,30 +121,33 @@
113 121 // Upgrader class name.
114 122 $upgrader['class'] = "CJTV{$this->getInternalVersionName()}Upgrade";
115 123 return $upgrader;
116 124 }
117 -
125 +
118 126 /**
119 127 * Allow executing of a single installation operation!
120 - * Both Install and Upgrade operations can be executed throught here
121 - *
122 - *
128 + * Both Install and Upgrade operations can be executed through here
129 + *
130 + *
123 131 * @return void
124 132 */
125 133 public function install() {
134 + // Initialize.
135 + $result = FALSE;
126 136 // Read input!
127 137 $rOperation = $this->input['operation'];
128 138 $type = $rOperation['type'];
129 - // Get allowed operations with thier state!
139 + // Get allowed operations with their state!
130 140 $operations = (array) get_option(self::INSTALLATION_STATE);
141 + $vOperations =& $operations[CJTPlugin::DB_VERSION];
131 142 // Invalid operation!
132 - if (!isset($operations['operations'][$type][$rOperation['name']])) {
143 + if (!isset($vOperations['operations'][$type][$rOperation['name']])) {
133 144 throw new Exception('Invalid operation');
134 145 }
135 146 else {
136 147 // Install only if not installed!
137 - $operation =& $operations['operations'][$type][$rOperation['name']];
138 - if ($operation['state'] != self::OPERATION_STATE_INSTALLED) {
148 + $operation =& $vOperations['operations'][$type][$rOperation['name']];
149 + if ((!isset($operation['state'])) || ($operation['state'] != self::OPERATION_STATE_INSTALLED)) {
139 150 // Import installer and get installer object!
140 151 switch ($type) {
141 152 case 'install':
142 153 cssJSToolbox::import('includes:installer:installer:installer.class.php');
@@ -142,9 +153,9 @@
142 153 cssJSToolbox::import('includes:installer:installer:installer.class.php');
143 154 $installer = CJTInstaller::getInstance();
144 155 break;
145 156 case 'upgrade':
146 - $upgrader = $operations['upgrader'];
157 + $upgrader = $vOperations['upgrader'];
147 158 cssJSToolbox::import($upgrader['file']);
148 159 $installer = new $upgrader['class']();
149 160 break;
150 161 }
@@ -153,27 +164,49 @@
153 164 $operation['state'] = self::OPERATION_STATE_INSTALLED;
154 165 // Update operations cache to reflect the new state!
155 166 update_option(self::INSTALLATION_STATE, $operations);
156 167 // Say OK!
157 - $this->response = array('state' => self::OPERATION_STATE_INSTALLED);
168 + $result = array('state' => self::OPERATION_STATE_INSTALLED);
158 169 }
159 170 }
160 171 }
172 + return $result;
161 173 }
162 -
174 +
163 175 /**
164 176 * put your comment there...
165 - *
177 + *
166 178 */
179 + public function isCommonRelease() {
180 + // Check weather the current installed version is in the same
181 + // release with the running version.
182 + // Get instaleled version components.
183 + $ivComponent = explode('.', str_replace('-', '.', $this->getInstalledDbVersion()));
184 + $nvComponent = explode('.', str_replace('-', '.', CJTPlugin::DB_VERSION));
185 + // Use PE-Edition sign if not sign used!
186 + if (!isset($ivComponent[2])) {
187 + $ivComponent[2] = 'PE';
188 + }
189 + if (!isset($nvComponent[2])) {
190 + $nvComponent[2] = 'PE';
191 + }
192 + // TRUE if same, FALSE otherwise.
193 + return (($ivComponent[0] == $nvComponent[0]) && ($ivComponent[2] == $nvComponent[2]));
194 + }
195 +
196 + /**
197 + * put your comment there...
198 + *
199 + */
167 200 public function isUpgrade() {
168 201 // If the version is not the same and not equal to current version then its upgrading!
169 202 $isUpgrade = (($this->installedDbVersion != CJTPlugin::DB_VERSION) && ($this->installedDbVersion != ''));
170 203 return $isUpgrade;
171 204 }
172 -
205 +
173 206 /**
174 207 * put your comment there...
175 - *
208 + *
176 209 * @param mixed $input
177 210 */
178 211 public function setInput(& $input) {
179 212 $this->input = $input;
@@ -178,6 +211,6 @@
178 211 public function setInput(& $input) {
179 212 $this->input = $input;
180 213 return $this; // Chaining!
181 214 }
182 -
215 +
183 216 } // End class.