1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Sync Github issue states Shell. |
5
|
|
|
* |
6
|
|
|
* phpMyAdmin Error reporting server |
7
|
|
|
* Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
8
|
|
|
* |
9
|
|
|
* Licensed under The MIT License |
10
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
11
|
|
|
* Redistributions of files must retain the above copyright notice. |
12
|
|
|
* |
13
|
|
|
* @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
14
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
15
|
|
|
* |
16
|
|
|
* @see https://www.phpmyadmin.net/ |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace App\Shell; |
20
|
|
|
|
21
|
|
|
use App\Application; |
22
|
|
|
use Cake\Command\Command; |
23
|
|
|
use Cake\Console\Arguments; |
24
|
|
|
use Cake\Console\ConsoleIo; |
25
|
|
|
use Cake\Console\ConsoleOptionParser; |
26
|
|
|
use Cake\Core\Configure; |
27
|
|
|
use Cake\Http\ServerRequest; |
28
|
|
|
use Cake\Http\Session; |
29
|
|
|
use Cake\Log\Log; |
30
|
|
|
use const PHP_SAPI; |
31
|
|
|
use function date; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Sync Github issue states Shell. |
35
|
|
|
*/ |
36
|
|
|
class SyncGithubIssueStatesShell extends Command |
37
|
|
|
{ |
38
|
|
|
protected const NAME = 'sync_github_issue_states'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The name of this command. |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $name = self::NAME; |
46
|
|
|
|
47
|
21 |
|
public static function defaultName(): string |
48
|
|
|
{ |
49
|
21 |
|
return self::NAME; |
50
|
|
|
} |
51
|
|
|
|
52
|
7 |
|
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser |
53
|
|
|
{ |
54
|
|
|
return $parser |
55
|
7 |
|
->setCommand($this->name) |
56
|
7 |
|
->setDescription('Sync GitHub issues states'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return int |
61
|
|
|
*/ |
62
|
7 |
|
public function execute(Arguments $args, ConsoleIo $io) |
63
|
|
|
{ |
64
|
7 |
|
Log::debug( |
65
|
|
|
'STARTED: Job "' |
66
|
|
|
. 'github/sync_issue_status' |
67
|
|
|
. '" at ' |
68
|
7 |
|
. date('d-m-Y G:i:s (e)'), |
69
|
7 |
|
['scope' => 'cron_jobs'] |
70
|
|
|
); |
71
|
|
|
|
72
|
7 |
|
Configure::write('CronDispatcher', true); |
73
|
7 |
|
if (PHP_SAPI !== 'cli') { |
74
|
|
|
exit; |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
7 |
|
$session = Session::create(); |
78
|
7 |
|
$session->write('Developer.id', 1); |
79
|
7 |
|
$request = new ServerRequest([ |
80
|
7 |
|
'url' => '/github/sync_issue_status', |
81
|
|
|
'params' => [ |
82
|
|
|
'controller' => 'Github', |
83
|
|
|
'action' => 'sync_issue_status', |
84
|
|
|
], |
85
|
7 |
|
'session' => $session, |
86
|
|
|
]); |
87
|
|
|
|
88
|
7 |
|
$server = new Application(''); |
89
|
7 |
|
$response = $server->handle($request); |
90
|
7 |
|
if ($response->getStatusCode() === 200) { |
91
|
7 |
|
Log::debug( |
92
|
|
|
'FINISHED: Job "' |
93
|
|
|
. 'github/sync_issue_status' |
94
|
|
|
. '" at ' |
95
|
7 |
|
. date('d-m-Y G:i:s (e)'), |
96
|
7 |
|
['scope' => 'cron_jobs'] |
97
|
|
|
); |
98
|
|
|
|
99
|
7 |
|
return 0; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
Log::error( |
103
|
|
|
'ERROR: Job "' |
104
|
|
|
. 'github/sync_issue_status' |
105
|
|
|
. '" at ' |
106
|
|
|
. date('d-m-Y G:i:s (e)') |
107
|
|
|
. ' response code: ' . $response->getStatusCode(), |
108
|
|
|
['scope' => 'cron_jobs'] |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
return 1; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.