Exemplo n.º 1
0
    /**
     * Constructor
     *
     * @return void
     * @todo Define visibility
     */
    public function __construct()
    {
        parent::__construct();
        if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['installToolPassword']) {
            $this->outputErrorAndExit('Install Tool deactivated.<br />
				You must enable it by setting a password in typo3conf/LocalConfiguration.php. If you insert the value below at array position \'EXT\' \'installToolPassword\', the password will be \'joh316\':<br /><br />
				\'bacb98acf97e0b6112b1d1b650b84971\'', 'Fatal error');
        }
        if ($this->sendNoCacheHeaders) {
            header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
            header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
            header('Expires: 0');
            header('Cache-Control: no-cache, must-revalidate');
            header('Pragma: no-cache');
        }
        // ****************************
        // Initializing incoming vars.
        // ****************************
        $this->INSTALL = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('TYPO3_INSTALL');
        $this->mode = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('mode');
        if ($this->mode !== '123') {
            $this->mode = '';
        }
        if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('step') === 'go') {
            $this->step = 'go';
        } else {
            $this->step = intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('step'));
        }
        // Let DBAL decide whether to load itself
        $dbalLoaderFile = $this->backPath . 'sysext/dbal/class.tx_dbal_autoloader.php';
        if (@is_file($dbalLoaderFile)) {
            include $dbalLoaderFile;
        }
        if ($this->mode === '123') {
            // Check for mandatory PHP modules
            $missingPhpModules = $this->getMissingPhpModules();
            if (count($missingPhpModules) > 0) {
                throw new \RuntimeException('TYPO3 Installation Error: The following PHP module(s) is/are missing: <em>' . implode(', ', $missingPhpModules) . '</em><br /><br />You need to install and enable these modules first to be able to install TYPO3.', 1294587482);
            }
            // Load saltedpasswords if possible
            $saltedpasswordsLoaderFile = $this->backPath . 'sysext/saltedpasswords/classes/class.tx_saltedpasswords_autoloader.php';
            if (@is_file($saltedpasswordsLoaderFile)) {
                include $saltedpasswordsLoaderFile;
            }
        }
        $this->redirect_url = \TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('redirect_url'));
        $this->INSTALL['type'] = '';
        if ($_GET['TYPO3_INSTALL']['type']) {
            $allowedTypes = array('config', 'database', 'update', 'images', 'extConfig', 'cleanup', 'phpinfo', 'typo3conf_edit', 'about', 'logout');
            if (in_array($_GET['TYPO3_INSTALL']['type'], $allowedTypes)) {
                $this->INSTALL['type'] = $_GET['TYPO3_INSTALL']['type'];
            }
        }
        if ($this->step == 4) {
            $this->INSTALL['type'] = 'database';
        }
        // Hook to raise the counter for the total steps in the 1-2-3 installer
        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);
            }
        }
        if ($this->mode == '123') {
            $tempItems = $this->menuitems;
            $this->menuitems = array('config' => $tempItems['config'], 'database' => $tempItems['database']);
            if (!$this->INSTALL['type'] || !isset($this->menuitems[$this->INSTALL['type']])) {
                $this->INSTALL['type'] = 'config';
            }
        } else {
            if (!$this->INSTALL['type'] || !isset($this->menuitems[$this->INSTALL['type']])) {
                $this->INSTALL['type'] = 'about';
            }
        }
        $this->action = $this->scriptSelf . '?TYPO3_INSTALL[type]=' . $this->INSTALL['type'] . ($this->mode ? '&mode=' . $this->mode : '') . ($this->step ? '&step=' . $this->step : '');
        $this->typo3temp_path = PATH_site . 'typo3temp/';
        if (!is_dir($this->typo3temp_path) || !is_writeable($this->typo3temp_path)) {
            $this->outputErrorAndExit('Install Tool needs to write to typo3temp/. Make sure this directory is writeable by your webserver: ' . htmlspecialchars($this->typo3temp_path), 'Fatal error');
        }
        try {
            $this->session = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_install_session');
        } catch (\Exception $exception) {
            $this->outputErrorAndExit($exception->getMessage());
        }
        // *******************
        // Check authorization
        // *******************
        if (!$this->session->hasSession()) {
            $this->session->startSession();
        }
        if ($this->session->isAuthorized() || $this->checkPassword()) {
            $this->passwordOK = 1;
            $this->session->refreshSession();
            $enableInstallToolFile = PATH_typo3conf . 'ENABLE_INSTALL_TOOL';
            if (is_file($enableInstallToolFile)) {
                // Extend the age of the ENABLE_INSTALL_TOOL file by one hour
                @touch($enableInstallToolFile);
            }
            if ($this->redirect_url) {
                \TYPO3\CMS\Core\Utility\HttpUtility::redirect($this->redirect_url);
            }
            $this->formProtection = \t3lib_formProtection_Factory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection');
            $this->formProtection->injectInstallTool($this);
        } else {
            $this->loginForm();
        }
    }
 /**
  * Writes the extension list to "localconf.php" file
  * Removes the temp_CACHED* files before return.
  *
  * @param	string		List of extensions
  * @return	void
  * @deprecated since TYPO3 4.5, will be removed in TYPO3 4.7 - Use Tx_Install_Updates_Base::installExtensions() instead
  */
 protected function writeNewExtensionList($newExtList)
 {
     t3lib_div::logDeprecatedFunction();
     // Instance of install tool
     $instObj = new t3lib_install();
     $instObj->allowUpdateLocalConf = 1;
     $instObj->updateIdentity = 'TYPO3 Core Update Manager';
     // Get lines from localconf file
     $lines = $instObj->writeToLocalconf_control();
     $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList\']', $newExtList);
     $instObj->writeToLocalconf_control($lines);
     $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = $newExtList;
     t3lib_extMgm::removeCacheFiles();
 }
 /**
  * Gets the table and field structure from database.
  * Which fields and which tables are determined from the ext_tables.sql file
  *
  * @param	string		Array with table.field values
  * @return	array		Array of tables and fields splitted.
  */
 function getTableAndFieldStructure($parts)
 {
     // Instance of install tool
     $instObj = new t3lib_install();
     $dbFields = $instObj->getFieldDefinitions_database(TYPO3_db);
     $outTables = array();
     foreach ($parts as $table) {
         $sub = explode('.', $table);
         if ($sub[0] && isset($dbFields[$sub[0]])) {
             if ($sub[1]) {
                 $key = explode('KEY:', $sub[1], 2);
                 if (count($key) == 2 && !$key[0]) {
                     // key:
                     if (isset($dbFields[$sub[0]]['keys'][$key[1]])) {
                         $outTables[$sub[0]]['keys'][$key[1]] = $dbFields[$sub[0]]['keys'][$key[1]];
                     }
                 } else {
                     if (isset($dbFields[$sub[0]]['fields'][$sub[1]])) {
                         $outTables[$sub[0]]['fields'][$sub[1]] = $dbFields[$sub[0]]['fields'][$sub[1]];
                     }
                 }
             } else {
                 $outTables[$sub[0]] = $dbFields[$sub[0]];
             }
         }
     }
     return $outTables;
 }
