Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ZeMKI
Mesort
Commits
feeba15e
Commit
feeba15e
authored
May 17, 2019
by
ZeMKI
Browse files
New command: delete studies with interview
New command studies:delete it deletes study interview token answers
parent
b400ff09
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/Console/Commands/DeleteClosedStudies.php
0 → 100644
View file @
feeba15e
<?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!"
);
}
}
}
}
app/Console/Kernel.php
View file @
feeba15e
...
...
@@ -13,7 +13,8 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected
$commands
=
[
Commands\CreateUserCommand
::
class
Commands\CreateUserCommand
::
class
,
Commands\DeleteClosedStudies
::
class
];
/**
...
...
app/Study.php
View file @
feeba15e
...
...
@@ -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
();
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment