[TASK] Create default TypoScript root template
authorOliver Hader <oliver@typo3.org>
Thu, 30 Aug 2012 14:59:36 +0000 (16:59 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 30 Aug 2012 18:46:25 +0000 (20:46 +0200)
One drawback of Extbase in the backend disposal is that it
requires frontend TypoScript to determine several required
settings. Since blank TYPO3 instances do not contain any
TypoScript by default - backend modules built on Extbase
will just fail.

The solution is to create a default page and TypoScript
template on installing a blank TYPO3 site.

Change-Id: I4fe5ffcad51bb07561d417202be577ee1bdd832a
Resolves: #40428
Releases: 6.0
Reviewed-on: http://review.typo3.org/14218
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/install/Classes/CoreUpdates/RootTemplateUpdate.php [new file with mode: 0644]
typo3/sysext/install/Classes/Installer.php
typo3/sysext/install/Classes/Service/UpdateDispatcherService.php [new file with mode: 0644]
typo3/sysext/install/Classes/Updates/InstallerProcessInterface.php [new file with mode: 0644]
typo3/sysext/install/ext_localconf.php

diff --git a/typo3/sysext/install/Classes/CoreUpdates/RootTemplateUpdate.php b/typo3/sysext/install/Classes/CoreUpdates/RootTemplateUpdate.php
new file mode 100644 (file)
index 0000000..d9876d3
--- /dev/null
@@ -0,0 +1,161 @@
+<?php
+namespace TYPO3\CMS\Install\CoreUpdates;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Oliver Hader <oliver.hader@typo3.org>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * Migrates the old media FlexForm to the new
+ */
+class RootTemplateUpdate extends \TYPO3\CMS\Install\Updates\AbstractUpdate implements \TYPO3\CMS\Install\Updates\InstallerProcessInterface {
+       protected $title = 'Integrate TypoScript Root Template';
+
+       /**
+        * Checks whether updates need to be performed
+        *
+        * @param string &$description The description for the update
+        * @param integer &$showUpdate 0=dont show update; 1=show update and next button; 2=only show description
+        * @return boolean
+        */
+       public function checkForUpdate(&$description, &$showUpdate = 0) {
+               $pages = $this->findRootLevelPages();
+
+               if ($pages !== NULL && $this->findRootTemplates(array_keys($pages)) !== NULL) {
+                       $description = 'There is already at least one TypoScript root template available.';
+                       $showUpdate = 0;
+               } else {
+                       $description = 'There is no TypoScript root template! However, one is required for Extbase to behave correctly.';
+                       $showUpdate = 1;
+               }
+
+               return $showUpdate > 0;
+       }
+
+       /**
+        * Performs updates and creates one page and Typoscript root template.
+        *
+        * @param       array           &$dbQueries: queries done in this update
+        * @param       mixed           &$customMessages: custom messages
+        * @return      boolean         whether the updated was made or not
+        */
+       public function performUpdate(array &$dbQueries, &$customMessages) {
+               $now = time();
+               $result = FALSE;
+
+               $status = $GLOBALS['TYPO3_DB']->exec_INSERTquery(
+                       'pages',
+                       array(
+                               'pid' => 0,
+                               'title' => 'Home',
+                               'is_siteroot' => 1,
+                               'crdate' => $now,
+                               'tstamp' => $now,
+                       )
+               );
+
+               $dbQueries[] = str_replace(chr(10), ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);
+
+               if ($status) {
+                       $pageId = $GLOBALS['TYPO3_DB']->sql_insert_id();
+
+                       $status = $GLOBALS['TYPO3_DB']->exec_INSERTquery(
+                               'sys_template',
+                               array(
+                                       'pid' => $pageId,
+                                       'title' => 'Default Root Template',
+                                       'root' => 1,
+                                       'clear' => 1,
+                                       'crdate' => $now,
+                                       'tstamp' => $now,
+                               )
+                       );
+
+                       $dbQueries[] = str_replace(chr(10), ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);
+
+                       if ($status) {
+                               $result = TRUE;
+                       }
+               }
+
+               return $result;
+       }
+
+       /**
+        * Finds pages on the root level (pid 0).
+        *
+        * @return array|NULL
+        */
+       protected function findRootLevelPages() {
+               $pages = NULL;
+
+               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                       'uid,pid',
+                       'pages',
+                       'pid=0 AND deleted=0',
+                       '',
+                       '',
+                       '',
+                       'uid'
+               );
+
+               if (is_array($rows)) {
+                       $pages = $rows;
+               }
+
+               return $pages;
+       }
+
+       /**
+        * Finds root templates in the given pages.
+        *
+        * @param array $pageUids
+        * @return array|NULL
+        */
+       protected function findRootTemplates(array $pageUids) {
+               $templates = NULL;
+
+               $pageUids = array_map('intval', $pageUids);
+               $pageUidList = implode(', ', $pageUids);
+
+               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                       'uid,pid',
+                       'sys_template',
+                       'deleted=0 AND root=1 AND pid IN (' . $pageUidList . ')',
+                       '',
+                       '',
+                       '',
+                       'uid'
+               );
+
+               if (is_array($rows)) {
+                       $templates = $rows;
+               }
+
+               return $templates;
+       }
+}
+
+
+?>
\ No newline at end of file
index 0f67490..427e8c4 100644 (file)
@@ -126,6 +126,11 @@ class Installer extends \t3lib_install {
         */
        public $totalSteps = 4;
 
+       /**
+        * @var boolean
+        */
+       protected $hasAdditionalSteps = FALSE;
+
        // Can be changed by hook to define the total steps in 123 mode
        // internal
        /**
@@ -304,7 +309,13 @@ class Installer extends \t3lib_install {
                if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['additionalSteps'])) {
                        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['additionalSteps'] as $classData) {
                                $hookObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classData);
-                               $this->totalSteps += (int) $hookObject->executeAdditionalSteps($this);
+                               $additionalSteps = (int) $hookObject->executeAdditionalSteps($this);
+
+                               if ($additionalSteps > 0) {
+                                       $this->hasAdditionalSteps = TRUE;
+                               }
+
+                               $this->totalSteps += $additionalSteps;
                        }
                }
                if ($this->mode == '123') {
@@ -5120,7 +5131,12 @@ REMOTE_ADDR was \'') . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOT
                                                                );
                                                                $GLOBALS['TYPO3_DB']->exec_INSERTquery('be_users', $insertFields);
                                                        }
+
+                                                       if (!$this->hasAdditionalSteps) {
+                                                               $this->dispatchInitializeUpdates();
+                                                       }
                                                }
+
                                                $this->message($tLabel, 'Imported ALL', ('
                                                                <p>
                                                                        Queries: ' . $r) . '
@@ -5503,6 +5519,18 @@ REMOTE_ADDR was \'') . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOT
        }
 
        /**
+        * Dispatches updates that shall be executed
+        * during initialization of a fresh TYPO3 instance.
+        *
+        * @return void
+        */
+       public function dispatchInitializeUpdates() {
+               /** @var $dispatcher \TYPO3\CMS\Install\Service\UpdateDispatcherService */
+               $dispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Install\Service\UpdateDispatcherService', $this);
+               $dispatcher->dispatchInitializeUpdates();
+       }
+
+       /**
         * Generates update wizard
         *
         * @return void
diff --git a/typo3/sysext/install/Classes/Service/UpdateDispatcherService.php b/typo3/sysext/install/Classes/Service/UpdateDispatcherService.php
new file mode 100644 (file)
index 0000000..bdef881
--- /dev/null
@@ -0,0 +1,137 @@
+<?php
+namespace TYPO3\CMS\Install\Service;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Oliver Hader <oliver.hader@typo3.org>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Dispatches update wizard tasks.
+ *
+ * @author Oliver Hader <oliver.hader@typo3.org>
+ */
+class UpdateDispatcherService implements \TYPO3\CMS\Core\SingletonInterface {
+       /**
+        * @var \TYPO3\CMS\Install\Installer
+        */
+       protected $installer;
+
+       /**
+        * @param \TYPO3\CMS\Install\Installer $installer
+        */
+       public function __construct(\TYPO3\CMS\Install\Installer $installer) {
+               $this->getDatabase()->store_lastBuiltQuery = TRUE;
+               $this->installer = $installer;
+       }
+
+       /**
+        * Dispatches updates that are also used to initialize TYPO3.
+        *
+        * @return void
+        */
+       public function dispatchInitializeUpdates() {
+               $queries = array();
+               $messages = array();
+
+               foreach ($this->findInitializeUpdates() as $initializeUpdate) {
+                       $initializeUpdate->performUpdate($queries, $messages);
+               }
+       }
+
+       /**
+        * Gets class names extending \TYPO3\CMS\Install\Updates\InitializeUpdate
+        *
+        * @return array|\TYPO3\CMS\Install\Updates\AbstractUpdate[]|\TYPO3\CMS\Install\Updates\InstallerProcessInterface[]
+        */
+       protected function findInitializeUpdates() {
+               $initializeUpdates = array();
+
+               foreach ($this->findAllUpdates() as $update) {
+                       if ($update instanceof \TYPO3\CMS\Install\Updates\InstallerProcessInterface) {
+                               $initializeUpdates[] = $update;
+                       }
+               }
+
+               return $initializeUpdates;
+       }
+
+       /**
+        * Gets all registered updates.
+        *
+        * @return array|\TYPO3\CMS\Install\Updates\AbstractUpdate[]
+        */
+       protected function findAllUpdates() {
+               $updates = array();
+
+               foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'] as $identifier => $className) {
+                       $update = $this->createUpdateObject($identifier, $className);
+
+                       if ($update !== NULL) {
+                               $updates[] = $update;
+                       }
+               }
+
+               return $updates;
+       }
+
+       /**
+        * Creates an update object.
+        *
+        * @param string $identifier
+        * @param string $className
+        * @return \TYPO3\CMS\Install\Updates\AbstractUpdate
+        * @throws \RuntimeException
+        */
+       protected function createUpdateObject($identifier, $className) {
+               $updateObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($className);
+
+               if (!$updateObject instanceof \TYPO3\CMS\Install\Updates\AbstractUpdate) {
+                       throw new \RuntimeException(
+                               'Update class ' . $className . ' must implement \TYPO3\CMS\Install\Updates\AbstractUpdate',
+                               1346336675
+                       );
+               }
+
+               /** @var $updateObject \TYPO3\CMS\Install\Updates\AbstractUpdate */
+               $updateObject->setIdentifier($identifier);
+               $updateObject->versionNumber = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version);
+               $updateObject->pObj = $this->installer;
+
+               if (isset($this->installer->INSTALL['update'][$identifier])) {
+                       $updateObject->userInput = $this->installer->INSTALL['update'][$identifier];
+               }
+
+               return $updateObject;
+       }
+
+       /**
+        * @return \TYPO3\CMS\Core\Database\DatabaseConnection
+        */
+       protected function getDatabase() {
+               return $GLOBALS['TYPO3_DB'];
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/install/Classes/Updates/InstallerProcessInterface.php b/typo3/sysext/install/Classes/Updates/InstallerProcessInterface.php
new file mode 100644 (file)
index 0000000..c92aa85
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+namespace TYPO3\CMS\Install\Updates;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2012 Oliver Hader <oliver.hader@typo3.org>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ * A copy is found in the textfile GPL.txt and important notices to the license
+ * from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Interface to tell that updates shall be executed
+ * on initializing a new TYPO3 instance.
+ *
+ * @author Oliver Hader <oliver.hader@typo3.org>
+ * @package TYPO3
+ * @subpackage install
+ */
+interface InstallerProcessInterface {
+
+}
+
+?>
\ No newline at end of file
index 721d61c..dc0c27e 100644 (file)
@@ -4,6 +4,8 @@ if (!defined('TYPO3_MODE')) {
 }
 // TYPO3 6.0 - Update localconf.php to LocalConfiguration.php
 $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['localConfiguration'] = 'tx_coreupdates_localconfiguration';
+// TYPO3 6.0 - Create page and TypoScript root template (automatically executed in 123-mode)
+$TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['rootTemplate'] = 'TYPO3\CMS\Install\CoreUpdates\RootTemplateUpdate';
 // TYPO3 4.5 - Check the database to be utf-8 compliant
 $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['charsetDefaults'] = 'tx_coreupdates_charsetdefaults';
 $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['changeCompatibilityVersion'] = 'TYPO3\\CMS\\Install\\CoreUpdates\\CompatVersionUpdate';