Exemplo n.º 4
0
 /**
  * Caches the field information.
  *
  * @return void
  */
 public function cacheFieldInfo()
 {
     $extSQL = '';
     $parsedExtSQL = array();
     // try to fetch cached file first
     // file is removed when admin_query() is called
     if (file_exists(PATH_typo3conf . 'temp_fieldInfo.php')) {
         $fdata = unserialize(t3lib_div::getUrl(PATH_typo3conf . 'temp_fieldInfo.php'));
         $this->cache_autoIncFields = $fdata['incFields'];
         $this->cache_fieldType = $fdata['fieldTypes'];
         $this->cache_primaryKeys = $fdata['primaryKeys'];
     } else {
         // handle stddb.sql, parse and analyze
         $extSQL = t3lib_div::getUrl(PATH_site . 't3lib/stddb/tables.sql');
         $parsedExtSQL = $this->Installer->getFieldDefinitions_fileContent($extSQL);
         $this->analyzeFields($parsedExtSQL);
         // loop over all installed extensions
         foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $ext => $v) {
             if (!is_array($v) || !isset($v['ext_tables.sql'])) {
                 continue;
             }
             // fetch db dump (if any) and parse it, then analyze
             $extSQL = t3lib_div::getUrl($v['ext_tables.sql']);
             $parsedExtSQL = $this->Installer->getFieldDefinitions_fileContent($extSQL);
             $this->analyzeFields($parsedExtSQL);
         }
         $cachedFieldInfo = array('incFields' => $this->cache_autoIncFields, 'fieldTypes' => $this->cache_fieldType, 'primaryKeys' => $this->cache_primaryKeys);
         $cachedFieldInfo = serialize($this->mapCachedFieldInfo($cachedFieldInfo));
         // write serialized content to file
         t3lib_div::writeFile(PATH_typo3conf . 'temp_fieldInfo.php', $cachedFieldInfo);
         if (strcmp(t3lib_div::getUrl(PATH_typo3conf . 'temp_fieldInfo.php'), $cachedFieldInfo)) {
             die('typo3conf/temp_fieldInfo.php was NOT updated properly (written content didn\'t match file content) - maybe write access problem?');
         }
     }
 }
 /**
  * Updates the database according to extension requirements
  * DBAL compliant (based on Install Tool code)
  *
  * @param	string		Extension key
  * @param	array		Extension information array
  * @return	void
  */
 function forceDBupdates($extKey, $extInfo)
 {
     $instObj = new t3lib_install();
     // Updating tables and fields?
     if (is_array($extInfo['files']) && in_array('ext_tables.sql', $extInfo['files'])) {
         $fileContent = t3lib_div::getUrl(tx_em_Tools::getExtPath($extKey, $extInfo['type']) . 'ext_tables.sql');
         $FDfile = $instObj->getFieldDefinitions_fileContent($fileContent);
         if (count($FDfile)) {
             $FDdb = $instObj->getFieldDefinitions_database(TYPO3_db);
             $diff = $instObj->getDatabaseExtra($FDfile, $FDdb);
             $update_statements = $instObj->getUpdateSuggestions($diff);
             foreach ((array) $update_statements['add'] as $string) {
                 $GLOBALS['TYPO3_DB']->admin_query($string);
             }
             foreach ((array) $update_statements['change'] as $string) {
                 $GLOBALS['TYPO3_DB']->admin_query($string);
             }
             foreach ((array) $update_statements['create_table'] as $string) {
                 $GLOBALS['TYPO3_DB']->admin_query($string);
             }
         }
     }
     // Importing static tables?
     if (is_array($extInfo['files']) && in_array('ext_tables_static+adt.sql', $extInfo['files'])) {
         $fileContent = t3lib_div::getUrl(tx_em_Tools::getExtPath($extKey, $extInfo['type']) . 'ext_tables_static+adt.sql');
         $statements = $instObj->getStatementarray($fileContent, 1);
         list($statements_table, $insertCount) = $instObj->getCreateTables($statements, 1);
         // Traverse the tables
         foreach ($statements_table as $table => $query) {
             $GLOBALS['TYPO3_DB']->admin_query('DROP TABLE IF EXISTS ' . $table);
             $GLOBALS['TYPO3_DB']->admin_query($query);
             if ($insertCount[$table]) {
                 $statements_insert = $instObj->getTableInsertStatements($statements, $table);
                 foreach ($statements_insert as $v) {
                     $GLOBALS['TYPO3_DB']->admin_query($v);
                 }
             }
         }
     }
 }
 /**
  * Write back configuration
  *
  * @param array $extConf
  * @return void
  */
 protected function writeExtConf($extConf)
 {
     $install = new t3lib_install();
     $install->allowUpdateLocalConf = 1;
     $install->updateIdentity = 'Caretaker Instance installation';
     $lines = $install->writeToLocalconf_control();
     $install->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extConf\'][\'caretaker_instance\']', serialize($extConf));
     $install->writeToLocalconf_control($lines);
     t3lib_extMgm::removeCacheFiles();
 }
