|
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
|
|
|
|
|
31
|
|
|
use function date; |
|
32
|
|
|
|
|
33
|
|
|
use const PHP_SAPI; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Sync Github issue states Shell. |
|
37
|
|
|
*/ |
|
38
|
|
|
class SyncGithubIssueStatesShell extends Command |
|
39
|
|
|
{ |
|
40
|
|
|
protected const NAME = 'sync_github_issue_states'; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The name of this command. |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $name = self::NAME; |
|
48
|
|
|
|
|
49
|
21 |
|
public static function defaultName(): string |
|
50
|
|
|
{ |
|
51
|
21 |
|
return self::NAME; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
7 |
|
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser |
|
55
|
|
|
{ |
|
56
|
|
|
return $parser |
|
57
|
7 |
|
->setCommand($this->name) |
|
58
|
7 |
|
->setDescription('Sync GitHub issues states'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return int |
|
63
|
|
|
*/ |
|
64
|
7 |
|
public function execute(Arguments $args, ConsoleIo $io) |
|
65
|
|
|
{ |
|
66
|
7 |
|
Log::debug( |
|
67
|
|
|
'STARTED: Job "' |
|
68
|
|
|
. 'github/sync_issue_status' |
|
69
|
|
|
. '" at ' |
|
70
|
7 |
|
. date('d-m-Y G:i:s (e)'), |
|
71
|
7 |
|
['scope' => 'cron_jobs'] |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
7 |
|
Configure::write('CronDispatcher', true); |
|
75
|
7 |
|
if (PHP_SAPI !== 'cli') { |
|
76
|
|
|
exit; |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
7 |
|
$session = Session::create(); |
|
80
|
7 |
|
$session->write('Developer.id', 1); |
|
81
|
7 |
|
$request = new ServerRequest([ |
|
82
|
7 |
|
'url' => '/github/sync_issue_status', |
|
83
|
|
|
'params' => [ |
|
84
|
|
|
'controller' => 'Github', |
|
85
|
|
|
'action' => 'sync_issue_status', |
|
86
|
|
|
], |
|
87
|
7 |
|
'session' => $session, |
|
88
|
|
|
]); |
|
89
|
|
|
|
|
90
|
7 |
|
$server = new Application(''); |
|
91
|
7 |
|
$response = $server->handle($request); |
|
92
|
7 |
|
if ($response->getStatusCode() === 200) { |
|
93
|
7 |
|
Log::debug( |
|
94
|
|
|
'FINISHED: Job "' |
|
95
|
|
|
. 'github/sync_issue_status' |
|
96
|
|
|
. '" at ' |
|
97
|
7 |
|
. date('d-m-Y G:i:s (e)'), |
|
98
|
7 |
|
['scope' => 'cron_jobs'] |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
7 |
|
return 0; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
Log::error( |
|
105
|
|
|
'ERROR: Job "' |
|
106
|
|
|
. 'github/sync_issue_status' |
|
107
|
|
|
. '" at ' |
|
108
|
|
|
. date('d-m-Y G:i:s (e)') |
|
109
|
|
|
. ' response code: ' . $response->getStatusCode(), |
|
110
|
|
|
['scope' => 'cron_jobs'] |
|
111
|
|
|
); |
|
112
|
|
|
|
|
113
|
|
|
return 1; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.