From 4dddcaebb0423503a4b5437992f6da51afcc4870 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 13 Sep 2020 11:29:47 -0700 Subject: [PATCH] Start ripping out old search functionality for models --- .../Attributes/SearchableInterface.php | 38 ------------------- .../LocationRepositoryInterface.php | 3 +- .../Repository/NodeRepositoryInterface.php | 2 +- .../Repository/ServerRepositoryInterface.php | 3 +- .../Repository/UserRepositoryInterface.php | 2 +- app/Models/Node.php | 16 +------- app/Models/Server.php | 17 --------- app/Models/Traits/Searchable.php | 13 ------- app/Models/User.php | 16 -------- app/Repositories/Concerns/Searchable.php | 32 ---------------- .../Eloquent/EloquentRepository.php | 14 +------ .../Eloquent/LocationRepository.php | 3 -- app/Repositories/Eloquent/MountRepository.php | 3 -- app/Repositories/Eloquent/NodeRepository.php | 11 +----- .../Eloquent/ServerRepository.php | 15 +++----- app/Repositories/Eloquent/UserRepository.php | 9 +---- 16 files changed, 15 insertions(+), 182 deletions(-) delete mode 100644 app/Contracts/Repository/Attributes/SearchableInterface.php delete mode 100644 app/Models/Traits/Searchable.php diff --git a/app/Contracts/Repository/Attributes/SearchableInterface.php b/app/Contracts/Repository/Attributes/SearchableInterface.php deleted file mode 100644 index f1ab6e804..000000000 --- a/app/Contracts/Repository/Attributes/SearchableInterface.php +++ /dev/null @@ -1,38 +0,0 @@ - 10, - 'fqdn' => 8, - 'location.short' => 4, - 'location.long' => 4, - ]; - /** * @var array */ @@ -216,7 +202,7 @@ class Node extends Model */ public function getDecryptedKey(): string { - return (string) Container::getInstance()->make(Encrypter::class)->decrypt( + return (string)Container::getInstance()->make(Encrypter::class)->decrypt( $this->daemon_token ); } diff --git a/app/Models/Server.php b/app/Models/Server.php index 4684ece65..3ccf9eadb 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -3,7 +3,6 @@ namespace Pterodactyl\Models; use Illuminate\Notifications\Notifiable; -use Pterodactyl\Models\Traits\Searchable; use Illuminate\Database\Query\JoinClause; use Znck\Eloquent\Traits\BelongsToThrough; @@ -58,7 +57,6 @@ class Server extends Model { use BelongsToThrough; use Notifiable; - use Searchable; /** * The resource name for this model when it is transformed into an @@ -154,21 +152,6 @@ class Server extends Model 'backup_limit' => 'integer', ]; - /** - * Parameters for search querying. - * - * @var array - */ - protected $searchableColumns = [ - 'name' => 100, - 'uuid' => 80, - 'uuidShort' => 80, - 'external_id' => 50, - 'user.email' => 40, - 'user.username' => 30, - 'node.name' => 10, - ]; - /** * Returns the format for server allocations when communicating with the Daemon. * diff --git a/app/Models/Traits/Searchable.php b/app/Models/Traits/Searchable.php deleted file mode 100644 index d1ab0eb86..000000000 --- a/app/Models/Traits/Searchable.php +++ /dev/null @@ -1,13 +0,0 @@ - 100, - 'email' => 100, - 'external_id' => 80, - 'uuid' => 80, - 'name_first' => 40, - 'name_last' => 40, - ]; - /** * Default values for specific fields in the database. * diff --git a/app/Repositories/Concerns/Searchable.php b/app/Repositories/Concerns/Searchable.php index 8bb11a552..2ae0b82a7 100644 --- a/app/Repositories/Concerns/Searchable.php +++ b/app/Repositories/Concerns/Searchable.php @@ -11,18 +11,6 @@ trait Searchable */ protected $searchTerm; - /** - * Set the search term. - * - * @param string|null $term - * @return $this - * @deprecated - */ - public function search($term) - { - return $this->setSearchTerm($term); - } - /** * Set the search term to use when requesting all records from * the model. @@ -41,24 +29,4 @@ trait Searchable return $clone; } - - /** - * Determine if a valid search term is set on this repository. - * - * @return bool - */ - public function hasSearchTerm(): bool - { - return ! empty($this->searchTerm); - } - - /** - * Return the search term. - * - * @return string|null - */ - public function getSearchTerm() - { - return $this->searchTerm; - } } diff --git a/app/Repositories/Eloquent/EloquentRepository.php b/app/Repositories/Eloquent/EloquentRepository.php index 34b5247af..bd8133022 100644 --- a/app/Repositories/Eloquent/EloquentRepository.php +++ b/app/Repositories/Eloquent/EloquentRepository.php @@ -289,12 +289,7 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf */ public function all(): Collection { - $instance = $this->getBuilder(); - if (is_subclass_of(get_called_class(), SearchableInterface::class) && $this->hasSearchTerm()) { - $instance = $instance->search($this->getSearchTerm()); - } - - return $instance->get($this->getColumns()); + return $this->getBuilder()->get($this->getColumns()); } /** @@ -305,12 +300,7 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf */ public function paginated(int $perPage): LengthAwarePaginator { - $instance = $this->getBuilder(); - if (is_subclass_of(get_called_class(), SearchableInterface::class) && $this->hasSearchTerm()) { - $instance = $instance->search($this->getSearchTerm()); - } - - return $instance->paginate($perPage, $this->getColumns()); + return $this->getBuilder()->paginate($perPage, $this->getColumns()); } /** diff --git a/app/Repositories/Eloquent/LocationRepository.php b/app/Repositories/Eloquent/LocationRepository.php index 47d5e321a..6d14d5aa6 100644 --- a/app/Repositories/Eloquent/LocationRepository.php +++ b/app/Repositories/Eloquent/LocationRepository.php @@ -4,15 +4,12 @@ namespace Pterodactyl\Repositories\Eloquent; use Pterodactyl\Models\Location; use Illuminate\Support\Collection; -use Pterodactyl\Repositories\Concerns\Searchable; use Illuminate\Database\Eloquent\ModelNotFoundException; use Pterodactyl\Exceptions\Repository\RecordNotFoundException; use Pterodactyl\Contracts\Repository\LocationRepositoryInterface; class LocationRepository extends EloquentRepository implements LocationRepositoryInterface { - use Searchable; - /** * Return the model backing this repository. * diff --git a/app/Repositories/Eloquent/MountRepository.php b/app/Repositories/Eloquent/MountRepository.php index c75ba2aa6..286e07913 100644 --- a/app/Repositories/Eloquent/MountRepository.php +++ b/app/Repositories/Eloquent/MountRepository.php @@ -5,14 +5,11 @@ namespace Pterodactyl\Repositories\Eloquent; use Pterodactyl\Models\Mount; use Pterodactyl\Models\Server; use Illuminate\Support\Collection; -use Pterodactyl\Repositories\Concerns\Searchable; use Illuminate\Database\Eloquent\ModelNotFoundException; use Pterodactyl\Exceptions\Repository\RecordNotFoundException; class MountRepository extends EloquentRepository { - use Searchable; - /** * Return the model backing this repository. * diff --git a/app/Repositories/Eloquent/NodeRepository.php b/app/Repositories/Eloquent/NodeRepository.php index 2385c9109..489782fb8 100644 --- a/app/Repositories/Eloquent/NodeRepository.php +++ b/app/Repositories/Eloquent/NodeRepository.php @@ -5,14 +5,11 @@ namespace Pterodactyl\Repositories\Eloquent; use Pterodactyl\Models\Node; use Illuminate\Support\Collection; use Illuminate\Support\LazyCollection; -use Pterodactyl\Repositories\Concerns\Searchable; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Pterodactyl\Contracts\Repository\NodeRepositoryInterface; class NodeRepository extends EloquentRepository implements NodeRepositoryInterface { - use Searchable; - /** * Return the model backing this repository. * @@ -92,13 +89,7 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa */ public function getNodeListingData(): LengthAwarePaginator { - $instance = $this->getBuilder()->with('location')->withCount('servers'); - - if ($this->hasSearchTerm()) { - $instance->search($this->getSearchTerm()); - } - - return $instance->paginate(25, $this->getColumns()); + return $this->getBuilder()->with('location')->withCount('servers')->paginate(25, $this->getColumns()); } /** diff --git a/app/Repositories/Eloquent/ServerRepository.php b/app/Repositories/Eloquent/ServerRepository.php index 73bf85733..d49a68994 100644 --- a/app/Repositories/Eloquent/ServerRepository.php +++ b/app/Repositories/Eloquent/ServerRepository.php @@ -5,7 +5,6 @@ namespace Pterodactyl\Repositories\Eloquent; use Pterodactyl\Models\Server; use Illuminate\Support\Collection; use Illuminate\Database\Eloquent\Builder; -use Pterodactyl\Repositories\Concerns\Searchable; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Pterodactyl\Exceptions\Repository\RecordNotFoundException; @@ -13,8 +12,6 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; class ServerRepository extends EloquentRepository implements ServerRepositoryInterface { - use Searchable; - /** * Return the model backing this repository. * @@ -33,9 +30,7 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt */ public function getAllServers(int $paginate): LengthAwarePaginator { - $instance = $this->getBuilder()->with('node', 'user', 'allocation')->search($this->getSearchTerm()); - - return $instance->paginate($paginate, $this->getColumns()); + return $this->getBuilder()->with('node', 'user', 'allocation')->paginate($paginate, $this->getColumns()); } /** @@ -67,7 +62,7 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt if (! is_null($server) && is_null($node)) { $instance = $instance->where('id', '=', $server); - } elseif (is_null($server) && ! is_null($node)) { + } else if (is_null($server) && ! is_null($node)) { $instance = $instance->where('node_id', '=', $node); } @@ -87,7 +82,7 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt if (! is_null($server) && is_null($node)) { $instance = $instance->where('id', '=', $server); - } elseif (is_null($server) && ! is_null($node)) { + } else if (is_null($server) && ! is_null($node)) { $instance = $instance->where('node_id', '=', $node); } @@ -224,9 +219,9 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt if (! empty($nodes) && ! empty($servers)) { $instance->whereIn('id', $servers)->orWhereIn('node_id', $nodes); - } elseif (empty($nodes) && ! empty($servers)) { + } else if (empty($nodes) && ! empty($servers)) { $instance->whereIn('id', $servers); - } elseif (! empty($nodes) && empty($servers)) { + } else if (! empty($nodes) && empty($servers)) { $instance->whereIn('node_id', $nodes); } diff --git a/app/Repositories/Eloquent/UserRepository.php b/app/Repositories/Eloquent/UserRepository.php index b6468b5bb..693bbb2a0 100644 --- a/app/Repositories/Eloquent/UserRepository.php +++ b/app/Repositories/Eloquent/UserRepository.php @@ -4,14 +4,11 @@ namespace Pterodactyl\Repositories\Eloquent; use Pterodactyl\Models\User; use Illuminate\Support\Collection; -use Pterodactyl\Repositories\Concerns\Searchable; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Pterodactyl\Contracts\Repository\UserRepositoryInterface; class UserRepository extends EloquentRepository implements UserRepositoryInterface { - use Searchable; - /** * Return the model backing this repository. * @@ -29,9 +26,7 @@ class UserRepository extends EloquentRepository implements UserRepositoryInterfa */ public function getAllUsersWithCounts(): LengthAwarePaginator { - return $this->getBuilder()->withCount('servers') - ->search($this->getSearchTerm()) - ->paginate(50, $this->getColumns()); + return $this->getBuilder()->withCount('servers')->paginate(50, $this->getColumns()); } /** @@ -46,7 +41,7 @@ class UserRepository extends EloquentRepository implements UserRepositoryInterfa 'id', 'email', 'username', 'name_first', 'name_last', ]); - $instance = $this->getBuilder()->search($query)->get($this->getColumns()); + $instance = $this->getBuilder()->get($this->getColumns()); return $instance->transform(function ($item) { $item->md5 = md5(strtolower($item->email));