Start ripping out old search functionality for models
This commit is contained in:
parent
3c7ffaaadb
commit
4dddcaebb0
16 changed files with 15 additions and 182 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
Reference in a new issue