PluginProbe
ManageWP Worker / 3.9.0
ManageWP Worker v3.9.0
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 / installer.class.php

installer.class.php in ManageWP Worker 3.9.0, at installer.class.php

369 lines 11.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*************************************************************
3 *
4 * installer.class.php
5 *
6 * Upgrade WordPress
7 *
8 *
9 * Copyright (c) 2011 Prelovac Media
10 * www.prelovac.com
11 **************************************************************/
12
13 class MMB_Installer extends MMB_Core
14 {
15 function __construct()
16 {
17 @set_time_limit(300);
18 parent::__construct();
19 include_once(ABSPATH . 'wp-admin/includes/file.php');
20 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
21 include_once(ABSPATH . 'wp-admin/includes/theme.php');
22 include_once(ABSPATH . 'wp-admin/includes/misc.php');
23 include_once(ABSPATH . 'wp-admin/includes/template.php');
24 @include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
25
26 global $wp_filesystem;
27 if (!$wp_filesystem)
28 WP_Filesystem();
29
30 }
31
32 function mmb_maintenance_mode($enable = false, $maintenance_message = '')
33 {
34 global $wp_filesystem;
35
36 $maintenance_message .= '<?php $upgrading = ' . time() . '; ?>';
37
38 $file = $wp_filesystem->abspath() . '.maintenance';
39 if ($enable) {
40 $wp_filesystem->delete($file);
41 $wp_filesystem->put_contents($file, $maintenance_message, FS_CHMOD_FILE);
42 } else {
43 $wp_filesystem->delete($file);
44 }
45 }
46
47 function install_remote_file($params)
48 {
49 global $wp_filesystem;
50 extract($params);
51
52 if (!isset($package) || empty($package))
53 return array(
54 'error' => '<p>No files received. Internal error.</p>'
55 );
56
57 if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance'))
58 return array(
59 'error' => '<p>Site under maintanace.</p>'
60 );
61 ;
62
63 $upgrader = new WP_Upgrader();
64 $destination = $type == 'themes' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR;
65
66
67 foreach ($package as $package_url) {
68 $key = basename($package_url);
69 $install_info[$key] = @$upgrader->run(array(
70 'package' => $package_url,
71 'destination' => $destination,
72 'clear_destination' => false, //Do not overwrite files.
73 'clear_working' => true,
74 'hook_extra' => array()
75 ));
76 }
77
78 if ($activate) {
79 if($type == 'plugins'){
80 include_once(ABSPATH.'wp-admin/includes/plugin.php');
81 $all_plugins = get_plugins();
82 foreach ($all_plugins as $plugin_slug => $plugin) {
83 $plugin_dir = preg_split('/\//', $plugin_slug);
84 foreach ($install_info as $key => $install) {
85 if (!$install || is_wp_error($install))
86 continue;
87
88 if ($install['destination_name'] == $plugin_dir[0]) {
89 $install_info[$key]['activated'] = activate_plugin($plugin_slug, '', false);
90 }
91 }
92 }
93 }else if(count($install_info) == 1){
94 include_once(ABSPATH.'wp-includes/theme.php');
95 $all_themes = get_themes();
96 foreach ($all_themes as $theme_name => $theme_data) {
97
98 foreach ($install_info as $key => $install) {
99 if (!$install || is_wp_error($install))
100 continue;
101
102 if ($theme_data['Template'] == $install['destination_name']) {
103 $install_info[$key]['activated'] = switch_theme($theme_data['Template'], $theme_data['Stylesheet']);
104 }
105 }
106 }
107 }
108 }
109 ob_clean();
110 $this->mmb_maintenance_mode(false);
111 return $install_info;
112 }
113
114 function do_upgrade($params = null){
115
116 if($params == null || empty($params))
117 return array('failed' => 'No upgrades passed.');
118
119 if (!$this->is_server_writable()) {
120 return array(
121 'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide#ftp">add FTP details</a></a>'
122 );
123 }
124 $params = isset($params['upgrades_all']) ? $params['upgrades_all'] : $params;
125
126 $core_upgrade = isset($params['wp_upgrade']) ? $params['wp_upgrade'] : array();
127 $upgrade_plugins = isset($params['upgrade_plugins']) ? $params['upgrade_plugins'] : array();
128 $upgrade_themes = isset($params['upgrade_themes']) ? $params['upgrade_themes'] : array();
129
130
131 $upgrades = array();
132 if(!empty($core_upgrade)){
133 $upgrades['core'] = $this->upgrade_core($core_upgrade);
134 }
135
136 if(!empty($upgrade_plugins)){
137 $plugin_files = array();
138 foreach($upgrade_plugins as $plugin){
139 $plugin_files[] = $plugin->file;
140 }
141
142 $upgrades['plugins'] = $this->upgrade_plugins($plugin_files);
143
144 }
145
146 if(!empty($upgrade_themes)){
147 $theme_temps = array();
148 foreach($upgrade_themes as $theme){
149 $theme_temps[] = $theme['theme_tmp'];
150 }
151
152 $upgrades['themes'] = $this->upgrade_themes($theme_temps);
153 $this->mmb_maintenance_mode(false);
154 }
155 ob_clean();
156 $this->mmb_maintenance_mode(false);
157 return $upgrades;
158 }
159
160 /**
161 * Upgrades WordPress locally
162 *
163 */
164 function upgrade_core($current)
165 {
166 ob_start();
167 global $mmb_wp_version, $wp_filesystem;
168
169 if(!class_exists('WP_Upgrader')){
170 include_once(ABSPATH.'wp-admin/includes/update.php');
171 if(function_exists('wp_update_core')){
172 $update = wp_update_core($current);
173 if(is_wp_error($update)){
174 return array(
175 'error' => $this->mmb_get_error($update)
176 );
177 }
178 else
179 return array(
180 'upgraded' => ' Upgraded successfully.'
181 );
182 }
183 }
184
185 $upgrader = new WP_Upgrader();
186
187 // Is an update available?
188 if (!isset($current->response) || $current->response == 'latest')
189 return array(
190 'upgraded' => ' Upgraded successfully.'
191 );
192
193 $res = $upgrader->fs_connect(array(
194 ABSPATH,
195 WP_CONTENT_DIR
196 ));
197 if (is_wp_error($res))
198 return array(
199 'error' => $this->mmb_get_error($res)
200 );
201
202 $wp_dir = trailingslashit($wp_filesystem->abspath());
203
204 $download = $upgrader->download_package($current->package);
205 if (is_wp_error($download))
206 return array(
207 'error' => $this->mmb_get_error($download)
208 );
209
210 $working_dir = $upgrader->unpack_package($download);
211 if (is_wp_error($working_dir))
212 return array(
213 'error' => $this->mmb_get_error($working_dir)
214 );
215
216 if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
217 $wp_filesystem->delete($working_dir, true);
218 return array(
219 'error' => 'Unable to move update files.'
220 );
221 }
222
223 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
224
225 require(ABSPATH . 'wp-admin/includes/update-core.php');
226
227
228 $update_core = update_core($working_dir, $wp_dir);
229 ob_end_clean();
230
231 if (is_wp_error($update_core))
232 return array(
233 'error' => $this->mmb_get_error($update_core)
234 );
235 ob_end_flush();
236 return array(
237 'upgraded' => 'Upgraded successfully.'
238 );
239 }
240
241
242 function upgrade_plugins($plugins = false){
243 if(!$plugins || empty($plugins))
244 return array(
245 'error' => 'No plugin files for upgrade.'
246 );
247 $return = array();
248 if (class_exists('Plugin_Upgrader') && class_exists('Bulk_Plugin_Upgrader_Skin')) {
249
250 $current_plugins = $this->mmb_get_transient('update_plugins');
251
252 $upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
253 $result = $upgrader->bulk_upgrade($plugins);
254
255 if (!empty($result)) {
256 foreach ($result as $plugin_slug => $plugin_info) {
257 if (!$plugin_info || is_wp_error($plugin_info)) {
258 $return[$plugin_slug] = $this->mmb_get_error($plugin_info);
259 } else {
260 unset($current_plugins->response[$plugin_slug]);
261 $return[$plugin_slug] = 1;
262 }
263 }
264 $this->mmb_set_transient('update_plugins', $current_plugins);
265 ob_end_clean();
266 return array(
267 'upgraded' => $return
268 );
269 }
270 else
271 return array(
272 'error' => 'Upgrade failed.'
273 );
274 } else {
275 ob_end_clean();
276 return array(
277 'error' => 'WordPress update required first.'
278 );
279 }
280 }
281
282 function upgrade_themes($themes = false){
283 if(!$themes || empty($themes))
284 return array(
285 'error' => 'No theme files for upgrade.'
286 );
287
288 if (class_exists('Theme_Upgrader') && class_exists('Bulk_Theme_Upgrader_Skin')) {
289
290 $current_themes = $this->mmb_get_transient('update_themes');
291
292 $upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('title', 'nonce', 'url', 'theme')));
293 $result = $upgrader->bulk_upgrade($themes);
294
295 $return = array();
296 if (!empty($result)) {
297 foreach ($result as $theme_tmp => $theme_info) {
298 if (is_wp_error($theme_info) || !$theme_info) {
299 $return[$theme_tmp] = $this->mmb_get_error($theme_info);
300 } else {
301 unset($current_themes->response[$theme_tmp]);
302 $return[$theme_tmp] = 1;
303 }
304 }
305 $this->mmb_set_transient('update_themes', $current_themes);
306 return array(
307 'upgraded' => $return
308 );
309 } else
310 return array(
311 'error' => 'Upgrade failed.'
312 );
313 } else {
314 ob_end_clean();
315 return array(
316 'error' => 'WordPress update required first'
317 );
318 }
319 }
320
321 function get_upgradable_plugins()
322 {
323 $current = $this->mmb_get_transient('update_plugins');
324 $upgradable_plugins = array();
325 if (!empty($current->response)) {
326 foreach ($current->response as $plugin_path => $plugin_data) {
327 if($plugin_path == 'worker/init.php')
328 continue;
329
330 if (!function_exists('get_plugin_data'))
331 include_once ABSPATH . 'wp-admin/includes/plugin.php';
332
333 $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
334
335 $current->response[$plugin_path]->name = $data['Name'];
336 $current->response[$plugin_path]->old_version = $data['Version'];
337 $current->response[$plugin_path]->file = $plugin_path;
338 $upgradable_plugins[] = $current->response[$plugin_path];
339 }
340 return $upgradable_plugins;
341 } else
342 return array();
343
344 }
345
346 function get_upgradable_themes()
347 {
348 $all_themes = get_themes();
349 $upgrade_themes = array();
350
351 $current = $this->mmb_get_transient('update_themes');
352 foreach ((array) $all_themes as $theme_template => $theme_data) {
353 if (!empty($current->response)) {
354 foreach ($current->response as $current_themes => $theme) {
355 if ($theme_data['Template'] == $current_themes) {
356 $current->response[$current_themes]['name'] = $theme_data['Name'];
357 $current->response[$current_themes]['old_version'] = $theme_data['Version'];
358 $current->response[$current_themes]['theme_tmp'] = $theme_data['Template'];
359 $upgrade_themes[] = $current->response[$current_themes];
360 continue;
361 }
362 }
363 }
364 }
365
366 return $upgrade_themes;
367 }
368 }
369 ?>