1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Etobi\CoreAPI\Service; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of the TYPO3 CMS project. |
7
|
|
|
* |
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
10
|
|
|
* of the License, or any later version. |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please read the |
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* The TYPO3 project - inspiring people to share! |
16
|
|
|
*/ |
17
|
|
|
use InvalidArgumentException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class DatabaseRealCompare |
21
|
|
|
* |
22
|
|
|
* @package Etobi\CoreAPI\Service |
23
|
|
|
* @author Georg Ringer <[email protected]> |
24
|
|
|
* @author Stefano Kowalke <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class DatabaseCompareReal extends DatabaseComparator { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Database compare. |
30
|
|
|
* |
31
|
|
|
* @param string $actions comma separated list of IDs |
32
|
|
|
* |
33
|
|
|
* @throws InvalidArgumentException |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
public function compare($actions) { |
|
|
|
|
37
|
|
|
$errors = array(); |
38
|
|
|
$results = array(); |
39
|
|
|
|
40
|
|
|
$allowedActions = $this->getAllowedActions($actions); |
41
|
|
|
|
42
|
|
|
$expectedSchema = $this->sqlExpectedSchemaService->getExpectedDatabaseSchema(); |
43
|
|
|
$currentSchema = $this->schemaMigrationService->getFieldDefinitions_database(); |
44
|
|
|
|
45
|
|
|
$addCreateChange = $this->schemaMigrationService->getDatabaseExtra($expectedSchema, $currentSchema); |
46
|
|
|
$addCreateChange = $this->schemaMigrationService->getUpdateSuggestions($addCreateChange); |
47
|
|
|
|
48
|
|
|
$dropRemove = $this->schemaMigrationService->getDatabaseExtra($currentSchema, $expectedSchema); |
49
|
|
|
$dropRemove = $this->schemaMigrationService->getUpdateSuggestions($dropRemove, 'remove'); |
50
|
|
|
|
51
|
|
|
$allowedRequestKeys = $this->getRequestKeys($addCreateChange, $dropRemove); |
52
|
|
|
|
53
|
|
|
if ($allowedActions[self::ACTION_UPDATE_CLEAR_TABLE] == 1) { |
54
|
|
|
$results[] = $this->schemaMigrationService->performUpdateQueries($addCreateChange['clear_table'], $allowedRequestKeys); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($allowedActions[self::ACTION_UPDATE_ADD] == 1) { |
58
|
|
|
$results[] = $this->schemaMigrationService->performUpdateQueries($addCreateChange['add'], $allowedRequestKeys); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
if ($allowedActions[self::ACTION_UPDATE_CHANGE] == 1) { |
|
|
|
|
62
|
|
|
$results[] = $this->schemaMigrationService->performUpdateQueries($addCreateChange['change'], $allowedRequestKeys); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ($allowedActions[self::ACTION_UPDATE_CREATE_TABLE] == 1) { |
66
|
|
|
$results[] = $this->schemaMigrationService->performUpdateQueries($addCreateChange['create_table'], $allowedRequestKeys); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
View Code Duplication |
if ($allowedActions[self::ACTION_REMOVE_CHANGE] == 1) { |
|
|
|
|
70
|
|
|
$results[] = $this->schemaMigrationService->performUpdateQueries($dropRemove['change'], $allowedRequestKeys); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
View Code Duplication |
if ($allowedActions[self::ACTION_REMOVE_DROP] == 1) { |
|
|
|
|
74
|
|
|
$results[] = $this->schemaMigrationService->performUpdateQueries($dropRemove['drop'], $allowedRequestKeys); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
View Code Duplication |
if ($allowedActions[self::ACTION_REMOVE_CHANGE_TABLE] == 1) { |
|
|
|
|
78
|
|
|
$results[] = $this->schemaMigrationService->performUpdateQueries($dropRemove['change_table'], $allowedRequestKeys); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
View Code Duplication |
if ($allowedActions[self::ACTION_REMOVE_DROP_TABLE] == 1) { |
|
|
|
|
82
|
|
|
$results[] = $this->schemaMigrationService->performUpdateQueries($dropRemove['drop_table'], $allowedRequestKeys); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
foreach ($results as $resultSet) { |
86
|
|
|
if (is_array($resultSet)) { |
87
|
|
|
foreach ($resultSet as $key => $errorMessage) { |
88
|
|
|
$errors[$key] = $errorMessage; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $errors; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get all request keys, even for those requests which are not used. |
98
|
|
|
* |
99
|
|
|
* @param array $update |
100
|
|
|
* @param array $remove |
101
|
|
|
* |
102
|
|
|
* @return array |
103
|
|
|
*/ |
104
|
|
|
protected function getRequestKeys(array $update, array $remove) { |
105
|
|
|
$tmpKeys = array(); |
106
|
|
|
|
107
|
|
|
$updateActions = array('clear_table', 'add', 'change', 'create_table'); |
108
|
|
|
$removeActions = array('change', 'drop', 'change_table', 'drop_table'); |
109
|
|
|
|
110
|
|
View Code Duplication |
foreach ($updateActions as $updateAction) { |
|
|
|
|
111
|
|
|
if (isset($update[$updateAction]) && is_array($update[$updateAction])) { |
112
|
|
|
$tmpKeys[] = array_keys($update[$updateAction]); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
View Code Duplication |
foreach ($removeActions as $removeAction) { |
|
|
|
|
117
|
|
|
if (isset($remove[$removeAction]) && is_array($remove[$removeAction])) { |
118
|
|
|
$tmpKeys[] = array_keys($remove[$removeAction]); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$finalKeys = array(); |
123
|
|
|
foreach ($tmpKeys as $keys) { |
124
|
|
|
foreach ($keys as $key) { |
125
|
|
|
$finalKeys[$key] = TRUE; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
return $finalKeys; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.
You can also find more information in the “Code” section of your repository.