[BUGFIX] Upgrade wizard to fill default EM repository
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / CoreUpdates / ExtensionManagerRepositories.php
1 <?php
2 namespace TYPO3\CMS\Install\CoreUpdates;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Georg Ringer <typo3@ringerge.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 * Contains the update class for filling the basic repository record of the extension manager
31 *
32 * @author Georg Ringer <typo3@ringerge.org>
33 */
34 class ExtensionManagerRepositories extends \TYPO3\CMS\Install\Updates\AbstractUpdate {
35
36 protected $title = 'Add the default extension manager repository';
37
38 /**
39 * Checks if an update is needed
40 *
41 * @param string &$description: The description for the update
42 * @return boolean Whether an update is needed (TRUE) or not (FALSE)
43 */
44 public function checkForUpdate(&$description) {
45 $result = FALSE;
46 $description = 'Add the default extension manager repository to the database.';
47
48 $databaseTables = $GLOBALS['TYPO3_DB']->admin_get_tables();
49 if (!isset($databaseTables['tx_extensionmanager_domain_model_repository'])) {
50 $result = TRUE;
51 } else {
52 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'tx_extensionmanager_domain_model_repository');
53 if ($count === 0) {
54 $result = TRUE;
55 }
56 }
57 return $result;
58 }
59
60 /**
61 * Performs the database update.
62 *
63 * @param array &$dbQueries: queries done in this update
64 * @param mixed &$customMessages: custom messages
65 * @return boolean Whether it worked (TRUE) or not (FALSE)
66 */
67 public function performUpdate(array &$dbQueries, &$customMessages) {
68 $result = FALSE;
69 $sqlFile = \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('extensionmanager') . DIRECTORY_SEPARATOR . 'ext_tables_static+adt.sql';
70 $sqlStatements = explode(';', \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($sqlFile));
71
72 foreach ($sqlStatements as $sqlStatement) {
73 if (trim($sqlStatement) !== '') {
74 $res = $GLOBALS['TYPO3_DB']->sql_query($sqlStatement);
75 $dbQueries[] = $sqlStatement;
76 if ($GLOBALS['TYPO3_DB']->sql_error()) {
77 $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error());
78 } else {
79 $result = TRUE;
80 }
81 }
82 }
83 return $result;
84 }
85
86 }
87
88 ?>