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