2014-05-02 04:03:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl\Update;
|
|
|
|
|
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
|
|
|
use ManiaControl\Callbacks\TimerListener;
|
|
|
|
use ManiaControl\Commands\CommandListener;
|
2014-05-02 17:50:30 +02:00
|
|
|
use ManiaControl\Files\BackupUtil;
|
2014-05-02 04:03:02 +02:00
|
|
|
use ManiaControl\Files\FileUtil;
|
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Players\Player;
|
2014-07-01 21:23:50 +02:00
|
|
|
use ManiaControl\Plugins\InstallMenu;
|
2014-07-24 23:15:25 +02:00
|
|
|
use ManiaControl\Plugins\Plugin;
|
2014-05-02 04:03:02 +02:00
|
|
|
use ManiaControl\Plugins\PluginManager;
|
2014-05-02 17:50:30 +02:00
|
|
|
use ManiaControl\Plugins\PluginMenu;
|
2014-06-27 01:18:55 +02:00
|
|
|
use ManiaControl\Utils\WebReader;
|
2014-05-02 04:03:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Manager checking for ManiaControl Plugin Updates
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-05-02 04:03:02 +02:00
|
|
|
*/
|
|
|
|
class PluginUpdateManager implements CallbackListener, CommandListener, TimerListener {
|
|
|
|
/*
|
2014-07-25 16:28:47 +02:00
|
|
|
* Private properties
|
2014-05-02 04:03:02 +02:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2014-05-02 04:03:02 +02:00
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Create a new plugin update manager instance
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-05-02 04:03:02 +02:00
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 04:03:02 +02:00
|
|
|
// Register for callbacks
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 04:03:02 +02:00
|
|
|
// Register for chat commands
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('checkpluginsupdate', $this, 'handle_CheckPluginsUpdate', true, 'Check for Plugin Updates.');
|
|
|
|
$this->maniaControl->commandManager->registerCommandListener('pluginsupdate', $this, 'handle_PluginsUpdate', true, 'Perform the Plugin Updates.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //checkpluginsupdate command
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
2014-05-02 04:03:02 +02:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function handle_CheckPluginsUpdate(array $chatCallback, Player $player) {
|
|
|
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATECHECK)) {
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
$this->checkPluginsUpdate($player);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if there are Outdated Plugins installed
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-05-02 04:03:02 +02:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function checkPluginsUpdate(Player $player = null) {
|
|
|
|
$message = 'Checking Plugins for newer Versions...';
|
|
|
|
if ($player) {
|
|
|
|
$this->maniaControl->chat->sendInformation($message, $player);
|
|
|
|
}
|
|
|
|
$this->maniaControl->log($message);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->pluginManager->fetchPluginList(function ($data, $error) use (&$player) {
|
2014-05-02 04:03:02 +02:00
|
|
|
if (!$data || $error) {
|
|
|
|
$message = 'Error while checking Plugins for newer Versions!';
|
|
|
|
if ($player) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendError($message, $player);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->log($message);
|
2014-05-02 04:03:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-06-17 23:27:28 +02:00
|
|
|
$pluginsData = $this->parsePluginsData($data);
|
|
|
|
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
|
2014-05-02 04:03:02 +02:00
|
|
|
$pluginUpdates = array();
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 04:03:02 +02:00
|
|
|
foreach ($pluginClasses as $pluginClass) {
|
2014-05-03 23:03:07 +02:00
|
|
|
/** @var Plugin $pluginClass */
|
2014-05-02 04:03:02 +02:00
|
|
|
$pluginId = $pluginClass::getId();
|
|
|
|
if (!isset($pluginsData[$pluginId])) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-05-02 15:35:52 +02:00
|
|
|
/** @var PluginUpdateData $pluginData */
|
2014-05-02 17:50:30 +02:00
|
|
|
$pluginData = $pluginsData[$pluginId];
|
2014-05-02 04:03:02 +02:00
|
|
|
$pluginVersion = $pluginClass::getVersion();
|
|
|
|
if ($pluginData->isNewerThan($pluginVersion)) {
|
|
|
|
$pluginUpdates[$pluginId] = $pluginData;
|
2014-05-02 17:50:30 +02:00
|
|
|
$message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})";
|
2014-05-02 04:03:02 +02:00
|
|
|
if ($player) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendSuccess($message, $player);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->log($message);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 04:03:02 +02:00
|
|
|
if (empty($pluginUpdates)) {
|
|
|
|
$message = 'Plugins Update Check completed: All Plugins are up-to-date!';
|
|
|
|
if ($player) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendSuccess($message, $player);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->log($message);
|
2014-05-02 17:50:30 +02:00
|
|
|
} else {
|
2014-05-02 04:03:02 +02:00
|
|
|
$updatesCount = count($pluginUpdates);
|
2014-05-02 17:50:30 +02:00
|
|
|
$message = "Plugins Update Check completed: There are {$updatesCount} Updates available!";
|
2014-05-02 04:03:02 +02:00
|
|
|
if ($player) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendSuccess($message, $player);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->log($message);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
/**
|
|
|
|
* Get an Array of Plugin Update Data from the given Web Service Result
|
|
|
|
*
|
|
|
|
* @param mixed $webServiceResult
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function parsePluginsData($webServiceResult) {
|
|
|
|
if (!$webServiceResult || !is_array($webServiceResult)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$pluginsData = array();
|
|
|
|
foreach ($webServiceResult as $pluginResult) {
|
|
|
|
$pluginData = new PluginUpdateData($pluginResult);
|
|
|
|
$pluginsData[$pluginData->pluginId] = $pluginData;
|
|
|
|
}
|
|
|
|
return $pluginsData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle //pluginsupdate command
|
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function handle_PluginsUpdate(array $chatCallback, Player $player) {
|
|
|
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATE)) {
|
|
|
|
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->performPluginsUpdate($player);
|
|
|
|
}
|
|
|
|
|
2014-05-02 04:03:02 +02:00
|
|
|
/**
|
|
|
|
* Perform an Update of all outdated Plugins
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-05-02 04:03:02 +02:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function performPluginsUpdate(Player $player = null) {
|
|
|
|
$pluginsUpdates = $this->getPluginsUpdates();
|
|
|
|
if (empty($pluginsUpdates)) {
|
|
|
|
$message = 'There are no Plugin Updates available!';
|
|
|
|
if ($player) {
|
|
|
|
$this->maniaControl->chat->sendInformation($message, $player);
|
|
|
|
}
|
|
|
|
$this->maniaControl->log($message);
|
|
|
|
return;
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 05:04:55 +02:00
|
|
|
$message = "Starting Plugins Updating...";
|
2014-05-02 04:03:02 +02:00
|
|
|
if ($player) {
|
|
|
|
$this->maniaControl->chat->sendInformation($message, $player);
|
|
|
|
}
|
|
|
|
$this->maniaControl->log($message);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-13 16:03:26 +02:00
|
|
|
$performBackup = $this->maniaControl->settingManager->getSettingValue($this->maniaControl->updateManager, UpdateManager::SETTING_PERFORM_BACKUPS);
|
2014-05-02 04:03:02 +02:00
|
|
|
if ($performBackup && !BackupUtil::performPluginsBackup()) {
|
|
|
|
$message = 'Creating Backup before Plugins Update failed!';
|
|
|
|
if ($player) {
|
|
|
|
$this->maniaControl->chat->sendError($message, $player);
|
|
|
|
}
|
|
|
|
$this->maniaControl->log($message);
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 04:03:02 +02:00
|
|
|
foreach ($pluginsUpdates as $pluginUpdateData) {
|
2014-05-02 05:04:55 +02:00
|
|
|
$this->installPlugin($pluginUpdateData, $player, true);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for Plugin Updates
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-05-02 04:03:02 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getPluginsUpdates() {
|
2014-05-02 17:50:30 +02:00
|
|
|
$url = ManiaControl::URL_WEBSERVICE . 'plugins';
|
2014-06-27 01:18:55 +02:00
|
|
|
$response = WebReader::loadUrl($url);
|
|
|
|
$dataJson = $response->getContent();
|
2014-05-02 04:03:02 +02:00
|
|
|
$pluginData = json_decode($dataJson);
|
|
|
|
if (!$pluginData || empty($pluginData)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 04:03:02 +02:00
|
|
|
$pluginsUpdates = $this->parsePluginsData($pluginData);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
|
|
|
$updates = array();
|
2014-05-02 04:03:02 +02:00
|
|
|
$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
|
|
|
|
foreach ($pluginClasses as $pluginClass) {
|
2014-05-30 03:17:39 +02:00
|
|
|
/** @var Plugin $pluginClass */
|
2014-05-02 04:03:02 +02:00
|
|
|
$pluginId = $pluginClass::getId();
|
|
|
|
if (isset($pluginsUpdates[$pluginId])) {
|
2014-05-02 15:35:52 +02:00
|
|
|
/** @var PluginUpdateData $pluginUpdateData */
|
2014-05-02 04:03:02 +02:00
|
|
|
$pluginUpdateData = $pluginsUpdates[$pluginId];
|
2014-05-02 17:50:30 +02:00
|
|
|
$pluginVersion = $pluginClass::getVersion();
|
2014-05-02 04:03:02 +02:00
|
|
|
if ($pluginUpdateData->isNewerThan($pluginVersion)) {
|
|
|
|
$updates[$pluginId] = $pluginUpdateData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 04:03:02 +02:00
|
|
|
if (empty($updates)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $updates;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the given Plugin Update Data
|
2014-05-02 17:50:30 +02:00
|
|
|
*
|
2014-05-02 04:03:02 +02:00
|
|
|
* @param PluginUpdateData $pluginUpdateData
|
2014-05-02 17:50:30 +02:00
|
|
|
* @param Player $player
|
|
|
|
* @param bool $update
|
2014-05-02 04:03:02 +02:00
|
|
|
*/
|
|
|
|
private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) {
|
2014-06-27 01:18:55 +02:00
|
|
|
$this->maniaControl->fileReader->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (
|
|
|
|
&$pluginUpdateData, &$player, &$update
|
|
|
|
) {
|
2014-05-02 18:21:38 +02:00
|
|
|
if (!$updateFileContent || $error) {
|
|
|
|
$message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!";
|
|
|
|
if ($player) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendInformation($message, $player);
|
2014-05-02 18:21:38 +02:00
|
|
|
}
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->log($message);
|
2014-05-02 18:21:38 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-17 23:27:28 +02:00
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
$actionNoun = ($update ? 'Update' : 'Install');
|
|
|
|
$actionVerb = ($update ? 'Updating' : 'Installing');
|
2014-05-02 04:03:02 +02:00
|
|
|
$actionVerbDone = ($update ? 'updated' : 'installed');
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 04:03:02 +02:00
|
|
|
$message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'...";
|
|
|
|
if ($player) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendInformation($message, $player);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->log($message);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
|
|
|
$tempDir = FileUtil::getTempFolder();
|
2014-05-02 04:03:02 +02:00
|
|
|
$updateFileName = $tempDir . $pluginUpdateData->zipfile;
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 04:03:02 +02:00
|
|
|
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
|
|
|
if (!$bytes || $bytes <= 0) {
|
|
|
|
$message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!";
|
|
|
|
if ($player) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendError($message, $player);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
|
|
|
trigger_error($message);
|
|
|
|
return;
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
|
|
|
$zip = new \ZipArchive();
|
2014-05-02 04:03:02 +02:00
|
|
|
$result = $zip->open($updateFileName);
|
|
|
|
if ($result !== true) {
|
|
|
|
$message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})";
|
|
|
|
if ($player) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendError($message, $player);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
|
|
|
trigger_error($message);
|
|
|
|
return;
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-03 21:37:28 +02:00
|
|
|
$zip->extractTo(ManiaControlDir . 'plugins' . DIRECTORY_SEPARATOR);
|
2014-05-02 04:03:02 +02:00
|
|
|
$zip->close();
|
|
|
|
unlink($updateFileName);
|
2014-06-20 18:51:25 +02:00
|
|
|
FileUtil::deleteTempFolder();
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 04:58:41 +02:00
|
|
|
$messageExtra = '';
|
|
|
|
if ($update) {
|
|
|
|
$messageExtra = ' (Restart ManiaControl to load the new Version!)';
|
|
|
|
}
|
|
|
|
$message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}";
|
2014-05-02 04:03:02 +02:00
|
|
|
if ($player) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendSuccess($message, $player);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->log($message);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-05-02 04:03:02 +02:00
|
|
|
if (!$update) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$newPluginClasses = $this->maniaControl->pluginManager->loadPlugins();
|
2014-05-02 04:03:02 +02:00
|
|
|
if (empty($newPluginClasses)) {
|
|
|
|
$message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!";
|
|
|
|
if ($player) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendError($message, $player);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->log($message);
|
2014-05-02 17:50:30 +02:00
|
|
|
} else {
|
2014-05-02 04:03:02 +02:00
|
|
|
$message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!";
|
|
|
|
if ($player) {
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendSuccess($message, $player);
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->log($message);
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-07-24 23:15:25 +02:00
|
|
|
$this->maniaControl->configurator->showMenu($player, InstallMenu::getTitle());
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-05-02 17:50:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle PlayerManialinkPageAnswer callback
|
|
|
|
*
|
|
|
|
* @param array $callback
|
|
|
|
*/
|
|
|
|
public function handleManialinkPageAnswer(array $callback) {
|
|
|
|
$actionId = $callback[1][2];
|
|
|
|
$update = (strpos($actionId, PluginMenu::ACTION_PREFIX_UPDATEPLUGIN) === 0);
|
2014-07-01 21:23:50 +02:00
|
|
|
$install = (strpos($actionId, InstallMenu::ACTION_PREFIX_INSTALL_PLUGIN) === 0);
|
2014-05-02 17:50:30 +02:00
|
|
|
if (!$update && !$install) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$login = $callback[1][1];
|
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
|
|
|
|
|
|
if ($update) {
|
|
|
|
$pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN));
|
2014-06-14 14:32:29 +02:00
|
|
|
if ($pluginClass === 'All') {
|
2014-05-02 17:50:30 +02:00
|
|
|
$this->performPluginsUpdate($player);
|
|
|
|
} else {
|
|
|
|
$pluginUpdateData = $this->getPluginUpdate($pluginClass);
|
|
|
|
if ($pluginUpdateData) {
|
|
|
|
$this->installPlugin($pluginUpdateData, $player, true);
|
|
|
|
} else {
|
|
|
|
$message = 'Error loading Plugin Update Data!';
|
|
|
|
$this->maniaControl->chat->sendError($message, $player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-07-01 21:23:50 +02:00
|
|
|
$pluginId = substr($actionId, strlen(InstallMenu::ACTION_PREFIX_INSTALL_PLUGIN));
|
2014-05-02 17:50:30 +02:00
|
|
|
|
2014-06-17 23:27:28 +02:00
|
|
|
$url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId;
|
|
|
|
$this->maniaControl->fileReader->loadFile($url, function ($data, $error) use (&$player) {
|
2014-05-02 17:50:30 +02:00
|
|
|
if ($error || !$data) {
|
|
|
|
$message = "Error loading Plugin Install Data! {$error}";
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendError($message, $player);
|
2014-05-02 17:50:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-15 01:31:31 +02:00
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
$data = json_decode($data);
|
2014-06-15 01:31:31 +02:00
|
|
|
if (!$data) {
|
2014-05-02 17:50:30 +02:00
|
|
|
$message = "Error loading Plugin Install Data! {$error}";
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->maniaControl->chat->sendError($message, $player);
|
2014-05-02 17:50:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-06-15 01:31:31 +02:00
|
|
|
|
|
|
|
$pluginUpdateData = new PluginUpdateData($data);
|
2014-06-17 23:27:28 +02:00
|
|
|
$this->installPlugin($pluginUpdateData, $player);
|
2014-05-02 17:50:30 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check given Plugin Class for Update
|
|
|
|
*
|
|
|
|
* @param string $pluginClass
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getPluginUpdate($pluginClass) {
|
|
|
|
$pluginClass = PluginManager::getPluginClass($pluginClass);
|
2014-05-30 03:17:39 +02:00
|
|
|
/** @var Plugin $pluginClass */
|
|
|
|
$pluginId = $pluginClass::getId();
|
|
|
|
$url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId;
|
2014-06-27 01:18:55 +02:00
|
|
|
$response = WebReader::loadUrl($url);
|
|
|
|
$dataJson = $response->getContent();
|
2014-05-30 03:17:39 +02:00
|
|
|
$pluginVersion = json_decode($dataJson);
|
|
|
|
if (!$pluginVersion) {
|
2014-05-02 17:50:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-05-30 03:17:39 +02:00
|
|
|
$pluginUpdateData = new PluginUpdateData($pluginVersion);
|
|
|
|
$version = $pluginClass::getVersion();
|
|
|
|
if ($pluginUpdateData->isNewerThan($version)) {
|
2014-05-02 17:50:30 +02:00
|
|
|
return $pluginUpdateData;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-02 04:03:02 +02:00
|
|
|
}
|