1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Garbuzivan\Laraveltokens\Commands; |
6
|
|
|
|
7
|
|
|
use Carbon\Carbon; |
8
|
|
|
use Garbuzivan\Laraveltokens\TokenManager; |
9
|
|
|
use Illuminate\Console\Command; |
10
|
|
|
use Illuminate\Support\Composer; |
11
|
|
|
|
12
|
|
|
class ProlongationByUserCommand extends Command |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* The console command name. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $name = 'tokens:prolongation-by-user {user_id} {day?} {user_type?}'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The console command description. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $description = 'Продлить срок действия всех токенов по id пользователя ' . |
27
|
|
|
'(tokens:prolongation-by-user {user_id} {day?} {user_type?})'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The console command signature. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $signature = 'tokens:prolongation-by-user {user_id} {day?} {user_type?}'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Composer |
38
|
|
|
*/ |
39
|
|
|
public Composer $composer; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var TokenManager |
43
|
|
|
*/ |
44
|
|
|
public TokenManager $TokenManager; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Create a new command instance. |
48
|
|
|
*/ |
49
|
|
|
public function __construct(TokenManager $TokenManager) |
50
|
|
|
{ |
51
|
|
|
parent::__construct(); |
52
|
|
|
$this->TokenManager = $TokenManager; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Execute the command. |
57
|
|
|
* |
58
|
|
|
* @return mixed |
59
|
|
|
*/ |
60
|
|
|
public function handle() |
61
|
|
|
{ |
62
|
|
|
$arguments = $this->arguments(); |
63
|
|
|
$user_id = $arguments['user_id'] ? intval($arguments['user_id']) : null; |
64
|
|
|
$user_type = $arguments['user_type'] ?? $this->TokenManager->getDefaultMorph(); |
65
|
|
|
if (is_null($user_id) || $user_id < 1) { |
66
|
|
|
$this->line('ID пользователя не введен.'); |
67
|
|
|
return 1; |
68
|
|
|
} |
69
|
|
|
$expiration = intval($arguments['day']) > 0 ? Carbon::now()->addDays(intval($arguments['day'])) : null; |
70
|
|
|
$this->TokenManager->prolongationAccessTokenByUser($user_id, $user_type, $expiration); |
71
|
|
|
$date = is_null($expiration) ? 'навсегда' : 'до ' . $expiration->format('Y-m-d H:i:s'); |
72
|
|
|
$this->line('Токен продлен ' . $date . '.'); |
73
|
|
|
return 1; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|