[BUGFIX] Suffix all interfaces with Interface
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / DatabaseUpdatedPrerequisite.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Install\Updates;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use Symfony\Component\Console\Output\OutputInterface;
20 use TYPO3\CMS\Install\Service\UpgradeWizardsService;
21
22 /**
23 * Prerequisite for upgrade wizards to ensure the database is up-to-date
24 *
25 * @internal
26 */
27 class DatabaseUpdatedPrerequisite implements PrerequisiteInterface, ChattyInterface
28 {
29 /**
30 * @var UpgradeWizardsService
31 */
32 protected $upgradeWizardsService;
33 /**
34 * @var \Symfony\Component\Console\Output\OutputInterface
35 */
36 protected $output;
37
38 public function __construct()
39 {
40 $this->upgradeWizardsService = new UpgradeWizardsService();
41 }
42
43 /**
44 * @return string
45 */
46 public function getTitle(): string
47 {
48 return 'Database Up-to-Date';
49 }
50
51 /**
52 */
53 public function ensure(): bool
54 {
55 $adds = $this->upgradeWizardsService->getBlockingDatabaseAdds();
56 $result = null;
57 if (count($adds) > 0) {
58 $this->output->writeln('Performing ' . count($adds) . ' database operations.');
59 $result = $this->upgradeWizardsService->addMissingTablesAndFields();
60 }
61 return $result === null;
62 }
63
64 /**
65 * @return bool
66 */
67 public function isFulfilled(): bool
68 {
69 $adds = $this->upgradeWizardsService->getBlockingDatabaseAdds();
70 return count($adds) === 0;
71 }
72
73 /**
74 * @param \Symfony\Component\Console\Output\OutputInterface $output
75 */
76 public function setOutput(OutputInterface $output): void
77 {
78 $this->output = $output;
79 }
80 }