PluginProbe
CSS & JavaScript Toolbox / 10.1
CSS & JavaScript Toolbox v10.1
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 / framework / extensions / package / state / packages.php

packages.php in CSS & JavaScript Toolbox 10.1, at framework/extensions/package/state/packages.php

187 lines 3.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 /**
7 *
8 */
9 class CJT_Framework_Extensions_Package_State_Packages extends ArrayIterator {
10
11 /**
12 *
13 */
14 const INSTALLED = 1;
15
16 /**
17 *
18 */
19 const NOT_INSTALLED = 2;
20
21 /**
22 *
23 */
24 const UPGRADE = 3;
25
26 /**
27 * put your comment there...
28 *
29 * @var mixed
30 */
31 protected $extDeDoc;
32
33 /**
34 * put your comment there...
35 *
36 * @var SimpleXMLElement
37 */
38 protected $dbOptionName;
39
40 /**
41 * put your comment there...
42 *
43 * @var mixed
44 */
45 protected $deDocPackages;
46
47 /**
48 * put your comment there...
49 *
50 * @var mixed
51 */
52 protected $installedPackages;
53
54 /**
55 * put your comment there...
56 *
57 * @var mixed
58 */
59 protected $oldPackagesQueue;
60
61 /**
62 * put your comment there...
63 *
64 * @param SimpleXMLElement $exDeDoc
65 * @return {CJT_Framework_Extensions_Package_State_Packages|SimpleXMLElement}
66 */
67 public function __construct(SimpleXMLElement & $extDeDoc) {
68 # Initialize
69 $extensionName = (string) $extDeDoc->attributes()->class;
70 $this->dbOptionName = "{$extensionName}.state.packages";
71 $this->extDeDoc =& $extDeDoc;
72 # Reading Database packages
73 $this->installedPackages = get_option($this->dbOptionName, array());
74 # Caching DeDoc packages
75 foreach ($extDeDoc->packages->package as $package) {
76 # Package data
77 $pckData = $package->attributes();
78 # Cache package data
79 $this->deDocPackages[(string) $pckData->name] = array(
80 'version' => ((string) $pckData->version),
81 'file' => ((string) $pckData->file)
82 );
83 }
84 # Support dedoc iteration side
85 parent::__construct($this->deDocPackages);
86 }
87
88 /**
89 * put your comment there...
90 *
91 */
92 public function clearInstallInfo() {
93 return delete_option($this->dbOptionName);
94 }
95
96 /**
97 * put your comment there...
98 *
99 */
100 public function & getDeletedPackages() {
101 return $this->oldPackagesQueue;
102 }
103
104 /**
105 * put your comment there...
106 *
107 */
108 public function getInstalledPackages() {
109 return $this->installedPackages;
110 }
111
112 /**
113 * put your comment there...
114 *
115 */
116 public function getState() {
117 # INitialize
118 $state = null;
119 $currentPckKey = $this->key();
120 $newPck = $this->current();
121 $oldPck = isset($this->oldPackagesQueue[$currentPckKey]) ? $this->oldPackagesQueue[$currentPckKey] : array('version' => null);
122 $package = $this->current();
123 $oldVersion = $oldPck['version'];
124 $newVersion = $package['version'];
125 # Compare packages state
126 if (!$oldVersion) {
127 # Not installed
128 $state = self::NOT_INSTALLED;
129 }
130 else if ($oldVersion != $newVersion) {
131 # Upgrading package
132 $state = self::UPGRADE;
133 }
134 else {
135 # Already installed, same version, no changes
136 $state = self::INSTALLED;
137 }
138 }
139
140 /**
141 * put your comment there...
142 *
143 * @param mixed $id
144 */
145 public function packageInstalled($id) {
146 # Get current package
147 $package =& $this->deDocPackages[$this->key()];
148 # Hold package id for installed package
149 $package['id'] = $id;
150 # Chain
151 return $this;
152 }
153
154 /**
155 * put your comment there...
156 *
157 */
158 public function removeOld() {
159 # INitialize
160 $currentKey = $this->key();
161 # Remove from installed packages working queue
162 unset($this->oldPackagesQueue[$currentKey]);
163 # Chain
164 return $this;
165 }
166
167 /**
168 * put your comment there...
169 *
170 */
171 public function rewind() {
172 # Reset
173 $this->oldPackagesQueue = $this->installedPackages;
174 # ArrayIterator
175 return parent::rewind();
176 }
177
178 /**
179 * put your comment there...
180 *
181 */
182 public function upgrade() {
183 # Save new deDoc packages into database, drop previous state
184 return update_option($this->dbOptionName, $this->deDocPackages);
185 }
186
187 } # End class