applied common formatting
This commit is contained in:
@ -11,9 +11,9 @@ use ManiaControl\ManiaControl;
|
||||
/**
|
||||
* Asynchronous File Reader
|
||||
*
|
||||
* @author kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class AsynchronousFileReader {
|
||||
/*
|
||||
@ -35,13 +35,13 @@ class AsynchronousFileReader {
|
||||
* Appends the Data
|
||||
*/
|
||||
public function appendData() {
|
||||
foreach($this->requests as $key => $request) {
|
||||
foreach ($this->requests as $key => $request) {
|
||||
/** @var Request $request */
|
||||
try {
|
||||
if ($request->socketPerform()) {
|
||||
$request->socketSelect();
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
if ($e->getMessage() == "Cannot perform if there are no requests in queue.") {
|
||||
unset($this->requests[$key]);
|
||||
} else {
|
||||
@ -54,10 +54,10 @@ class AsynchronousFileReader {
|
||||
/**
|
||||
* Load a remote file
|
||||
*
|
||||
* @param string $url
|
||||
* @param callable $function
|
||||
* @param string $contentType
|
||||
* @param int $keepAlive
|
||||
* @param string $url
|
||||
* @param callable $function
|
||||
* @param string $contentType
|
||||
* @param int $keepAlive
|
||||
* @return bool
|
||||
*/
|
||||
public function loadFile($url, $function, $contentType = 'UTF-8', $keepAlive = 0) {
|
||||
@ -119,11 +119,11 @@ class AsynchronousFileReader {
|
||||
/**
|
||||
* Send Data via POST Method
|
||||
*
|
||||
* @param string $url
|
||||
* @param callable $function
|
||||
* @param string $content
|
||||
* @param bool $compression
|
||||
* @param string $contentType
|
||||
* @param string $url
|
||||
* @param callable $function
|
||||
* @param string $content
|
||||
* @param bool $compression
|
||||
* @param string $contentType
|
||||
* @return bool
|
||||
*/
|
||||
public function postData($url, $function, $content, $compression = false, $contentType = 'text/xml; charset=UTF-8') {
|
||||
|
@ -1,14 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Files;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Backup Utility Class
|
||||
*
|
||||
* @author ManiaControl Team
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
abstract class BackupUtil {
|
||||
/*
|
||||
@ -18,53 +19,30 @@ abstract class BackupUtil {
|
||||
|
||||
/**
|
||||
* Perform a Full Backup of ManiaControl
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function performFullBackup() {
|
||||
$backupFolder = self::getBackupFolder();
|
||||
$backupFolder = self::getBackupFolder();
|
||||
$backupFileName = $backupFolder . 'backup_' . ManiaControl::VERSION . '_' . date('y-m-d') . '_' . time() . '.zip';
|
||||
$backupZip = new \ZipArchive();
|
||||
if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== TRUE) {
|
||||
$backupZip = new \ZipArchive();
|
||||
if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== true) {
|
||||
trigger_error("Couldn't create Backup Zip!");
|
||||
return false;
|
||||
}
|
||||
$excludes = array('.', '..', 'backup', 'logs', 'ManiaControl.log');
|
||||
$pathInfo = pathInfo(ManiaControlDir);
|
||||
$excludes = array('.', '..', 'backup', 'logs', 'ManiaControl.log');
|
||||
$pathInfo = pathInfo(ManiaControlDir);
|
||||
$parentPath = $pathInfo['dirname'] . '/';
|
||||
$dirName = $pathInfo['basename'];
|
||||
$dirName = $pathInfo['basename'];
|
||||
$backupZip->addEmptyDir($dirName);
|
||||
self::zipDirectory($backupZip, ManiaControlDir, strlen($parentPath), $excludes);
|
||||
$backupZip->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a Backup of the Plugins
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function performPluginsBackup() {
|
||||
$backupFolder = self::getBackupFolder();
|
||||
$backupFileName = $backupFolder . 'backup_plugins_' . date('y-m-d') . '_' . time() . '.zip';
|
||||
$backupZip = new \ZipArchive();
|
||||
if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== TRUE) {
|
||||
trigger_error("Couldn't create Backup Zip!");
|
||||
return false;
|
||||
}
|
||||
$excludes = array('.', '..');
|
||||
$pathInfo = pathInfo(ManiaControlDir . '/plugins');
|
||||
$parentPath = $pathInfo['dirname'] . '/';
|
||||
$dirName = $pathInfo['basename'];
|
||||
$backupZip->addEmptyDir($dirName);
|
||||
self::zipDirectory($backupZip, ManiaControlDir . '/plugins', strlen($parentPath), $excludes);
|
||||
$backupZip->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Backup Folder Path and create it if necessary
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getBackupFolder() {
|
||||
@ -77,11 +55,11 @@ abstract class BackupUtil {
|
||||
|
||||
/**
|
||||
* Add a complete Directory to the ZipArchive
|
||||
*
|
||||
*
|
||||
* @param \ZipArchive $zipArchive
|
||||
* @param string $folderName
|
||||
* @param int $prefixLength
|
||||
* @param array $excludes
|
||||
* @param string $folderName
|
||||
* @param int $prefixLength
|
||||
* @param array $excludes
|
||||
* @return bool
|
||||
*/
|
||||
private static function zipDirectory(\ZipArchive &$zipArchive, $folderName, $prefixLength, array $excludes = array()) {
|
||||
@ -94,7 +72,7 @@ abstract class BackupUtil {
|
||||
if (in_array($file, $excludes)) {
|
||||
continue;
|
||||
}
|
||||
$filePath = $folderName . '/' . $file;
|
||||
$filePath = $folderName . '/' . $file;
|
||||
$localPath = substr($filePath, $prefixLength);
|
||||
if (is_file($filePath)) {
|
||||
$zipArchive->addFile($filePath, $localPath);
|
||||
@ -109,4 +87,27 @@ abstract class BackupUtil {
|
||||
closedir($folderHandle);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a Backup of the Plugins
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function performPluginsBackup() {
|
||||
$backupFolder = self::getBackupFolder();
|
||||
$backupFileName = $backupFolder . 'backup_plugins_' . date('y-m-d') . '_' . time() . '.zip';
|
||||
$backupZip = new \ZipArchive();
|
||||
if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== true) {
|
||||
trigger_error("Couldn't create Backup Zip!");
|
||||
return false;
|
||||
}
|
||||
$excludes = array('.', '..');
|
||||
$pathInfo = pathInfo(ManiaControlDir . '/plugins');
|
||||
$parentPath = $pathInfo['dirname'] . '/';
|
||||
$dirName = $pathInfo['basename'];
|
||||
$backupZip->addEmptyDir($dirName);
|
||||
self::zipDirectory($backupZip, ManiaControlDir . '/plugins', strlen($parentPath), $excludes);
|
||||
$backupZip->close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,15 @@
|
||||
|
||||
namespace ManiaControl\Files;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Formatter;
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Files Utility Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
abstract class FileUtil {
|
||||
/*
|
||||
@ -20,7 +20,7 @@ abstract class FileUtil {
|
||||
|
||||
/**
|
||||
* Load a remote file
|
||||
*
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $contentType
|
||||
* @return string || null
|
||||
@ -29,48 +29,48 @@ abstract class FileUtil {
|
||||
if (!$url) {
|
||||
return null;
|
||||
}
|
||||
$urlData = parse_url($url);
|
||||
$port = (isset($urlData['port']) ? $urlData['port'] : 80);
|
||||
$urlData = parse_url($url);
|
||||
$port = (isset($urlData['port']) ? $urlData['port'] : 80);
|
||||
$urlQuery = isset($urlData['query']) ? "?" . $urlData['query'] : "";
|
||||
|
||||
|
||||
$fsock = fsockopen($urlData['host'], $port);
|
||||
stream_set_timeout($fsock, 3);
|
||||
|
||||
|
||||
$query = 'GET ' . $urlData['path'] . $urlQuery . ' HTTP/1.0' . PHP_EOL;
|
||||
$query .= 'Host: ' . $urlData['host'] . PHP_EOL;
|
||||
$query .= 'Content-Type: ' . $contentType . PHP_EOL;
|
||||
$query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL;
|
||||
$query .= PHP_EOL;
|
||||
|
||||
|
||||
fwrite($fsock, $query);
|
||||
|
||||
|
||||
$buffer = '';
|
||||
$info = array('timed_out' => false);
|
||||
$info = array('timed_out' => false);
|
||||
while (!feof($fsock) && !$info['timed_out']) {
|
||||
$buffer .= fread($fsock, 1024);
|
||||
$info = stream_get_meta_data($fsock);
|
||||
}
|
||||
fclose($fsock);
|
||||
|
||||
|
||||
if ($info['timed_out'] || !$buffer) {
|
||||
return null;
|
||||
}
|
||||
if (substr($buffer, 9, 3) != "200") {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
$result = explode("\r\n\r\n", $buffer, 2);
|
||||
|
||||
|
||||
if (count($result) < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return $result[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load config xml-file
|
||||
*
|
||||
*
|
||||
* @param string $fileName
|
||||
* @return \SimpleXMLElement
|
||||
*/
|
||||
@ -89,7 +89,7 @@ abstract class FileUtil {
|
||||
|
||||
/**
|
||||
* Return file name cleared from special characters
|
||||
*
|
||||
*
|
||||
* @param string $fileName
|
||||
* @return string
|
||||
*/
|
||||
@ -100,9 +100,19 @@ abstract class FileUtil {
|
||||
return $fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the Temporary Folder if it's empty
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function removeTempFolder() {
|
||||
$tempFolder = self::getTempFolder(false);
|
||||
return @rmdir($tempFolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Temporary Folder and create it if necessary
|
||||
*
|
||||
*
|
||||
* @param bool $createIfNecessary
|
||||
* @return string
|
||||
*/
|
||||
@ -114,19 +124,9 @@ abstract class FileUtil {
|
||||
return $tempFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the Temporary Folder if it's empty
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function removeTempFolder() {
|
||||
$tempFolder = self::getTempFolder(false);
|
||||
return @rmdir($tempFolder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if ManiaControl has sufficient Access to write to Files in the given Directories
|
||||
*
|
||||
*
|
||||
* @param mixed $directories
|
||||
* @return bool
|
||||
*/
|
||||
@ -134,7 +134,7 @@ abstract class FileUtil {
|
||||
if (!is_array($directories)) {
|
||||
$directories = array($directories);
|
||||
}
|
||||
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
$dir = new \RecursiveDirectoryIterator(ManiaControlDir . $directory);
|
||||
foreach (new \RecursiveIteratorIterator($dir) as $fileName => $file) {
|
||||
@ -148,7 +148,7 @@ abstract class FileUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user