/** * Generates the group listing for the view. * * @param \Illuminate\Contracts\View\View $view * @return void */ public function compose(View $view) { $active_group = null; $active_project = null; if (isset($view->project) && !$view->project->is_template) { $active_group = $view->project->group_id; $active_project = $view->project->id; } $groups = Group::where('id', '<>', Template::GROUP_ID)->orderBy('name')->get(); $view->with('active_group', $active_group); $view->with('active_project', $active_project); $view->with('groups', $groups); }
/** * Run the migrations. */ public function up() { Schema::table('groups', function (Blueprint $table) { $table->unsignedInteger('order')->default(0); }); $groups = Group::where('id', '<>', Template::GROUP_ID)->orderBy('name')->get(); $i = 0; foreach ($groups as $group) { $group->order = $i; $group->save(); $i++; } }
/** * Reverse the migrations. * * @return void */ public function down() { $group = Group::findOrFail(1); $group->delete(); }
/** * Run the migrations. * * @return void */ public function up() { foreach ($this->relations as $relation) { $className = "REBELinBLUE\\Deployer\\{$relation}"; $instance = new $className(); $table = $instance->getTable(); // Add the target fields to the tables Schema::table($table, function (Blueprint $table) { $table->integer('target_id')->nullable(); $table->string('target_type')->nullable(); }); if (config('database.default') !== 'sqlite') { $drop = config('database.default') === 'mysql' ? 'FOREIGN KEY' : 'CONSTRAINT'; DB::statement("ALTER TABLE {$table} DROP {$drop} {$table}_project_id_foreign"); } } // Now find the existing templates in the project template and move them to templates table $templates = []; foreach (Project::where('is_template', true)->get() as $project) { $data = $project->toArray(); unset($data['id']); $templates[$project->id] = Template::create($data); } // Now loop through the relations and set the target details foreach ($this->relations as $relation) { $className = "REBELinBLUE\\Deployer\\{$relation}"; $instance = new $className(); foreach ($instance->all() as $row) { $row->target_id = $row->project_id; $row->target_type = 'project'; if (isset($templates[$row->project_id])) { $row->target_id = $templates[$row->project_id]->id; $row->target_type = 'template'; } $row->save(); } } // Remove any deleted non templates from group 1 to group 2 $project = new Project(); $project->where('is_template', false)->where('group_id', 1)->withTrashed()->update(['group_id' => 2]); // Remove the left over fake templates and the containing group Project::where('is_template', true)->forceDelete(); Group::find(1)->forceDelete(); // Remove the unneeded project ID column foreach ($this->relations as $relation) { $className = "REBELinBLUE\\Deployer\\{$relation}"; $instance = new $className(); $table = $instance->getTable(); // You can't drop a column in SQLite if (config('database.default') !== 'sqlite') { DB::statement("ALTER TABLE {$table} DROP COLUMN project_id"); } if (config('database.default') === 'mysql') { DB::statement("ALTER TABLE {$table} MODIFY target_id INT(11) NOT NULL"); DB::statement("ALTER TABLE {$table} MODIFY target_type VARCHAR(255) NOT NULL"); } elseif (config('database.default') === 'pgsql') { DB::statement("ALTER TABLE {$table} ALTER COLUMN target_id SET NOT NULL"); DB::statement("ALTER TABLE {$table} ALTER COLUMN target_type SET NOT NULL"); } } }