From 8e657a0bf0c146ce143f90c4f72a6277b4e74827 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 1 Sep 2016 21:21:01 -0400 Subject: [PATCH] Remove old 'active' column and replace some references with 'suspended' in place --- app/Console/Commands/RunTasks.php | 2 +- app/Http/Controllers/Admin/UserController.php | 1 - app/Models/Server.php | 9 +++--- app/Repositories/ServerRepository.php | 2 +- ...2016_09_01_211924_remove_active_column.php | 31 +++++++++++++++++++ 5 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 database/migrations/2016_09_01_211924_remove_active_column.php diff --git a/app/Console/Commands/RunTasks.php b/app/Console/Commands/RunTasks.php index 351dabd68..cb69cc15c 100644 --- a/app/Console/Commands/RunTasks.php +++ b/app/Console/Commands/RunTasks.php @@ -67,7 +67,7 @@ class RunTasks extends Command */ public function handle() { - $tasks = Models\Task::where('queued', 0)->where('active', 1)->where('next_run', '<=', (Carbon::now())->toAtomString())->get(); + $tasks = Models\Task::where('queued', 0)->where('suspended', 0)->where('next_run', '<=', (Carbon::now())->toAtomString())->get(); $this->info(sprintf('Preparing to queue %d tasks.', count($tasks))); $bar = $this->output->createProgressBar(count($tasks)); diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index da0aeac9b..e46e8f03e 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -69,7 +69,6 @@ class UserController extends Controller ->join('nodes', 'servers.node', '=', 'nodes.id') ->join('locations', 'nodes.location', '=', 'locations.id') ->where('owner', $id) - ->where('active', 1) ->get(), ]); } diff --git a/app/Models/Server.php b/app/Models/Server.php index 02857590b..171e62194 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -59,7 +59,7 @@ class Server extends Model */ protected $casts = [ 'node' => 'integer', - 'active' => 'integer', + 'suspended' => 'integer', 'owner' => 'integer', 'memory' => 'integer', 'swap' => 'integer', @@ -117,7 +117,7 @@ class Server extends Model /** * Returns array of all servers owned by the logged in user. - * Returns all active servers if user is a root admin. + * Returns all users servers if user is a root admin. * * @return \Illuminate\Database\Eloquent\Collection */ @@ -132,8 +132,7 @@ class Server extends Model 'allocations.port' )->join('nodes', 'servers.node', '=', 'nodes.id') ->join('locations', 'nodes.location', '=', 'locations.id') - ->join('allocations', 'servers.allocation', '=', 'allocations.id') - ->where('active', 1); + ->join('allocations', 'servers.allocation', '=', 'allocations.id'); if (self::$user->root_admin !== 1) { $query->whereIn('servers.id', Subuser::accessServers()); @@ -164,7 +163,7 @@ class Server extends Model $query = self::select('servers.*', 'services.file as a_serviceFile') ->join('services', 'services.id', '=', 'servers.service') - ->where('uuidShort', $uuid)->where('active', 1); + ->where('uuidShort', $uuid); if (self::$user->root_admin !== 1) { $query->whereIn('servers.id', Subuser::accessServers()); diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index c5d0c6bcf..06d97e353 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -205,7 +205,7 @@ class ServerRepository 'uuidShort' => $uuid->generateShort('servers', 'uuidShort', $generatedUuid), 'node' => $data['node'], 'name' => $data['name'], - 'active' => 1, + 'suspended' => 0, 'owner' => $user->id, 'memory' => $data['memory'], 'swap' => $data['swap'], diff --git a/database/migrations/2016_09_01_211924_remove_active_column.php b/database/migrations/2016_09_01_211924_remove_active_column.php new file mode 100644 index 000000000..746559a80 --- /dev/null +++ b/database/migrations/2016_09_01_211924_remove_active_column.php @@ -0,0 +1,31 @@ +dropColumn('active'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('servers', function (Blueprint $table) { + $table->tinyInteger('active')->after('name')->unsigned()->default(0); + }); + } +}