[FEATURE] Add autofocus attribute to BE login
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Service / UpdateDispatcherService.php
1 <?php
2 namespace TYPO3\CMS\Install\Service;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Oliver Hader <oliver.hader@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Dispatches update wizard tasks.
32 *
33 * @author Oliver Hader <oliver.hader@typo3.org>
34 */
35 class UpdateDispatcherService implements \TYPO3\CMS\Core\SingletonInterface {
36 /**
37 * @var \TYPO3\CMS\Install\Installer
38 */
39 protected $installer;
40
41 /**
42 * @param \TYPO3\CMS\Install\Installer $installer
43 */
44 public function __construct(\TYPO3\CMS\Install\Installer $installer) {
45 $this->getDatabase()->store_lastBuiltQuery = TRUE;
46 $this->installer = $installer;
47 }
48
49 /**
50 * Dispatches updates that are also used to initialize TYPO3.
51 *
52 * @return void
53 */
54 public function dispatchInitializeUpdates() {
55 $queries = array();
56 $messages = array();
57
58 foreach ($this->findInitializeUpdates() as $initializeUpdate) {
59 $initializeUpdate->performUpdate($queries, $messages);
60 }
61 }
62
63 /**
64 * Gets class names extending \TYPO3\CMS\Install\Updates\InitializeUpdate
65 *
66 * @return array|\TYPO3\CMS\Install\Updates\AbstractUpdate[]|\TYPO3\CMS\Install\Updates\InstallerProcessInterface[]
67 */
68 protected function findInitializeUpdates() {
69 $initializeUpdates = array();
70
71 foreach ($this->findAllUpdates() as $update) {
72 if ($update instanceof \TYPO3\CMS\Install\Updates\InstallerProcessInterface) {
73 $initializeUpdates[] = $update;
74 }
75 }
76
77 return $initializeUpdates;
78 }
79
80 /**
81 * Gets all registered updates.
82 *
83 * @return array|\TYPO3\CMS\Install\Updates\AbstractUpdate[]
84 */
85 protected function findAllUpdates() {
86 $updates = array();
87
88 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'] as $identifier => $className) {
89 $update = $this->createUpdateObject($identifier, $className);
90
91 if ($update !== NULL) {
92 $updates[] = $update;
93 }
94 }
95
96 return $updates;
97 }
98
99 /**
100 * Creates an update object.
101 *
102 * @param string $identifier
103 * @param string $className
104 * @return \TYPO3\CMS\Install\Updates\AbstractUpdate
105 * @throws \RuntimeException
106 */
107 protected function createUpdateObject($identifier, $className) {
108 $updateObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($className);
109
110 if (!$updateObject instanceof \TYPO3\CMS\Install\Updates\AbstractUpdate) {
111 throw new \RuntimeException(
112 'Update class ' . $className . ' must implement \TYPO3\CMS\Install\Updates\AbstractUpdate',
113 1346336675
114 );
115 }
116
117 /** @var $updateObject \TYPO3\CMS\Install\Updates\AbstractUpdate */
118 $updateObject->setIdentifier($identifier);
119 $updateObject->versionNumber = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version);
120 $updateObject->pObj = $this->installer;
121
122 if (isset($this->installer->INSTALL['update'][$identifier])) {
123 $updateObject->userInput = $this->installer->INSTALL['update'][$identifier];
124 }
125
126 return $updateObject;
127 }
128
129 /**
130 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
131 */
132 protected function getDatabase() {
133 return $GLOBALS['TYPO3_DB'];
134 }
135 }
136
137 ?>