4
4
5
5
namespace Linkage \DoctrineRowLevelSecurity ;
6
6
7
+ use Doctrine \DBAL \Platforms \AbstractPlatform ;
7
8
use Doctrine \DBAL \Schema \Comparator ;
8
9
use Doctrine \DBAL \Schema \Schema ;
9
10
use Doctrine \DBAL \Schema \SchemaDiff ;
10
11
use Doctrine \DBAL \Schema \SchemaException ;
11
12
use Doctrine \DBAL \Schema \Table ;
12
13
use Doctrine \DBAL \Schema \TableDiff ;
13
14
14
- class RowLevelSecurityAwareComparator
15
+ class RowLevelSecurityAwareComparator extends Comparator
15
16
{
16
- private readonly Comparator $ delegate ;
17
-
18
- public function __construct ()
17
+ public function __construct (AbstractPlatform $ platform )
19
18
{
20
- $ this -> delegate = new Comparator ( );
19
+ parent :: __construct ( $ platform );
21
20
}
22
21
23
22
public function compareSchemas (Schema $ fromSchema , Schema $ toSchema ): RowLevelSecurityAwareSchemaDiff |SchemaDiff
24
23
{
25
- $ baseDiff = $ this -> delegate -> compare ($ fromSchema , $ toSchema );
24
+ $ baseDiff = parent :: compareSchemas ($ fromSchema , $ toSchema );
26
25
27
26
$ hasRlsDiff = false ;
28
27
foreach ($ toSchema ->getTables () as $ toTable ) {
@@ -32,37 +31,35 @@ public function compareSchemas(Schema $fromSchema, Schema $toSchema): RowLevelSe
32
31
// 新規テーブルは差分がある扱いなのでcreateのイベントリスナに任せる
33
32
continue ;
34
33
}
35
- $ tableDiff = $ this ->diffTable ($ fromTable , $ toTable );
34
+ $ tableDiff = $ this ->compareTable ($ fromTable , $ toTable );
36
35
if ($ tableDiff instanceof RowLevelSecurityAwareTableDiff) {
37
- $ baseDiff ->changedTables [$ tableDiff ->name ] = $ tableDiff ;
36
+ $ baseDiff ->changedTables [$ tableDiff ->getOldTable ()-> getName () ] = $ tableDiff ;
38
37
$ hasRlsDiff = true ;
39
38
}
40
39
}
41
40
42
41
return $ hasRlsDiff ? new RowLevelSecurityAwareSchemaDiff ($ baseDiff ) : $ baseDiff ;
43
42
}
44
43
45
- public function diffTable (Table $ fromTable , Table $ toTable ): TableDiff | bool
44
+ public function compareTable (Table $ fromTable , Table $ toTable ): TableDiff
46
45
{
47
- $ baseDiff = $ this -> delegate -> diffTable ($ fromTable , $ toTable );
46
+ $ baseTableDiff = parent :: compareTable ($ fromTable , $ toTable );
48
47
49
48
if ($ toTable ->hasOption (RowLevelSecurityConfig::RLS_OPTION_NAME ) && !$ fromTable ->hasOption (RowLevelSecurityConfig::RLS_OPTION_NAME )) {
50
49
// RLSがなかったテーブルにRLSを足した時
51
- $ baseTableDiff = $ baseDiff instanceof TableDiff ? $ baseDiff : new TableDiff ($ toTable ->getName (), fromTable: $ fromTable );
52
50
$ rlsTableDiff = new RowLevelSecurityAwareTableDiff ($ baseTableDiff );
53
51
$ rlsTableDiff ->addedRowLevelSecurity = $ toTable ->getOption (RowLevelSecurityConfig::RLS_OPTION_NAME );
54
52
55
53
return $ rlsTableDiff ;
56
54
}
57
55
if (!$ toTable ->hasOption (RowLevelSecurityConfig::RLS_OPTION_NAME ) && $ fromTable ->hasOption (RowLevelSecurityConfig::RLS_OPTION_NAME )) {
58
56
// RLSがあったテーブルのRLSを消した時
59
- $ baseTableDiff = $ baseDiff instanceof TableDiff ? $ baseDiff : new TableDiff ($ toTable ->getName (), fromTable: $ fromTable );
60
57
$ rlsTableDiff = new RowLevelSecurityAwareTableDiff ($ baseTableDiff );
61
58
$ rlsTableDiff ->removedRowLevelSecurity = $ fromTable ->getOption (RowLevelSecurityConfig::RLS_OPTION_NAME );
62
59
63
60
return $ rlsTableDiff ;
64
61
}
65
62
66
- return $ baseDiff ;
63
+ return $ baseTableDiff ;
67
64
}
68
65
}
0 commit comments