Add database management back to front-end and begin some refactoring
Here we go again boys...
This commit is contained in:
parent
2b80de03df
commit
97dc0519d6
32 changed files with 774 additions and 407 deletions
|
@ -10,6 +10,7 @@
|
|||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Pterodactyl\Models\Database;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||
|
@ -17,6 +18,11 @@ use Pterodactyl\Exceptions\Repository\DuplicateDatabaseNameException;
|
|||
|
||||
class DatabaseRepository extends EloquentRepository implements DatabaseRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $connection = self::DEFAULT_CONNECTION_NAME;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\DatabaseManager
|
||||
*/
|
||||
|
@ -45,6 +51,40 @@ class DatabaseRepository extends EloquentRepository implements DatabaseRepositor
|
|||
return Database::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the connection name to execute statements against.
|
||||
*
|
||||
* @param string $connection
|
||||
* @return $this
|
||||
*/
|
||||
public function setConnection(string $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the connection to execute statements aganist.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConnection(): string
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the databases belonging to a server.
|
||||
*
|
||||
* @param int $server
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getDatabasesForServer(int $server): Collection
|
||||
{
|
||||
return $this->getBuilder()->where('server_id', $server)->get($this->getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @return bool|\Illuminate\Database\Eloquent\Model
|
||||
|
@ -67,80 +107,64 @@ class DatabaseRepository extends EloquentRepository implements DatabaseRepositor
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createDatabase($database, $connection = null)
|
||||
public function createDatabase($database)
|
||||
{
|
||||
return $this->runStatement(
|
||||
sprintf('CREATE DATABASE IF NOT EXISTS `%s`', $database),
|
||||
$connection
|
||||
);
|
||||
return $this->runStatement(sprintf('CREATE DATABASE IF NOT EXISTS `%s`', $database));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createUser($username, $remote, $password, $connection = null)
|
||||
public function createUser($username, $remote, $password)
|
||||
{
|
||||
return $this->runStatement(
|
||||
sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\'', $username, $remote, $password),
|
||||
$connection
|
||||
);
|
||||
return $this->runStatement(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\'', $username, $remote, $password));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function assignUserToDatabase($database, $username, $remote, $connection = null)
|
||||
public function assignUserToDatabase($database, $username, $remote)
|
||||
{
|
||||
return $this->runStatement(
|
||||
sprintf(
|
||||
'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX, EXECUTE ON `%s`.* TO `%s`@`%s`',
|
||||
$database,
|
||||
$username,
|
||||
$remote
|
||||
),
|
||||
$connection
|
||||
);
|
||||
return $this->runStatement(sprintf(
|
||||
'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX, EXECUTE ON `%s`.* TO `%s`@`%s`',
|
||||
$database,
|
||||
$username,
|
||||
$remote
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function flush($connection = null)
|
||||
public function flush()
|
||||
{
|
||||
return $this->runStatement('FLUSH PRIVILEGES', $connection);
|
||||
return $this->runStatement('FLUSH PRIVILEGES');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dropDatabase($database, $connection = null)
|
||||
public function dropDatabase($database)
|
||||
{
|
||||
return $this->runStatement(
|
||||
sprintf('DROP DATABASE IF EXISTS `%s`', $database),
|
||||
$connection
|
||||
);
|
||||
return $this->runStatement(sprintf('DROP DATABASE IF EXISTS `%s`', $database));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dropUser($username, $remote, $connection = null)
|
||||
public function dropUser($username, $remote)
|
||||
{
|
||||
return $this->runStatement(
|
||||
sprintf('DROP USER IF EXISTS `%s`@`%s`', $username, $remote),
|
||||
$connection
|
||||
);
|
||||
return $this->runStatement(sprintf('DROP USER IF EXISTS `%s`@`%s`', $username, $remote));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the provided statement against the database on a given connection.
|
||||
*
|
||||
* @param string $statement
|
||||
* @param null|string $connection
|
||||
* @param string $statement
|
||||
* @return bool
|
||||
*/
|
||||
protected function runStatement($statement, $connection = null)
|
||||
protected function runStatement($statement)
|
||||
{
|
||||
return $this->database->connection($connection)->statement($statement);
|
||||
return $this->database->connection($this->getConnection())->statement($statement);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue