-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathInstanceCommandParser.php
79 lines (68 loc) · 2.71 KB
/
InstanceCommandParser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php declare(strict_types = 1);
/**
* This file is part of the SqlFtw library (https://github.com/sqlftw)
*
* Copyright (c) 2017 Vlasta Neubauer (@paranoiq)
*
* For the full copyright and license information read the file 'license.md', distributed with this source code
*/
namespace SqlFtw\Parser\Ddl;
use SqlFtw\Parser\InvalidVersionException;
use SqlFtw\Parser\ParserException;
use SqlFtw\Parser\TokenList;
use SqlFtw\Platform\Features\Feature;
use SqlFtw\Platform\Platform;
use SqlFtw\Sql\Ddl\Instance\AlterInstanceAction;
use SqlFtw\Sql\Ddl\Instance\AlterInstanceCommand;
use SqlFtw\Sql\Keyword;
use function strtolower;
class InstanceCommandParser
{
private Platform $platform;
public function __construct(Platform $platform)
{
$this->platform = $platform;
}
/**
* 8.0 https://dev.mysql.com/doc/refman/8.0/en/alter-instance.html
* ALTER INSTANCE instance_action
*
* instance_action: {
* | {ENABLE|DISABLE} INNODB REDO_LOG
* | ROTATE INNODB MASTER KEY
* | ROTATE BINLOG MASTER KEY
* | RELOAD TLS
* [FOR CHANNEL {mysql_main | mysql_admin}]
* [NO ROLLBACK ON ERROR]
* | RELOAD KEYRING
* }
*
* 5.7 https://dev.mysql.com/doc/refman/5.7/en/alter-instance.html
* ALTER INSTANCE ROTATE INNODB MASTER KEY
*/
public function parseAlterInstance(TokenList $tokenList): AlterInstanceCommand
{
if (!isset($this->platform->features[Feature::ALTER_INSTANCE])) {
throw new InvalidVersionException(Feature::ALTER_INSTANCE, $this->platform, $tokenList);
}
$tokenList->expectKeywords(Keyword::ALTER, Keyword::INSTANCE);
$action = $tokenList->expectMultiNameEnum(AlterInstanceAction::class);
if (!$action->equalsValue(AlterInstanceAction::ROTATE_INNODB_MASTER_KEY)
&& !isset($this->platform->features[Feature::ALTER_INSTANCE_2])
) {
throw new InvalidVersionException(Feature::ALTER_INSTANCE_2, $this->platform, $tokenList);
}
$forChannel = null;
$noRollbackOnError = false;
if ($action->equalsValue(AlterInstanceAction::RELOAD_TLS)) {
if ($tokenList->hasKeywords(Keyword::FOR, Keyword::CHANNEL)) {
$forChannel = strtolower($tokenList->expectNonReservedNameOrString());
if ($forChannel !== 'mysql_main' && $forChannel !== 'mysql_admin') {
throw new ParserException('Invalid channel name.', $tokenList);
}
}
$noRollbackOnError = $tokenList->hasKeywords(Keyword::NO, Keyword::ROLLBACK, Keyword::ON, Keyword::ERROR);
}
return new AlterInstanceCommand($action, $forChannel, $noRollbackOnError);
}
}