* Added support for listing and calling methods in new installer
authorThomas Hempel <thomas.hempel@typo3.org>
Tue, 11 Dec 2007 17:28:42 +0000 (17:28 +0000)
committerThomas Hempel <thomas.hempel@typo3.org>
Tue, 11 Dec 2007 17:28:42 +0000 (17:28 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2822 709f56b5-9817-0410-a4d7-c38de5d9e867

typo3/sysext/install/mod/class.tx_install.php
typo3/sysext/install/mod/locallang_mod.xml
typo3/sysext/install/mod/scripts.js
typo3/sysext/install/modules/database/class.tx_install_module_database.php
typo3/sysext/install/modules/database/conf.php
typo3/sysext/install/modules/database/locallang.xml
typo3/sysext/install/modules/setup/class.tx_install_module_setup.php

index cbc1a68..5449c39 100644 (file)
@@ -176,11 +176,14 @@ class tx_install {
                        die();
                }       
                
                        die();
                }       
                
-               if($this->env['mode'] == '123') {
-                       $this->env['module'] = 'installer';
-                       $this->passwordOK = true;
-               } else {
-                       $this->env['module'] = $this->defaults['module'];
+                       // set some default module if nothing was set
+               if (empty($this->env['module']))        {
+                       if($this->env['mode'] == '123') {
+                               $this->env['module'] = 'installer';
+                               $this->passwordOK = true;
+                       } else {
+                               $this->env['module'] = $this->defaults['module'];
+                       }
                }
                        
                        // load localconf file
                }
                        
                        // load localconf file
@@ -188,10 +191,13 @@ class tx_install {
                
                        // do the login if mode is not 123
                if($this->env['mode'] != '123') {
                
                        // do the login if mode is not 123
                if($this->env['mode'] != '123') {
+                       $this->passwordOK = false;
+                       
                        $randomKey = $_COOKIE[$this->cookieName.'_key'];
                        if(!$randomKey) {
                                $randomKey = md5(uniqid(microtime()));
                                setcookie($this->cookieName.'_key', $randomKey, 0, '/');                // Cookie is set
                        $randomKey = $_COOKIE[$this->cookieName.'_key'];
                        if(!$randomKey) {
                                $randomKey = md5(uniqid(microtime()));
                                setcookie($this->cookieName.'_key', $randomKey, 0, '/');                // Cookie is set
+
                                        // add a message that pops up in a JavaScript alert
                                $this->viewObj->addJSmessage($this->basicsObj->getLabel('msg_setup_firstcall'));
                        }
                                        // add a message that pops up in a JavaScript alert
                                $this->viewObj->addJSmessage($this->basicsObj->getLabel('msg_setup_firstcall'));
                        }
@@ -212,11 +218,19 @@ class tx_install {
                                $method = $this->env['method'];
                        }
                        
                                $method = $this->env['method'];
                        }
                        
+                               // execute given method and save the result in a local variable
                        $moduleContent = $this->basicsObj->executeMethod(array($this->env['module'], $method));
                
                        $moduleContent = $this->basicsObj->executeMethod(array($this->env['module'], $method));
                
+                               // check if we have to handle the module content with AJAX
                        if ($this->env['ajax'] == 1)    {
                                header('X-JSON: (true)');
                                header('Content-type: text/html; charset=utf-8');
                        if ($this->env['ajax'] == 1)    {
                                header('X-JSON: (true)');
                                header('Content-type: text/html; charset=utf-8');
+                               
+                                       // render errors if module returned FALSE
+                               if ($moduleContent == false)    {
+                                       $moduleContent = $this->viewObj->renderErrors();
+                               }
+                               
                                echo $moduleContent;
                        } else {
                                if($moduleContent === false) {
                                echo $moduleContent;
                        } else {
                                if($moduleContent === false) {
@@ -246,7 +260,7 @@ class tx_install {
         * @return      boolean true if submitted password is ok, false otherwise
         */
        private function checkPassword($randomKey) {
         * @return      boolean true if submitted password is ok, false otherwise
         */
        private function checkPassword($randomKey) {
-               $password     = t3lib_div::_GP('password');
+               $password     = t3lib_div::_GP('typo3_install_password');
                $warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
                $passwordOk   = false;
                
                $warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
                $passwordOk   = false;
                
@@ -319,7 +333,7 @@ class tx_install {
                                                        'label'       => 'label_setup_password',
                                                        'elementType' => 'password',
                                                        'options'     => array(
                                                        'label'       => 'label_setup_password',
                                                        'elementType' => 'password',
                                                        'options'     => array(
-                                                               'name' => 'password'
+                                                               'name' => 'typo3_install_password'
                                                        )
                                                )
                                        ),
                                                        )
                                                )
                                        ),
index eb268c9..4cff213 100755 (executable)
@@ -71,6 +71,7 @@ REMOTE_ADDR was "%s" (%s)</label>
 
                        <label index="label_subcategory_connection">Connection</label>
                        <label index="label_subcategory_cleanup">Clean Up</label>
 
                        <label index="label_subcategory_connection">Connection</label>
                        <label index="label_subcategory_cleanup">Clean Up</label>
+                       <label index="label_subcategory_analyze">Analyze</label>
                        <label index="label_subcategory_php">PHP</label>
                        <label index="label_subcategory_directories">Directories</label>
                        <label index="label_subcategory_backend">Backend</label>
                        <label index="label_subcategory_php">PHP</label>
                        <label index="label_subcategory_directories">Directories</label>
                        <label index="label_subcategory_backend">Backend</label>
index 35db469..beccc6b 100644 (file)
@@ -161,6 +161,15 @@ function executeMethod(module, method, extraParameters, callBack)  {
        });
 }
 
        });
 }
 
+function displayMethodResult(data)     {
+       console.debug(data);
+       if (data.request.parameters.target)     {
+               $(data.request.parameters.target).innerHTML = data.responseText;
+       } else {
+               alert(data.responseText);
+       }
+}
+
 allOpen = false;
 
        // add event observers
 allOpen = false;
 
        // add event observers
index 40d55e3..9ba578f 100755 (executable)
@@ -433,6 +433,132 @@ class tx_install_module_database extends tx_install_module_base   {
 
                return true;
        }
 
                return true;
        }
