karma plugin settings migration
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl;
|
||||
namespace ManiaControl\Database;
|
||||
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Database Connection Class
|
||||
@ -16,6 +17,7 @@ class Database implements TimerListener {
|
||||
* Public Properties
|
||||
*/
|
||||
public $mysqli = null;
|
||||
public $migrationHelper = null;
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
@ -59,6 +61,9 @@ class Database implements TimerListener {
|
||||
|
||||
// Register Method which checks the Database Connection every 5 seconds
|
||||
$this->maniaControl->timerManager->registerTimerListening($this, 'checkConnection', 5000);
|
||||
|
||||
// Create migration helper
|
||||
$this->migrationHelper = new MigrationHelper($maniaControl);
|
||||
}
|
||||
|
||||
/**
|
75
application/core/Database/MigrationHelper.php
Normal file
75
application/core/Database/MigrationHelper.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Database;
|
||||
|
||||
use ManiaControl\Settings\SettingManager;
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Database Migration Assistant
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class MigrationHelper {
|
||||
/*
|
||||
* Private Properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Construct Migration Helper
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer the Settings of the given Class to a new One
|
||||
*
|
||||
* @param mixed $sourceClass
|
||||
* @param mixed $targetClass
|
||||
* @return bool
|
||||
*/
|
||||
public function transferSettings($sourceClass, $targetClass) {
|
||||
$sourceClass = $this->getClass($sourceClass);
|
||||
$targetClass = $this->getClass($targetClass);
|
||||
|
||||
var_dump($sourceClass, $targetClass);
|
||||
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
$query = "INSERT INTO `" . SettingManager::TABLE_SETTINGS . "` (`class`, `setting`, `type`, `value`, `default`)
|
||||
SELECT ?, `setting`, `type`, `value`, `default` FROM `" . SettingManager::TABLE_SETTINGS . "` WHERE `class` = ?;";
|
||||
$statement = $mysqli->prepare($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
$statement->bind_param('ss', $targetClass, $sourceClass);
|
||||
if ($statement->error) {
|
||||
trigger_error($statement->error);
|
||||
$statement->close();
|
||||
return false;
|
||||
}
|
||||
$success = $statement->execute();
|
||||
$statement->close();
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Class of the given Object
|
||||
*
|
||||
* @param mixed $class
|
||||
* @return string
|
||||
*/
|
||||
private function getClass($class) {
|
||||
if (is_object($class)) {
|
||||
return get_class($class);
|
||||
}
|
||||
return (string) $class;
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ use Maniaplanet\DedicatedServer\Connection;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\TransportException;
|
||||
use ManiaControl\Database\Database;
|
||||
|
||||
require_once __DIR__ . '/Libs/Maniaplanet/DedicatedServer/Connection.php';
|
||||
require_once __DIR__ . '/Libs/GbxDataFetcher/gbxdatafetcher.inc.php';
|
||||
|
Reference in New Issue
Block a user