PluginProbe
ManageWP Worker / 4.9.37
ManageWP Worker v4.9.37
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Updater / UpdateManager.php

UpdateManager.php in ManageWP Worker 4.9.37, at src/MWP/Updater/UpdateManager.php

169 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <[email protected]>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 class MWP_Updater_UpdateManager
12 {
13
14 private $context;
15
16 private $coreInfo;
17
18 private $pluginInfo;
19
20 private $themeInfo;
21
22 public function __construct(MWP_WordPress_Context $context)
23 {
24 $this->context = $context;
25 $this->reload();
26 }
27
28 /**
29 * @return int|null UNIX timestamp of last update check.
30 */
31 public function getLastChecked()
32 {
33 if (empty($this->pluginInfo->last_checked)) {
34 return null;
35 }
36
37 return $this->pluginInfo->last_checked;
38 }
39
40 /**
41 * @param string $pluginBasename Ie. 'worker/init.php'
42 *
43 * @return MWP_Updater_PluginUpdate|null
44 */
45 public function getPluginUpdate($pluginBasename)
46 {
47 if (empty($this->pluginInfo->response[$pluginBasename])) {
48 return null;
49 }
50
51 $info = $this->pluginInfo->response[$pluginBasename];
52
53 $update = new MWP_Updater_PluginUpdate();
54 $update->id = $info->id;
55 $update->version = $info->new_version;
56 $update->basename = $pluginBasename;
57 $update->url = $info->url;
58 $update->package = $info->package;
59 $update->slug = $info->plugin;
60
61 return $update;
62 }
63
64 /**
65 * @param string $themeSlug Ie. 'twentyeleven'.
66 *
67 * @return MWP_Updater_ThemeUpdate|null
68 */
69 public function getThemeUpdate($themeSlug)
70 {
71 if (empty($this->themeInfo->response[$themeSlug])) {
72 return null;
73 }
74
75 $info = $this->themeInfo->response[$themeSlug];
76
77 $update = new MWP_Updater_ThemeUpdate();
78 $update->slug = $info['theme']; // === $themeSlug
79 $update->version = $info['new_version'];
80 $update->url = $info['url'];
81 $update->package = $info['package'];
82
83 return $update;
84 }
85
86 /**
87 * @return MWP_Updater_PluginUpdate[]
88 */
89 public function getPluginUpdates()
90 {
91 if (empty($this->pluginInfo->response)) {
92 return array();
93 }
94
95 $updates = array();
96 foreach (array_keys($this->pluginInfo->response) as $basename) {
97 $updates[] = $this->getPluginUpdate($basename);
98 }
99
100 return $updates;
101 }
102
103 /**
104 * @return MWP_Updater_ThemeUpdate[]
105 */
106 public function getThemeUpdates()
107 {
108 if (empty($this->themeInfo->response)) {
109 return array();
110 }
111
112 $updates = array();
113 foreach (array_keys($this->themeInfo->response) as $slug) {
114 $updates[] = $this->getThemeUpdate($slug);
115 }
116
117 return $updates;
118 }
119
120 /**
121 * @return MWP_Updater_CoreUpdate[]
122 *
123 * @see core_upgrade_preamble
124 */
125 public function getCoreUpdates()
126 {
127 if (empty($this->coreInfo->updates)) {
128 return array();
129 }
130
131 $firstUpdate = $this->coreInfo->updates[0];
132
133 if (!isset($firstUpdate->response) || 'latest' === $firstUpdate->response) {
134 return array();
135 }
136
137 $locale = $this->context->getLocale();
138 $latestUpdate = null;
139
140 foreach ($this->coreInfo->updates as $update) {
141 if ($update->response === 'upgrade' && $update->locale === $locale) {
142 $latestUpdate = $update;
143 }
144 }
145
146 $updates = array();
147
148 if ($latestUpdate !== null) {
149 $showUpdate = new MWP_Updater_CoreUpdate();
150 $showUpdate->locale = $latestUpdate->locale;
151 $showUpdate->type = $latestUpdate->response;
152 $showUpdate->version = $latestUpdate->version;
153 $showUpdate->phpVersion = $latestUpdate->php_version;
154 $showUpdate->mysqlVersion = $latestUpdate->mysql_version;
155
156 $updates[] = $showUpdate;
157 }
158
159 return $updates;
160 }
161
162 private function reload()
163 {
164 $this->coreInfo = $this->context->transientGet('update_core');
165 $this->pluginInfo = $this->context->transientGet('update_plugins');
166 $this->themeInfo = $this->context->transientGet('update_themes');
167 }
168 }
169