Commit feeba15e authored by ZeMKI's avatar ZeMKI
Browse files

New command: delete studies with interview

New command studies:delete it deletes
study
interview
token
answers
parent b400ff09
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class DeleteClosedStudies extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'studies:delete';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete a study that has already interviews';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*php ar
* @return mixed
*/
public function handle()
{
$headers = ['Study Name', 'made by'];
$studiesAndCreator = \App\Study::join('users','user_id','=','users.id')->select('studies.name', 'users.email')->get()->toArray();
$this->table($headers, $studiesAndCreator);
$headers = ['Study Id','Study Name'];
$studies = \App\Study::select('studies.id','studies.name')->get()->toArray();
$this->table($headers, $studies);
$studiesId = \App\Study::pluck('id')->toArray();
array_unshift($studiesId,0);
$this->warn("Press 0 to delete nothing");
$id = $this->choice('Which study you want to delete??',$studiesId,0);
$study = \App\Study::find($id);
if(!$study){
$this->warn("study not found or exited with 0");
}else if($study->interviews->count() > 0){
if($this->confirm("THIS STUDY HAS INTERVIEWS, YOU WILL DELETE THEM. ARE YOU SURE?",false)){
foreach ($study->interviews as $i){
$i->answers()->detach();
$i->answers()->delete();
$i->tokens()->detach();
$i->tokens()->delete();
$i->delete();
}
$study->interviews()->delete();
$study->delete();
$this->info("study deleted!");
}
}
}
}
......@@ -13,7 +13,8 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
Commands\CreateUserCommand::class
Commands\CreateUserCommand::class,
Commands\DeleteClosedStudies::class
];
/**
......
......@@ -29,6 +29,8 @@ class Study extends LaratrustTeam
if(strpos($f, 'presets') === false)Storage::delete($f);
}
foreach ($tokens as $t) {
Token::where('id', $t)->delete();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment