Merge branch 'develop' into feature/api-v1

This commit is contained in:
Dane Everitt 2017-12-14 21:12:17 -06:00
commit a1da8a3c9d
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
68 changed files with 1785 additions and 524 deletions

View file

@ -24,8 +24,10 @@
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\User;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\DaemonKey;
use Illuminate\Support\Collection;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Contracts\Repository\DaemonKeyRepositoryInterface;
@ -83,4 +85,28 @@ class DaemonKeyRepository extends EloquentRepository implements DaemonKeyReposit
return $instance;
}
/**
* Get all of the keys for a specific user including the information needed
* from their server relation for revocation on the daemon.
*
* @param \Pterodactyl\Models\User $user
* @return \Illuminate\Support\Collection
*/
public function getKeysForRevocation(User $user): Collection
{
return $this->getBuilder()->with('server:id,uuid,node_id')->where('user_id', $user->id)->get($this->getColumns());
}
/**
* Delete an array of daemon keys from the database. Used primarily in
* conjunction with getKeysForRevocation.
*
* @param array $ids
* @return bool|int
*/
public function deleteKeys(array $ids)
{
return $this->getBuilder()->whereIn('id', $ids)->delete();
}
}

View file

@ -18,11 +18,6 @@ class LocationRepository extends EloquentRepository implements LocationRepositor
{
use Searchable;
/**
* @var string
*/
protected $searchTerm;
/**
* {@inheritdoc}
*/

View file

@ -0,0 +1,96 @@
<?php
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Setting;
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
class SettingsRepository extends EloquentRepository implements SettingsRepositoryInterface
{
/**
* @var array
*/
private $cache = [];
/**
* @var array
*/
private $databaseMiss = [];
/**
* Return an instance of the model that acts as the base for
* this repository.
*
* @return string
*/
public function model()
{
return Setting::class;
}
/**
* Store a new persistent setting in the database.
*
* @param string $key
* @param string $value
*/
public function set(string $key, string $value)
{
// Clear item from the cache.
$this->clearCache($key);
$this->withoutFresh()->updateOrCreate(['key' => $key], ['value' => $value]);
}
/**
* Retrieve a persistent setting from the database.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function get(string $key, $default = null)
{
// If item has already been requested return it from the cache. If
// we already know it is missing, immediately return the default
// value.
if (array_key_exists($key, $this->cache)) {
return $this->cache[$key];
} elseif (array_key_exists($key, $this->databaseMiss)) {
return $default;
}
$instance = $this->getBuilder()->where('key', $key)->first();
if (is_null($instance)) {
$this->databaseMiss[$key] = true;
return $default;
}
$this->cache[$key] = $instance->value;
return $this->cache[$key];
}
/**
* Remove a key from the database cache.
*
* @param string $key
* @return mixed
*/
public function forget(string $key)
{
$this->clearCache($key);
$this->deleteWhere(['key' => $key]);
}
/**
* Remove a key from the cache.
*
* @param string $key
*/
protected function clearCache(string $key)
{
unset($this->cache[$key], $this->databaseMiss[$key]);
}
}