Added feature #16457: em: add possibility to install extension from t3x (used by...
authorErnesto Baschny <ernst@cron-it.de>
Thu, 18 Nov 2010 03:11:20 +0000 (03:11 +0000)
committerErnesto Baschny <ernst@cron-it.de>
Thu, 18 Nov 2010 03:11:20 +0000 (03:11 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9485 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/em/classes/connection/class.tx_em_connection_extdirectserver.php
typo3/sysext/em/classes/extensions/class.tx_em_extensions_list.php
typo3/sysext/em/classes/index.php
typo3/sysext/em/classes/install/class.tx_em_install.php
typo3/sysext/em/classes/tools/class.tx_em_tools.php

index e88bd7b..90128ab 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -61,6 +61,7 @@
        * Added feature #11916: New TYPO3_DB method for queries that expect just a single result row: exec_SELECTgetSingleRow (Thanks to Jo Hasenau)
        * Fixed bug #16444: Bugfix:dbal installs itself automatically whenever the install tool is called (Thanks to Susanne Moog)
        * Fixed bug #16456: When dbal is activated, styles.content.get (and others) doesn't work anymore (empty result)
+       * Added feature #16457: em: add possibility to install extension from t3x (used by the introduction package)
 
 2010-11-17  Benjamin Mack  <benni@typo3.org>
 
index dfb6a2a..2c31d23 100644 (file)
@@ -42,6 +42,20 @@ class tx_em_Connection_ExtDirectServer {
        var $xmlhandler;
 
        /**
+        * Class for printing extension lists
+        *
+        * @var tx_em_Extensions_List
+        */
+       public $extensionList;
+
+       /**
+        * Class for extension details
+        *
+        * @var tx_em_Extensions_Details
+        */
+       public $extensionDetails;
+
+       /**
         * Keeps instance of settings class.
         *
         * @var tx_em_Settings
@@ -654,11 +668,14 @@ class tx_em_Connection_ExtDirectServer {
         * @return  array status
         */
        public function uploadExtension($parameter) {
-               $uploadedTempFile = t3lib_div::upload_to_tempfile($parameter['extupload-path']['tmp_name']);
+               $uploadedTempFile = isset($parameter['extfile']) ? $parameter['extfile'] : t3lib_div::upload_to_tempfile($parameter['extupload-path']['tmp_name']);
                $location = ($parameter['loc'] === 'G' || $parameter['loc'] === 'S') ? $parameter['loc'] : 'L';
                $uploadOverwrite = $parameter['uploadOverwrite'] ? TRUE : FALSE;
 
                $install = t3lib_div::makeInstance('tx_em_Install', $this);
+               $this->extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
+               $this->extensionDetails = t3lib_div::makeInstance('tx_em_Extensions_Details', $this);
+
                $upload = $install->uploadExtensionFile($uploadedTempFile, $location, $uploadOverwrite);
 
                if ($upload[0] === FALSE) {
@@ -667,8 +684,11 @@ class tx_em_Connection_ExtDirectServer {
                                'error' => $upload[1]
                        );
                }
+
                $extKey = $upload[1][0]['extKey'];
-               $result = $install->installExtension($upload[1], $location);
+               $version = '';
+               $dontDelete = TRUE;
+               $result = $install->installExtension($upload[1], $location, $version, $uploadedTempFile, $dontDelete);
                return array(
                        'success' => TRUE,
                        'data' => $result,
@@ -676,6 +696,24 @@ class tx_em_Connection_ExtDirectServer {
                );
 
        }
+
+       /**
+        * Enables an extension
+        *
+        * @param  $extensionKey
+        * @return void
+        */
+       public function enableExtension($extensionKey) {
+               $this->extensionList = t3lib_div::makeInstance('tx_em_Extensions_List', $this);
+               $install = t3lib_div::makeInstance('tx_em_Install', $this);
+
+               list($installedList,) = $this->extensionList->getInstalledExtensions();
+               $newExtensionList = $this->extensionList->addExtToList($extensionKey, $installedList);
+
+               $install->writeNewExtensionList($newExtensionList);
+               tx_em_Tools::refreshGlobalExtList();
+               $install->forceDBupdates($extensionKey, $newExtensionList[$extensionKey]);
+       }
 }
 
 ?>
\ No newline at end of file
index c57fcf3..95c2699 100644 (file)
@@ -544,10 +544,11 @@ EXTENSION KEYS:
                                                '</a></td>';
 
                                // Manual download
-                               $fileP = PATH_site . $this->parentObject->typePaths[$extInfo['type']] . $extKey . '/doc/manual.sxw';
+                               $fileP = PATH_site . tx_em_Tools::typePath($extInfo['type']) . $extKey . '/doc/manual.sxw';
                                $cells[] = '<td nowrap="nowrap">' .
-                                               ($this->parentObject->typePaths[$extInfo['type']] && @is_file($fileP) ?
-                                                               '<a href="' . htmlspecialchars(t3lib_div::resolveBackPath($this->parentObject->doc->backPath . '../' . $this->parentObject->typePaths[$extInfo['type']] . $extKey . '/doc/manual.sxw')) . '" target="_blank" title="' . $GLOBALS['LANG']->getLL('listRow_local_manual') . '">' .
+                                               (tx_em_Tools::typePath($extInfo['type']) && @is_file($fileP) ?
+                                                               '<a href="' . htmlspecialchars(t3lib_div::resolveBackPath($this->parentObject->doc->backPath . '../' .
+                                                                       tx_em_Tools::typePath($extInfo['type']) . $extKey . '/doc/manual.sxw')) . '" target="_blank" title="' . $GLOBALS['LANG']->getLL('listRow_local_manual') . '">' .
                                                                                t3lib_iconWorks::getSpriteIcon('actions-system-extension-documentation') . '</a>' : '') .
                                                '</td>';
 
@@ -781,6 +782,7 @@ EXTENSION KEYS:
 
                // Implode unique list of extensions to load and return:
                $list = implode(',', array_unique($listArr));
+
                return $list;
        }
 
@@ -835,8 +837,9 @@ EXTENSION KEYS:
         * @see removeExtFromList(), addExtToList()
         */
        function removeRequiredExtFromListArr($listArr) {
+               $requiredExtensions = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'], 1);
                foreach ($listArr as $k => $ext) {
-                       if (in_array($ext, $this->parentObject->requiredExt) || !strcmp($ext, '_CACHEFILE')) {
+                       if (in_array($ext, $requiredExtensions) || !strcmp($ext, '_CACHEFILE')) {
                                unset($listArr[$k]);
                        }
                }
index 235b659..1fde84c 100644 (file)
@@ -428,7 +428,11 @@ class SC_mod_tools_em_index extends t3lib_SCbase {
 
                        // temporary unset new modules
                unset ($this->MOD_MENU['function']['extensionmanager'], $this->MOD_MENU['function']['develop']);
-
+               /*
+               if (!intval($GLOBALS['TYPO3_CONF_VARS']['BE']['debug'])) {
+                       unset ($this->MOD_MENU['function']['develop']);
+               }
+        */
 
                $this->MOD_MENU['singleDetails'] = $this->mergeExternalItems($this->MCONF['name'], 'singleDetails', $this->MOD_MENU['singleDetails']);
 
@@ -466,10 +470,9 @@ class SC_mod_tools_em_index extends t3lib_SCbase {
         * @return      void
         */
        function main() {
-               global $BE_USER, $LANG, $TYPO3_CONF_VARS;
 
                if (empty($this->MOD_SETTINGS['mirrorListURL'])) {
-                       $this->MOD_SETTINGS['mirrorListURL'] = $TYPO3_CONF_VARS['EXT']['em_mirrorListURL'];
+                       $this->MOD_SETTINGS['mirrorListURL'] = $GLOBALS['TYPO3_CONF_VARS']['EXT']['em_mirrorListURL'];
                }
 
                // Starting page:
@@ -1312,9 +1315,9 @@ class SC_mod_tools_em_index extends t3lib_SCbase {
                                                break;
                                }
                                if ($newExtList != -1) {
-                                       $this->writeNewExtensionList($newExtList);
-                                       $this->refreshGlobalExtList();
-                                       $this->forceDBupdates($extKey, $inst_list[$extKey]);
+                                       $this->install->writeNewExtensionList($newExtList);
+                                       tx_em_Tools::refreshGlobalExtList();
+                                       $this->install->forceDBupdates($extKey, $inst_list[$extKey]);
                                        return array(true, $GLOBALS['LANG']->getLL('ext_import_ext_loaded'));
                                }
                        }
@@ -1360,9 +1363,9 @@ class SC_mod_tools_em_index extends t3lib_SCbase {
                        $this->importExtFromRep($extKey, $version, 'L');
                        $newExtList = $this->extensionList->addExtToList($extKey, $inst_list);
                        if ($newExtList != -1) {
-                               $this->writeNewExtensionList($newExtList);
-                               $this->refreshGlobalExtList();
-                               $this->forceDBupdates($extKey, $inst_list[$extKey]);
+                               $this->install->writeNewExtensionList($newExtList);
+                               tx_em_Tools::refreshGlobalExtList();
+                               $this->install->forceDBupdates($extKey, $inst_list[$extKey]);
                                $this->translations->installTranslationsForExtension($extKey, $this->getMirrorURL());
                                return array(true, $GLOBALS['LANG']->getLL('ext_import_ext_imported'));
                        } else {
@@ -1373,29 +1376,6 @@ class SC_mod_tools_em_index extends t3lib_SCbase {
                }
        }
 
-       function refreshGlobalExtList() {
-               global $TYPO3_LOADED_EXT;
-
-               $TYPO3_LOADED_EXT = t3lib_extMgm::typo3_loadExtensions();
-               if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
-                       require(PATH_typo3conf . $TYPO3_LOADED_EXT['_CACHEFILE'] . '_ext_localconf.php');
-               }
-               return;
-
-               $GLOBALS['TYPO3_LOADED_EXT'] = t3lib_extMgm::typo3_loadExtensions();
-               if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
-                       require(PATH_typo3conf . $TYPO3_LOADED_EXT['_CACHEFILE'] . '_ext_localconf.php');
-               } else {
-                       $temp_TYPO3_LOADED_EXT = $TYPO3_LOADED_EXT;
-                       foreach ($temp_TYPO3_LOADED_EXT as $_EXTKEY => $temp_lEDat) {
-                               if (is_array($temp_lEDat) && $temp_lEDat['ext_localconf.php']) {
-                                       $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
-                                       require($temp_lEDat['ext_localconf.php']);
-                               }
-                       }
-               }
-       }
-
 
        /**
         * Imports an extensions from the online repository
@@ -1613,7 +1593,7 @@ class SC_mod_tools_em_index extends t3lib_SCbase {
                                                        }
                                                }
                                                if (!$updates || t3lib_div::_GP('_do_install')) {
-                                                       $this->writeNewExtensionList($newExtList);
+                                                       $this->install->writeNewExtensionList($newExtList);
                                                        $action = $this->CMD['load'] ? 'installed' : 'removed';
                                                        $GLOBALS['BE_USER']->writelog(5, 1, 0, 0, 'Extension list has been changed, extension %s has been %s', array($extKey, $action));
 
@@ -2418,110 +2398,11 @@ class SC_mod_tools_em_index extends t3lib_SCbase {
        }
 
 
-       /**
-        * Writes the extension list to "localconf.php" file
-        * Removes the temp_CACHED* files before return.
-        *
-        * @param       string          List of extensions
-        * @return      void
-        */
-       function writeNewExtensionList($newExtList) {
-               global $TYPO3_CONF_VARS;
-
-               $strippedExtensionList = $this->stripNonFrontendExtensions($newExtList);
-
-               // Instance of install tool
-               $instObj = new t3lib_install;
-               $instObj->allowUpdateLocalConf = 1;
-               $instObj->updateIdentity = 'TYPO3 Extension Manager';
 
-               // Get lines from localconf file
-               $lines = $instObj->writeToLocalconf_control();
-               $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList\']', $newExtList);
-               $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList_FE\']', $strippedExtensionList);
-               $instObj->writeToLocalconf_control($lines);
 
-               $TYPO3_CONF_VARS['EXT']['extList'] = $newExtList;
-               $TYPO3_CONF_VARS['EXT']['extList_FE'] = $strippedExtensionList;
-               t3lib_extMgm::removeCacheFiles();
-       }
 
-       /**
-        * Removes unneeded extensions from the frontend based on
-        * EMCONF doNotLoadInFE = 1
-        *
-        * @param string $extList
-        * @return string
-        */
-       function stripNonFrontendExtensions($extList) {
-               $fullExtList = $this->extensionList->getInstalledExtensions();
-               $extListArray = t3lib_div::trimExplode(',', $extList);
-               foreach ($extListArray as $arrayKey => $extKey) {
-                       if ($fullExtList[0][$extKey]['EM_CONF']['doNotLoadInFE'] == 1) {
-                               unset($extListArray[$arrayKey]);
-                       }
-               }
-               $nonFEList = implode(',', $extListArray);
-               return $nonFEList;
-       }
 
 
-       /**
-        * 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);
-                                       }
-                               }
-                       }
-               }
-       }
-
 
        /************************************
         *
index bda3d04..486cc75 100644 (file)
@@ -1304,6 +1304,107 @@ class tx_em_Install {
                return $content;
        }
 
+       /**
+        * Writes the extension list to "localconf.php" file
+        * Removes the temp_CACHED* files before return.
+        *
+        * @param       string          List of extensions
+        * @return      void
+        */
+       function writeNewExtensionList($newExtList) {
+               $strippedExtensionList = $this->stripNonFrontendExtensions($newExtList);
+
+               // Instance of install tool
+               $instObj = new t3lib_install;
+               $instObj->allowUpdateLocalConf = 1;
+               $instObj->updateIdentity = 'TYPO3 Extension Manager';
+
+               // Get lines from localconf file
+               $lines = $instObj->writeToLocalconf_control();
+               $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList\']', $newExtList);
+               $instObj->setValueInLocalconfFile($lines, '$TYPO3_CONF_VARS[\'EXT\'][\'extList_FE\']', $strippedExtensionList);
+               $instObj->writeToLocalconf_control($lines);
+
+               $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = $newExtList;
+               $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList_FE'] = $strippedExtensionList;
+               t3lib_extMgm::removeCacheFiles();
+       }
+
+       /**
+        * Removes unneeded extensions from the frontend based on
+        * EMCONF doNotLoadInFE = 1
+        *
+        * @param string $extList
+        * @return string
+        */
+       function stripNonFrontendExtensions($extList) {
+               $fullExtList = $this->parentObject->extensionList->getInstalledExtensions();
+               $extListArray = t3lib_div::trimExplode(',', $extList);
+               foreach ($extListArray as $arrayKey => $extKey) {
+                       if ($fullExtList[0][$extKey]['EM_CONF']['doNotLoadInFE'] == 1) {
+                               unset($extListArray[$arrayKey]);
+                       }
+               }
+               $nonFEList = implode(',', $extListArray);
+               return $nonFEList;
+       }
+
+       /**
+        * 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);
+                                       }
+                               }
+                       }
+               }
+       }
+
 }
 
 ?>
\ No newline at end of file
index a9896da..f074e39 100644 (file)
@@ -93,6 +93,34 @@ final class tx_em_Tools {
 
 
        /**
+        * Refreshes the global extension list
+        *
+        * @return void
+        */
+       function refreshGlobalExtList() {
+               global $TYPO3_LOADED_EXT;
+
+               $TYPO3_LOADED_EXT = t3lib_extMgm::typo3_loadExtensions();
+               if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
+                       require(PATH_typo3conf . $TYPO3_LOADED_EXT['_CACHEFILE'] . '_ext_localconf.php');
+               }
+               return;
+
+               $GLOBALS['TYPO3_LOADED_EXT'] = t3lib_extMgm::typo3_loadExtensions();
+               if ($TYPO3_LOADED_EXT['_CACHEFILE']) {
+                       require(PATH_typo3conf . $TYPO3_LOADED_EXT['_CACHEFILE'] . '_ext_localconf.php');
+               } else {
+                       $temp_TYPO3_LOADED_EXT = $TYPO3_LOADED_EXT;
+                       foreach ($temp_TYPO3_LOADED_EXT as $_EXTKEY => $temp_lEDat) {
+                               if (is_array($temp_lEDat) && $temp_lEDat['ext_localconf.php']) {
+                                       $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
+                                       require($temp_lEDat['ext_localconf.php']);
+                               }
+                       }
+               }
+       }
+
+       /**
         * Set category array entries for extension
         *
         * @param       array           Category index array