+       
+       /**
+        * Compares the current database with a given SQL file. If the argument is null it uses the
+        * default file t3lib/stddb/tables.sql.
+        *
+        * @param       string  $sqlFile: The file that is used for comparision; NULL for default file
+        * @return      HTML-Code or false if an error occured
+        */
+       public function analyzeCompareFile($sqlFile = NULL)     {
+               if (is_null($sqlFile))  {
+                       $sqlFile = PATH_t3lib.'stddb/tables.sql';
+               }
+               
+               $tblFileContent = t3lib_div::getUrl($sqlFile);
+               
+                       // return an error if the given file was not found
+               if (!$tblFileContent)   {
+                       $this->addError(sprintf($this->get_LL('msg_database_error_filenotfound'), $sqlFile), FATAL);
+                       return false;
+               }
+
+               /*
+               reset($GLOBALS['TYPO3_LOADED_EXT']);
+               foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $loadedExtConf)        {
+                       if (is_array($loadedExtConf) && $loadedExtConf['ext_tables.sql'])       {
+                               $tblFileContent.= chr(10).chr(10).chr(10).chr(10).t3lib_div::getUrl($loadedExtConf['ext_tables.sql']);
+                       }
+               }
+               
+               $t3lib_install = t3lib_div::makeInstance('t3lib_install');
+               $statements = $t3lib_install->getStatementArray($tblFileContent, 1);
+               
+               list($statements_table, $insertCount) = $t3lib_install->getCreateTables($statements, 1);
+               
+               $tblFileContent = t3lib_div::getUrl(PATH_t3lib.'stddb/tables.sql');
+               reset($GLOBALS['TYPO3_LOADED_EXT']);
+               
+               
+               
+               $fileContent = implode(
+                       $t3lib_install->getStatementArray($tblFileContent,1,'^CREATE TABLE '),
+                       chr(10)
+               );
+               $FDfile = $t3lib_install->getFieldDefinitions_sqlContent($fileContent);
+               
+               if (!count($FDfile))    {
+                       $this->addError(sprintf('There were no "CREATE TABLE" definitions in the provided file: %s', PATH_t3lib.'stddb/tables.sql'), FATAL);
+                       return false;
+               }
+               
+                       // Updating database...
+               /*
+               if (is_array($this->INSTALL['database_update']))        {
+                       $FDdb = $this->getFieldDefinitions_database();
+                       $diff = $this->getDatabaseExtra($FDfile, $FDdb);
+                       $update_statements = $this->getUpdateSuggestions($diff);
+                       $diff = $this->getDatabaseExtra($FDdb, $FDfile);
+                       $remove_statements = $this->getUpdateSuggestions($diff,'remove');
+
+                       $this->performUpdateQueries($update_statements['add'],$this->INSTALL['database_update']);
+                       $this->performUpdateQueries($update_statements['change'],$this->INSTALL['database_update']);
+                       $this->performUpdateQueries($remove_statements['change'],$this->INSTALL['database_update']);
+                       $this->performUpdateQueries($remove_statements['drop'],$this->INSTALL['database_update']);
+
+                       $this->performUpdateQueries($update_statements['create_table'],$this->INSTALL['database_update']);
+                       $this->performUpdateQueries($remove_statements['change_table'],$this->INSTALL['database_update']);
+                       $this->performUpdateQueries($remove_statements['drop_table'],$this->INSTALL['database_update']);
+               }
+               */
+
+               /*
+                       // Init again / first time depending...
+               $FDdb = $t3lib_install->getFieldDefinitions_database();
+
+               $diff = $t3lib_install->getDatabaseExtra($FDfile, $FDdb);
+               $update_statements = $t3lib_install->getUpdateSuggestions($diff);
+
+               $diff = $t3lib_install->getDatabaseExtra($FDdb, $FDfile);
+               $remove_statements = $t3lib_install->getUpdateSuggestions($diff,'remove');
+
+               $tLabel = 'Update database tables and fields';
+
+               if ($remove_statements || $update_statements)   {
+                       $formContent = $this->generateUpdateDatabaseForm('get_form',$update_statements,$remove_statements,$action_type);
+                       $this->message($tLabel,'Table and field definitions should be updated',"
+                       There seems to be a number of differencies between the database and the selected SQL-file.
+                       Please select which statements you want to execute in order to update your database:<br /><br />
+                       ".$formContent."
+                       ",2);
+               } else {
+                       $formContent = $this->generateUpdateDatabaseForm('get_form',$update_statements,$remove_statements,$action_type);
+                       $this->message($tLabel,'Table and field definitions are OK.',"
+                       The tables and fields in the current database corresponds perfectly to the database in the selected SQL-file.
+                       ",-1);
+               }
+               
+               return $formContent;
+               */
+               
+               return 'Here comes the result from the database analyzer';
+       }
+       
+       
+       
+       private function displaySuggestions($arr, $excludeList='')      {
+               $out='';
+               $out.='<tr><td bgcolor="#9BA1A8" align="center"><strong>'.$this->fw('Field name:').'</strong></td><td bgcolor="#9BA1A8" align="center"><strong>'.$this->fw('Info / Suggestion for the field:').'</strong></td></tr>';
+               $fC=0;
+               if (is_array($arr))     {
+                       reset($arr);
+                       while(list($fieldname, $fieldContent)=each($arr))       {
+                               if (!t3lib_div::inList($excludeList,$fieldname) && substr($fieldname,0,strlen($this->deletedPrefixKey))!=$this->deletedPrefixKey && substr($fieldname,-1)!='.') {
+                                       $fieldContent = $this->fw($fieldContent);
+                                       if ($arr[$fieldname.'.'])       {
+                                               $fieldContent.= '<hr />';
+                                               $fieldContent.= '<pre>'.trim($arr[$fieldname.'.']).'</pre>';
+                                       }
+                                       $out.='<tr><td bgcolor="#ABBBB4">'.$this->fw($fieldname).'</td><td bgcolor="#ABBBB4">'.$fieldContent.'</td></tr>';
+                                       $fC++;
+                               }
+                       }
+               }
+               $out= '<table border="0" cellpadding="2" cellspacing="2">'.$out.'</table>';
+               return array($out,$fC);
+       }
+
 
 }
 
 
 }
 
