PluginProbe
CSS & JavaScript Toolbox / 6.0.9
CSS & JavaScript Toolbox v6.0.9
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
css-javascript-toolbox / models / installer.php

installer.php in CSS & JavaScript Toolbox 6.0.9, at models/installer.php

193 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 // Disallow direct access.
7 defined('ABSPATH') or die("Access denied");
8
9 /**
10 *
11 */
12 class CJTInstallerModel {
13
14 /**
15 *
16 */
17 const OPERATION_STATE_INSTALLED = 'installed';
18
19 /**
20 *
21 */
22 const INSTALLATION_STATE = 'state.CJTInstallerModel.operations';
23
24 /**
25 *
26 */
27 const NOTICED_DISMISSED_OPTION_NAME = 'settings.CJTInstallerModel.noticeDismissed';
28
29 /**
30 * put your comment there...
31 *
32 * @var mixed
33 */
34 protected $input;
35
36 /**
37 * put your comment there...
38 *
39 * @var mixed
40 */
41 protected $installedDbVersion;
42
43 /**
44 * put your comment there...
45 *
46 */
47 public function __construct() {
48 $this->installedDbVersion = get_option(CJTPlugin::DB_VERSION_OPTION_NAME);
49 }
50
51 /**
52 * put your comment there...
53 *
54 * @param mixed $dismiss
55 */
56 public function dismissNotice($dismiss = null) {
57 // Read current value!
58 $currentValue = get_user_option(self::NOTICED_DISMISSED_OPTION_NAME);
59 if ($dismiss !== null) {
60 // Dismiss can' be reverted!
61 update_user_option(get_current_user_id(), self::NOTICED_DISMISSED_OPTION_NAME, true);
62 }
63 return $currentValue;
64 }
65
66 /**
67 * put your comment there...
68 *
69 */
70 public function getInstalledDbVersion() {
71 return $this->installedDbVersion;
72 }
73
74 /**
75 * put your comment there...
76 *
77 */
78 public function getInternalVersionName() {
79 return str_replace(array('.', '-'), '', $this->installedDbVersion);
80 }
81
82 /**
83 * Get installer operations for current CJT version!
84 *
85 * @return array Operations list metadata.
86 */
87 public function getOperations() {
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])) {
93 // Import installer reflection!
94 cssJSToolbox::import('framework:installer:reflection.class.php');
95 // Get Installer operations.
96 cssJSToolbox::import('includes:installer:installer:installer.class.php');
97 $operations[CJTPlugin::DB_VERSION]['operations']['install'] = CJTInstallerReflection::getInstance('CJTInstaller', 'CJTInstaller')->getOperations();
98 if ($this->isUpgrade()) {
99 // Get upgrade operations , Also cache upgrader info for later use!
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!
106 cssJSToolbox::import($upgrader['file']);
107 $operations[CJTPlugin::DB_VERSION]['operations']['upgrade'] = CJTInstallerReflection::getInstance($upgrader['class'], 'CJTUpgradeNonTabledVersions')->getOperations();
108 }
109 update_option(self::INSTALLATION_STATE, $operations);
110 }
111 return $operations[CJTPlugin::DB_VERSION];
112 }
113
114 /**
115 * put your comment there...
116 *
117 */
118 public function getUpgrader() {
119 // Upgrader file.
120 $upgrader['file'] = "includes:installer:upgrade:{$this->getInstalledDbVersion()}:upgrade.class.php";
121 // Upgrader class name.
122 $upgrader['class'] = "CJTV{$this->getInternalVersionName()}Upgrade";
123 return $upgrader;
124 }
125
126 /**
127 * Allow executing of a single installation operation!
128 * Both Install and Upgrade operations can be executed throught here
129 *
130 *
131 * @return void
132 */
133 public function install() {
134 // Read input!
135 $rOperation = $this->input['operation'];
136 $type = $rOperation['type'];
137 // Get allowed operations with their state!
138 $operations = (array) get_option(self::INSTALLATION_STATE);
139 $vOperations =& $operations[CJTPlugin::DB_VERSION];
140 // Invalid operation!
141 if (!isset($vOperations['operations'][$type][$rOperation['name']])) {
142 throw new Exception('Invalid operation');
143 }
144 else {
145 // Install only if not installed!
146 $operation =& $vOperations['operations'][$type][$rOperation['name']];
147 if ((!isset($operation['state'])) || ($operation['state'] != self::OPERATION_STATE_INSTALLED)) {
148 // Import installer and get installer object!
149 switch ($type) {
150 case 'install':
151 cssJSToolbox::import('includes:installer:installer:installer.class.php');
152 $installer = CJTInstaller::getInstance();
153 break;
154 case 'upgrade':
155 $upgrader = $vOperations['upgrader'];
156 cssJSToolbox::import($upgrader['file']);
157 $installer = new $upgrader['class']();
158 break;
159 }
160 // Execute the requested operation, save state only when succesed!
161 if ($installer->{$rOperation['name']}()) {
162 $operation['state'] = self::OPERATION_STATE_INSTALLED;
163 // Update operations cache to reflect the new state!
164 update_option(self::INSTALLATION_STATE, $operations);
165 // Say OK!
166 $this->response = array('state' => self::OPERATION_STATE_INSTALLED);
167 }
168 }
169 }
170 }
171
172 /**
173 * put your comment there...
174 *
175 */
176 public function isUpgrade() {
177 // If the version is not the same and not equal to current version then its upgrading!
178 $isUpgrade = (($this->installedDbVersion != CJTPlugin::DB_VERSION) && ($this->installedDbVersion != ''));
179 return $isUpgrade;
180 }
181
182 /**
183 * put your comment there...
184 *
185 * @param mixed $input
186 */
187 public function setInput(& $input) {
188 $this->input = $input;
189 return $this; // Chaining!
190 }
191
192 } // End class.
193