[TASK] Migrate form upgrade wizard to new API
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / ReferenceIndexUpdatedPrerequisite.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\Core\Database\ReferenceIndex;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * ReferenceIndex Prerequisite
25 *
26 * Defines that the reference index needs to be up-to-date before an upgrade wizard may be run
27 *
28 * @internal
29 */
30 class ReferenceIndexUpdatedPrerequisite implements PrerequisiteInterface, ChattyInterface
31 {
32 /**
33 * @var object|\TYPO3\CMS\Core\Database\ReferenceIndex
34 */
35 private $referenceIndex;
36 /**
37 * @var \Symfony\Component\Console\Output\OutputInterface
38 */
39 protected $output;
40
41 /**
42 * ReferenceIndexUpdatedPrerequisite constructor
43 */
44 public function __construct()
45 {
46 $this->referenceIndex = GeneralUtility::makeInstance(ReferenceIndex::class);
47 }
48
49 /**
50 * @inheritdoc
51 */
52 public function getTitle(): string
53 {
54 return 'Reference Index Up-to-Date';
55 }
56
57 /**
58 * Updates the reference index
59 *
60 * @return bool
61 */
62 public function ensure(): bool
63 {
64 $this->referenceIndex->enableRuntimeCache();
65 ob_clean();
66 ob_start();
67 $result = $this->referenceIndex->updateIndex(false, true);
68 $output = ob_get_clean();
69 $this->output->write($output);
70 return $result[2] === 0;
71 }
72
73 /**
74 * Checks whether there are reference index updates to be done
75 *
76 * @return bool
77 */
78 public function isFulfilled(): bool
79 {
80 $this->referenceIndex->enableRuntimeCache();
81 $result = $this->referenceIndex->updateIndex(true, false);
82 return $result[2] === 0;
83 }
84
85 /**
86 * @param \Symfony\Component\Console\Output\OutputInterface $output
87 */
88 public function setOutput(OutputInterface $output): void
89 {
90 $this->output = $output;
91 }
92 }