[TASK] Get rid of ObjectManager in install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / AbstractDatabaseSchemaUpdate.php
1 <?php
2 namespace TYPO3\CMS\Install\Updates;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Install\Service\SqlExpectedSchemaService;
19 use TYPO3\CMS\Install\Service\SqlSchemaMigrationService;
20
21 /**
22 * Contains the update class to create and alter tables, fields and keys to comply to the database schema
23 */
24 abstract class AbstractDatabaseSchemaUpdate extends AbstractUpdate
25 {
26 /**
27 * @var string
28 */
29 protected $title;
30
31 /**
32 * @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService
33 */
34 protected $schemaMigrationService;
35
36 /**
37 * @var \TYPO3\CMS\Install\Service\SqlExpectedSchemaService
38 */
39 protected $expectedSchemaService;
40
41 /**
42 * Constructor function.
43 */
44 public function __construct(SqlSchemaMigrationService $schemaMigrationService = null, SqlExpectedSchemaService $expectedSchemaService = null)
45 {
46 $this->schemaMigrationService = $schemaMigrationService ?: GeneralUtility::makeInstance(SqlSchemaMigrationService::class);
47 $this->expectedSchemaService = $expectedSchemaService ?: GeneralUtility::makeInstance(SqlExpectedSchemaService::class);
48 }
49
50 /**
51 * Compare current and expected database schemas and return the database differences
52 *
53 * @return array database differences
54 */
55 protected function getDatabaseDifferences()
56 {
57 $expectedSchema = $this->expectedSchemaService->getExpectedDatabaseSchema();
58 $currentSchema = $this->schemaMigrationService->getFieldDefinitions_database();
59
60 // Difference from expected to current
61 return $this->schemaMigrationService->getDatabaseExtra($expectedSchema, $currentSchema);
62 }
63 }