PluginProbe
CSS & JavaScript Toolbox / 6.0.7
CSS & JavaScript Toolbox v6.0.7
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.7, at models/installer.php

190 lines 5.2 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 // Check if cached: Use only installer cache for 'current' CJT version.
89 if (!isset($operations[CJTPlugin::DB_VERSION])) {
90 // Import installer reflection!
91 cssJSToolbox::import('framework:installer:reflection.class.php');
92 // Get Installer operations.
93 cssJSToolbox::import('includes:installer:installer:installer.class.php');
94 $operations[CJTPlugin::DB_VERSION]['operations']['install'] = CJTInstallerReflection::getInstance('CJTInstaller', 'CJTInstaller')->getOperations();
95 if ($this->isUpgrade()) {
96 // Get upgrade operations , Also cache upgrader info for later use!
97 $operations[CJTPlugin::DB_VERSION]['upgrader'] = $upgrader = $this->getUpgrader();
98 // Check if upgrader exists!
99 if (!file_exists(cssJSToolbox::resolvePath($upgrader['file']))) {
100 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!!");
101 }
102 // Import upgrader + reflect its operations!
103 cssJSToolbox::import($upgrader['file']);
104 $operations[CJTPlugin::DB_VERSION]['operations']['upgrade'] = CJTInstallerReflection::getInstance($upgrader['class'], 'CJTUpgradeNonTabledVersions')->getOperations();
105 }
106 update_option(self::INSTALLATION_STATE, $operations);
107 }
108 return $operations[CJTPlugin::DB_VERSION];
109 }
110
111 /**
112 * put your comment there...
113 *
114 */
115 public function getUpgrader() {
116 // Upgrader file.
117 $upgrader['file'] = "includes:installer:upgrade:{$this->getInstalledDbVersion()}:upgrade.class.php";
118 // Upgrader class name.
119 $upgrader['class'] = "CJTV{$this->getInternalVersionName()}Upgrade";
120 return $upgrader;
121 }
122
123 /**
124 * Allow executing of a single installation operation!
125 * Both Install and Upgrade operations can be executed throught here
126 *
127 *
128 * @return void
129 */
130 public function install() {
131 // Read input!
132 $rOperation = $this->input['operation'];
133 $type = $rOperation['type'];
134 // Get allowed operations with their state!
135 $operations = (array) get_option(self::INSTALLATION_STATE);
136 $vOperations =& $operations[CJTPlugin::DB_VERSION];
137 // Invalid operation!
138 if (!isset($vOperations['operations'][$type][$rOperation['name']])) {
139 throw new Exception('Invalid operation');
140 }
141 else {
142 // Install only if not installed!
143 $operation =& $vOperations['operations'][$type][$rOperation['name']];
144 if ((!isset($operation['state'])) || ($operation['state'] != self::OPERATION_STATE_INSTALLED)) {
145 // Import installer and get installer object!
146 switch ($type) {
147 case 'install':
148 cssJSToolbox::import('includes:installer:installer:installer.class.php');
149 $installer = CJTInstaller::getInstance();
150 break;
151 case 'upgrade':
152 $upgrader = $vOperations['upgrader'];
153 cssJSToolbox::import($upgrader['file']);
154 $installer = new $upgrader['class']();
155 break;
156 }
157 // Execute the requested operation, save state only when succesed!
158 if ($installer->{$rOperation['name']}()) {
159 $operation['state'] = self::OPERATION_STATE_INSTALLED;
160 // Update operations cache to reflect the new state!
161 update_option(self::INSTALLATION_STATE, $operations);
162 // Say OK!
163 $this->response = array('state' => self::OPERATION_STATE_INSTALLED);
164 }
165 }
166 }
167 }
168
169 /**
170 * put your comment there...
171 *
172 */
173 public function isUpgrade() {
174 // If the version is not the same and not equal to current version then its upgrading!
175 $isUpgrade = (($this->installedDbVersion != CJTPlugin::DB_VERSION) && ($this->installedDbVersion != ''));
176 return $isUpgrade;
177 }
178
179 /**
180 * put your comment there...
181 *
182 * @param mixed $input
183 */
184 public function setInput(& $input) {
185 $this->input = $input;
186 return $this; // Chaining!
187 }
188
189 } // End class.
190