Example #1
0
 /**
  *  Delete a project
  *
  * @return void
  *
  * @throws \Exception
  */
 public function delete()
 {
     $id = $this->id;
     parent::delete();
     /* Delete all children from the project */
     Project\Issue::where('project_id', '=', $id)->delete();
     Project\Issue\Comment::where('project_id', '=', $id)->delete();
     Project\User::where('project_id', '=', $id)->delete();
     User\Activity::where('parent_id', '=', $id)->delete();
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     if (!Schema::hasTable('tags')) {
         Schema::create('tags', function (Blueprint $table) {
             $table->increments('id')->unsigned();
             $table->bigInteger('parent_id')->default(0);
             $table->string('name', 255)->unique();
             $table->string('bgcolor', 50)->nullable();
             $table->boolean('group');
             $table->timestamps();
         });
         $groups = ['status', 'type', 'resolution'];
         foreach ($groups as $group) {
             $model = new Model\Tag();
             $model->name = $group;
             $model->group = true;
             $model->save();
         }
         $tags = [['name' => 'open', 'parent_id' => 'status', 'bgcolor' => '#c43c35'], ['name' => 'testing', 'parent_id' => 'status', 'bgcolor' => '#6c8307'], ['name' => 'closed', 'parent_id' => 'status', 'bgcolor' => '#46a546'], ['name' => 'feature', 'parent_id' => 'type', 'bgcolor' => '#62cffc'], ['name' => 'bug', 'parent_id' => 'type', 'bgcolor' => '#f89406'], ['name' => 'won\'t fix', 'parent_id' => 'resolution', 'bgcolor' => '#812323'], ['name' => 'fixed', 'parent_id' => 'resolution', 'bgcolor' => '#048383']];
         foreach ($tags as $tag) {
             $model = new Model\Tag();
             $model->name = $tag['name'];
             $model->bgcolor = $tag['bgcolor'];
             $model->parent_id = Model\Tag::where('name', '=', $tag['parent_id'])->first()->id;
             $model->group = false;
             $model->save();
         }
     }
     if (!Schema::hasTable('projects_issues_tags')) {
         Schema::create('projects_issues_tags', function (Blueprint $table) {
             $table->bigInteger('issue_id');
             $table->bigInteger('tag_id');
             $table->primary(['issue_id', 'tag_id']);
         });
     }
     $openIssues = Model\Project\Issue::where('status', '=', Model\Project\Issue::STATUS_OPEN)->lists('id');
     if (count($openIssues) > 0) {
         $openTag = Model\Tag::where('parent_id', '=', Model\Tag::where('name', '=', 'status')->first()->id)->where('name', '=', 'open')->first();
         $openTag->issues()->attach($openIssues);
     }
     $closedIssues = Model\Project\Issue::where('status', '=', Model\Project\Issue::STATUS_CLOSED)->lists('id');
     if (count($closedIssues) > 0) {
         $closedTag = Model\Tag::where('parent_id', '=', Model\Tag::where('name', '=', 'status')->first()->id)->where('name', '=', 'closed')->first();
         $closedTag->issues()->attach($closedIssues);
     }
     // Create activity type for tag update
     $activity = new Model\Activity();
     $activity->description = 'Updated issue tags';
     $activity->activity = 'update-issue-tags';
     $activity->save();
 }
 /**
  * Fetch an issue by column
  *
  * @param string          $field
  * @param int|string|bool $value
  *
  * @return Model\Project\Issue
  */
 public function fetchIssueBy($field, $value)
 {
     return Model\Project\Issue::where($field, '=', $value)->first();
 }