index 2809698..0a2e87c 100644 (file)
@@ -66,6 +66,13 @@ $GLOBALS['MCA']['database'] = array (
        ),
        
        'methods' => array (
        ),
        
        'methods' => array (
+               'analyze_compareFile' => array (
+                       'categoryMain' => 'database',
+                       'categorySub' => 'analyze',
+                       'tags' => array('database', 'db', 'cleanup', 'compare'),
+                       'method' => 'database:analyzeCompareFile',
+                       'autostart' => false
+               ),
                'cleanUp_cachedImageSizes' => array(
                        'title' => 'title_cleanUp_cachedImageSizes',
                        'description' => 'description_cleanUp_cachedImageSizes',
                'cleanUp_cachedImageSizes' => array(
                        'title' => 'title_cleanUp_cachedImageSizes',
                        'description' => 'description_cleanUp_cachedImageSizes',
@@ -73,7 +80,8 @@ $GLOBALS['MCA']['database'] = array (
                        'categoryMain' => 'database',
                        'categorySub' => 'cleanup',
                        'tags' => array ('database', 'db', 'clean'),
                        'categoryMain' => 'database',
                        'categorySub' => 'cleanup',
                        'tags' => array ('database', 'db', 'clean'),
-                       'method' => 'database:cleanUpCachedImageSizes'
+                       'method' => 'database:cleanUpCachedImageSizes',
+                       'autostart' => false
                ),
        ),
        
                ),
        ),
        
