|
25 | 25 | */ |
26 | 26 | class DatabaseCompareDry extends DatabaseComparator { |
27 | 27 |
|
28 | | - /** |
29 | | - * @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService $schemaMigrationService Instance of SQL handler |
30 | | - */ |
31 | | - protected $schemaMigrationService; |
32 | | - |
33 | | - /** |
34 | | - * Inject the SchemaMigrationService |
35 | | - * |
36 | | - * @param \TYPO3\CMS\Install\Service\SqlSchemaMigrationService $schemaMigrationService |
37 | | - */ |
38 | | - public function injectSchemaMigrationService(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService $schemaMigrationService) { |
39 | | - $this->schemaMigrationService = $schemaMigrationService; |
40 | | - } |
41 | | - |
42 | 28 | /** |
43 | 29 | * Database compare. |
44 | 30 | * |
45 | 31 | * @param string $actions comma separated list of IDs |
46 | | - * |
47 | 32 | * @throws InvalidArgumentException |
48 | | - * |
49 | 33 | * @return array |
50 | 34 | */ |
51 | 35 | public function compare($actions) { |
52 | 36 | $errors = array(); |
53 | | - $allowedActions = array(); |
| 37 | + $results = array(); |
54 | 38 |
|
55 | | - $this->checkAvailableActions($actions, $allowedActions); |
| 39 | + $allowedActions = $this->getAllowedActions($actions); |
56 | 40 |
|
57 | | - $tblFileContent = ''; |
| 41 | + $expectedSchema = $this->sqlExpectedSchemaService->getExpectedDatabaseSchema(); |
| 42 | + $currentSchema = $this->schemaMigrationService->getFieldDefinitions_database(); |
58 | 43 |
|
59 | | - foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $loadedExtConf) { |
60 | | - if (is_array($loadedExtConf) && $loadedExtConf['ext_tables.sql']) { |
61 | | - $extensionSqlContent = $this->getUrl($loadedExtConf['ext_tables.sql']); |
62 | | - $tblFileContent .= LF . LF . LF . LF . $extensionSqlContent; |
63 | | - } |
64 | | - } |
| 44 | + $addCreateChange = $this->schemaMigrationService->getDatabaseExtra($expectedSchema, $currentSchema); |
| 45 | + $addCreateChange = $this->schemaMigrationService->getUpdateSuggestions($addCreateChange); |
65 | 46 |
|
66 | | - if (is_callable('TYPO3\\CMS\\Core\\Cache\\Cache::getDatabaseTableDefinitions')) { |
67 | | - $tblFileContent .= $this->getDatabaseTableDefinitionsFromCache(); |
68 | | - } |
| 47 | + $dropRemove = $this->schemaMigrationService->getDatabaseExtra($currentSchema, $expectedSchema); |
| 48 | + $dropRemove = $this->schemaMigrationService->getUpdateSuggestions($dropRemove, 'remove'); |
69 | 49 |
|
70 | | - if (class_exists('TYPO3\\CMS\\Core\\Category\\CategoryRegistry')) { |
71 | | - $tblFileContent .= $this->getCategoryRegistry()->getDatabaseTableDefinitions(); |
| 50 | + if ($allowedActions[self::ACTION_UPDATE_CLEAR_TABLE] == 1) { |
| 51 | + $results['update_clear_table'] = $addCreateChange['clear_table']; |
72 | 52 | } |
73 | 53 |
|
74 | | - if ($tblFileContent) { |
75 | | - $fileContent = implode(LF, $this->schemaMigrationService->getStatementArray($tblFileContent, 1, '^CREATE TABLE ')); |
76 | | - $fieldDefinitionsFromFile = $this->schemaMigrationService->getFieldDefinitions_fileContent($fileContent); |
77 | | - |
78 | | - $fieldDefinitionsFromDb = $this->schemaMigrationService->getFieldDefinitions_database(); |
79 | | - |
80 | | - $diff = $this->schemaMigrationService->getDatabaseExtra($fieldDefinitionsFromFile, $fieldDefinitionsFromDb); |
81 | | - $updateStatements = $this->schemaMigrationService->getUpdateSuggestions($diff); |
82 | | - |
83 | | - $results = array(); |
84 | | - |
85 | | - if ($allowedActions[self::ACTION_UPDATE_CLEAR_TABLE] == 1) { |
86 | | - $results['clear_table'] = $updateStatements['clear_table']; |
87 | | - } |
88 | | - |
89 | | - if ($allowedActions[self::ACTION_UPDATE_ADD] == 1) { |
90 | | - $results['add'] = $updateStatements['add']; |
91 | | - } |
| 54 | + if ($allowedActions[self::ACTION_UPDATE_ADD] == 1) { |
| 55 | + $results['update_add'] = $addCreateChange['add']; |
| 56 | + } |
92 | 57 |
|
93 | | - if ($allowedActions[self::ACTION_UPDATE_CHANGE] == 1) { |
94 | | - $results['update_change'] = $updateStatements['change']; |
95 | | - } |
| 58 | + if ($allowedActions[self::ACTION_UPDATE_CHANGE] == 1) { |
| 59 | + $results['update_change'] = $addCreateChange['change']; |
| 60 | + } |
96 | 61 |
|
97 | | - if ($allowedActions[self::ACTION_REMOVE_CHANGE] == 1) { |
98 | | - $results['remove_change'] = $updateStatements['change']; |
99 | | - } |
| 62 | + if ($allowedActions[self::ACTION_UPDATE_CREATE_TABLE] == 1) { |
| 63 | + $results['update_create_table'] = $addCreateChange['create_table']; |
| 64 | + } |
100 | 65 |
|
101 | | - if ($allowedActions[self::ACTION_REMOVE_DROP] == 1) { |
102 | | - $results['drop'] = $updateStatements['drop']; |
103 | | - } |
| 66 | + if ($allowedActions[self::ACTION_REMOVE_CHANGE] == 1) { |
| 67 | + $results['remove_change'] = $dropRemove['change']; |
| 68 | + } |
104 | 69 |
|
105 | | - if ($allowedActions[self::ACTION_UPDATE_CREATE_TABLE] == 1) { |
106 | | - $results['create_table'] = $updateStatements['create_table']; |
107 | | - } |
| 70 | + if ($allowedActions[self::ACTION_REMOVE_DROP] == 1) { |
| 71 | + $results['remove_drop'] = $dropRemove['drop']; |
| 72 | + } |
108 | 73 |
|
109 | | - if ($allowedActions[self::ACTION_REMOVE_CHANGE_TABLE] == 1) { |
110 | | - $results['change_table'] = $updateStatements['change_table']; |
111 | | - } |
| 74 | + if ($allowedActions[self::ACTION_REMOVE_CHANGE_TABLE] == 1) { |
| 75 | + $results['remove_change_table'] = $dropRemove['change_table']; |
| 76 | + } |
112 | 77 |
|
113 | | - if ($allowedActions[self::ACTION_REMOVE_DROP_TABLE] == 1) { |
114 | | - $results['change_table'] = $updateStatements['change_table']; |
115 | | - } |
| 78 | + if ($allowedActions[self::ACTION_REMOVE_DROP_TABLE] == 1) { |
| 79 | + $results['remove_drop_table'] = $dropRemove['drop_table']; |
| 80 | + } |
116 | 81 |
|
117 | | - foreach ($results as $key => $resultSet) { |
118 | | - if (!empty($resultSet)) { |
119 | | - $errors[$key] = $resultSet; |
120 | | - } |
| 82 | + foreach ($results as $key => $resultSet) { |
| 83 | + if (!empty($resultSet)) { |
| 84 | + $errors[$key] = $resultSet; |
121 | 85 | } |
122 | 86 | } |
123 | 87 |
|
|
0 commit comments