|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fenos\Notifynder\Artisan; |
|
4
|
|
|
|
|
5
|
|
|
use Fenos\Notifynder\Contracts\NotifynderCategory; |
|
6
|
|
|
use Illuminate\Console\Command; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
|
|
9
|
|
|
class DeleteCategory extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The console command name. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $name = 'notifynder:delete:category'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The console command description. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Delete a notifynder category by ID or Name given'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var \\Fenos\Notifynder\Contracts\NotifynderCategory |
|
27
|
|
|
*/ |
|
28
|
|
|
private $notifynderCategory; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Create a new command instance. |
|
32
|
|
|
* |
|
33
|
|
|
* @param NotifynderCategory $notifynderCategory |
|
34
|
|
|
* @return \Fenos\Notifynder\Artisan\DeleteCategory |
|
|
|
|
|
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(NotifynderCategory $notifynderCategory) |
|
37
|
|
|
{ |
|
38
|
|
|
parent::__construct(); |
|
39
|
|
|
$this->notifynderCategory = $notifynderCategory; |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Execute the console command. |
|
44
|
|
|
* |
|
45
|
|
|
* @return mixed |
|
46
|
|
|
*/ |
|
47
|
|
|
public function fire() |
|
48
|
|
|
{ |
|
49
|
|
|
$identifier = $this->argument('identifier'); |
|
50
|
|
|
|
|
51
|
|
|
if ($this->isIntegerValue($identifier)) { |
|
52
|
|
|
$delete = $this->notifynderCategory->delete($identifier); |
|
53
|
|
|
} else { |
|
54
|
|
|
$delete = $this->notifynderCategory->deleteByName($identifier); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (! $delete) { |
|
58
|
|
|
$this->error('Category Not found'); |
|
59
|
|
|
|
|
60
|
|
|
return false; |
|
61
|
|
|
} |
|
62
|
|
|
$this->info('Category has been deleted'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function isIntegerValue($identifier) |
|
66
|
|
|
{ |
|
67
|
|
|
return preg_match('/[0-9]/', $identifier); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get the console command arguments. |
|
72
|
|
|
* |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function getArguments() |
|
76
|
|
|
{ |
|
77
|
|
|
return [ |
|
78
|
|
|
['identifier', InputArgument::REQUIRED, '1 - nameCategory'], |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.