index 70cc125..070e052 100755 (executable)
                        <label index="title_typo_db_password">Database password</label>
                        <label index="title_typo_db">TYPO3 database</label>
 
                        <label index="title_typo_db_password">Database password</label>
                        <label index="title_typo_db">TYPO3 database</label>
 
+                       <label index="title_analyze_compareFile">Compare against default database</label>
+
                        <label index="label_database_defaulttables">Create default database tables</label>
                        <label index="label_selectdump">Please select a database dump</label>
                        <label index="label_database_defaulttables">Create default database tables</label>
                        <label index="label_selectdump">Please select a database dump</label>
+                       <label index="label_execute">Execute</label>
 
                        <label index="msg_database_error_cantconnect">FATAL: Can't connect to database-server!</label>
                        <label index="msg_database_error_cantselectdb">FATAL: Can't select database "%s"</label>
                        <label index="msg_database_error_couldnotcreate">Could not create database with name "%s"</label>
 
                        <label index="msg_database_error_cantconnect">FATAL: Can't connect to database-server!</label>
                        <label index="msg_database_error_cantselectdb">FATAL: Can't select database "%s"</label>
                        <label index="msg_database_error_couldnotcreate">Could not create database with name "%s"</label>
+                       <label index="msg_database_error_filenotfound">The compare-file "%s" was not found!</label>
 
                        <label index="msg_database_warning_selectdb">Please select a database or fill in a name for a new database.</label>
                        <label index="msg_database_warning_invalidname">The NEW database name "%s" was not alphanumeric, a-zA-Z0-9_-</label>
 
                        <label index="msg_database_warning_selectdb">Please select a database or fill in a name for a new database.</label>
                        <label index="msg_database_warning_invalidname">The NEW database name "%s" was not alphanumeric, a-zA-Z0-9_-</label>
index 64b48f4..32dea96 100644 (file)
@@ -226,7 +226,14 @@ class tx_install_module_setup extends tx_install_module_base       {
                                                                        break;
                                                                case 'methods':
                                                                                // the result of methods is simply printed out
                                                                        break;
                                                                case 'methods':
                                                                                // the result of methods is simply printed out
-                                                                       $deliverableContent = $this->basicsObject->executeMethod($modConfig['method']);
+                                                                       if ($modConfig['autostart'] == true)    {
+                                                                               $deliverableContent = $this->basicsObject->executeMethod($modConfig['method']);
+                                                                       } else {
+                                                                               $target = $name.'_result';
+                                                                               list($module, $method) = t3lib_div::trimExplode(':', $modConfig['method']);
+                                                                               $deliverableContent = '<a href="#" onclick="executeMethod(\''.$module.'\', \''.$method.'\',  {target:\''.$target.'\'}, displayMethodResult)">'.$this->get_LL('label_execute').'</a>
+                                                                                       <div id="'.$target.'"></div>';
+                                                                       }
                                                                        break;
                                                        }
                                                        
                                                                        break;
                                                        }