Exemplo n.º 7
0
 /**
  * Updates the mapping in localconf.php according to form input values.
  *
  * @param array $data
  * @param t3lib_install $instObj
  * @return void
  * @api
  */
 public function updateMapping(array $data, t3lib_install $instObj)
 {
     $newMapping = $this->mapping;
     foreach ($data['tables'] as $table => $newName) {
         $newName = trim($newName);
         if ($newName && $newName !== $table) {
             if (!isset($newMapping[$table])) {
                 $newMapping[$table] = array();
             }
             $newMapping[$table]['mapTableName'] = $newName;
         }
         if (isset($data['fields'][$table])) {
             foreach ($data['fields'][$table] as $field => $newName) {
                 $newName = trim($newName);
                 if ($newName && $newName !== $field) {
                     if (!isset($newMapping[$table])) {
                         $newMapping[$table] = array();
                     }
                     if (!isset($newMapping[$table]['mapFieldNames'])) {
                         $newMapping[$table]['mapFieldNames'] = array();
                     }
                     $newMapping[$table]['mapFieldNames'][$field] = $newName;
                 }
             }
         }
     }
     // Sort table and field names
     foreach ($newMapping as $table => &$config) {
         if (isset($config['mapFieldNames'])) {
             ksort($config['mapFieldNames']);
         }
     }
     ksort($newMapping);
     // Write new mapping to localconf.php
     $key = '$TYPO3_CONF_VARS[\'EXTCONF\'][\'dbal\'][\'mapping\']';
     $instObj->allowUpdateLocalConf = 1;
     $instObj->updateIdentity = 'TYPO3 Extension Manager';
     $lines = $instObj->writeToLocalconf_control();
     $instObj->setArrayValueInLocalconfFile($lines, $key, $newMapping);
     if ($instObj->writeToLocalconf($lines)) {
         $this->mapping = $newMapping;
     }
 }
 /**
  * Writes or returns lines from localconf.php
  *
  * @param array $lines Array of lines to write back to localconf.php. Possibly
  * @param boolean $showOutput If TRUE then print what has been done.
  * @return mixed If $lines is not an array it will return an array with the lines from localconf.php. Otherwise it will return a status string, either "continue" (updated) or "nochange" (not updated)
  * @see parent::writeToLocalconf_control()
  */
 function writeToLocalconf_control($lines = '', $showOutput = TRUE)
 {
     // Get the template file
     $templateFile = @file_get_contents(PATH_site . $this->templateFilePath . 'WriteToLocalConfControl.html');
     $returnVal = parent::writeToLocalconf_control($lines);
     if ($showOutput) {
         switch ($returnVal) {
             case 'continue':
                 // Get the template part from the file
                 $template = t3lib_parsehtml::getSubpart($templateFile, '###CONTINUE###');
                 // Get the subpart for messages
                 $messagesSubPart = t3lib_parsehtml::getSubpart($template, '###MESSAGES###');
                 $messages = array();
                 foreach ($this->messages as $message) {
                     // Define the markers content
                     $messagesMarkers['message'] = $message;
                     // Fill the markers in the subpart
                     $messages[] = t3lib_parsehtml::substituteMarkerArray($messagesSubPart, $messagesMarkers, '###|###', TRUE, FALSE);
                 }
                 // Substitute the subpart for messages
                 $content = t3lib_parsehtml::substituteSubpart($template, '###MESSAGES###', implode(chr(10), $messages));
                 // Define the markers content
                 $markers = array('header' => 'Writing to \'localconf.php\'', 'action' => $this->action, 'label' => 'Click to continue...');
                 // Fill the markers
                 $content = t3lib_parsehtml::substituteMarkerArray($content, $markers, '###|###', TRUE, FALSE);
                 $this->outputExitBasedOnStep($content);
                 break;
             case 'nochange':
                 // Get the template part from the file
                 $template = t3lib_parsehtml::getSubpart($templateFile, '###NOCHANGE###');
                 // Define the markers content
                 $markers = array('header' => 'Writing to \'localconf.php\'', 'message' => 'No values were changed, so nothing is updated!', 'action' => $this->action, 'label' => 'Click to continue...');
                 // Fill the markers
                 $content = t3lib_parsehtml::substituteMarkerArray($template, $markers, '###|###', TRUE, FALSE);
                 $this->outputExitBasedOnStep($content);
                 break;
         }
     }
     return $returnVal;
 }