[TASK] Re-work/simplify copyright header in PHP files - Part 1
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / RootTemplateUpdate.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 /**
18 * Migrates the old media FlexForm to the new
19 */
20 class RootTemplateUpdate extends AbstractUpdate implements InstallerProcessInterface {
21
22 /**
23 * @var string
24 */
25 protected $title = 'Integrate TypoScript Root Template';
26
27 /**
28 * Checks whether updates need to be performed
29 *
30 * @param string &$description The description for the update
31 * @param integer &$showUpdate 0=dont show update; 1=show update and next button; 2=only show description
32 * @return boolean
33 */
34 public function checkForUpdate(&$description, &$showUpdate = 0) {
35 $pages = $this->findRootLevelPages();
36
37 if ($pages !== NULL && $this->findRootTemplates(array_keys($pages)) !== NULL) {
38 $description = 'There is already at least one TypoScript root template available.';
39 $showUpdate = 0;
40 } else {
41 $description = 'There is no TypoScript root template! However, one is required for Extbase to behave correctly.';
42 $showUpdate = 1;
43 }
44
45 return $showUpdate > 0;
46 }
47
48 /**
49 * Performs updates and creates one page and Typoscript root template.
50 *
51 * @param array &$dbQueries Queries done in this update
52 * @param mixed &$customMessages Custom messages
53 * @return boolean Whether the updated was made or not
54 */
55 public function performUpdate(array &$dbQueries, &$customMessages) {
56 $now = time();
57 $result = FALSE;
58
59 $status = $GLOBALS['TYPO3_DB']->exec_INSERTquery(
60 'pages',
61 array(
62 'pid' => 0,
63 'title' => 'Home',
64 'is_siteroot' => 1,
65 'crdate' => $now,
66 'tstamp' => $now,
67 )
68 );
69
70 $dbQueries[] = str_replace(chr(10), ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);
71
72 if ($status) {
73 $pageId = $GLOBALS['TYPO3_DB']->sql_insert_id();
74
75 $status = $GLOBALS['TYPO3_DB']->exec_INSERTquery(
76 'sys_template',
77 array(
78 'pid' => $pageId,
79 'title' => 'Default Root Template',
80 'root' => 1,
81 'clear' => 1,
82 'crdate' => $now,
83 'tstamp' => $now,
84 )
85 );
86
87 $dbQueries[] = str_replace(chr(10), ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);
88
89 if ($status) {
90 $result = TRUE;
91 }
92 }
93
94 return $result;
95 }
96
97 /**
98 * Finds pages on the root level (pid 0).
99 *
100 * @return array|NULL
101 */
102 protected function findRootLevelPages() {
103 $pages = NULL;
104
105 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
106 'uid,pid',
107 'pages',
108 'pid=0 AND deleted=0',
109 '',
110 '',
111 '',
112 'uid'
113 );
114
115 if (is_array($rows) && !empty($rows)) {
116 $pages = $rows;
117 }
118
119 return $pages;
120 }
121
122 /**
123 * Finds root templates in the given pages.
124 *
125 * @param array $pageUids
126 * @return array|NULL
127 */
128 protected function findRootTemplates(array $pageUids) {
129 $templates = NULL;
130
131 $pageUids = array_map('intval', $pageUids);
132 $pageUidList = implode(', ', $pageUids);
133
134 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
135 'uid,pid',
136 'sys_template',
137 'deleted=0 AND root=1 AND pid IN (' . $pageUidList . ')',
138 '',
139 '',
140 '',
141 'uid'
142 );
143
144 if (is_array($rows)) {
145 $templates = $rows;
146 }
147
148 return $templates;
149 }
150 }