Added feature #16137: [em] Task to update extension list
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 29 Oct 2010 13:30:40 +0000 (13:30 +0000)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 29 Oct 2010 13:30:40 +0000 (13:30 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9222 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/core_autoload.php
typo3/sysext/em/classes/exception/class.em_connection_exception.php [new file with mode: 0644]
typo3/sysext/em/classes/tasks/class.em_tasks_updateextensionlist.php [new file with mode: 0644]
typo3/sysext/em/ext_autoload.php [new file with mode: 0644]
typo3/sysext/em/ext_localconf.php [new file with mode: 0644]
typo3/sysext/em/language/locallang.xml [new file with mode: 0644]

index 8d474c2..f720ee5 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2010-10-29  Christian Kuhn  <lolli@schwarzbu.ch>
 
+       * Added feature #16137: [em] Task to update extension list
        * Fixed bug #4272: Inconsistent return values of ini_get() produce false positives for safe_mode detection (Thanks to Peter Beernink)
 
 2010-10-29  Ernesto Baschny  <ernst@cron-it.de>
index 16d08fc..9b3165e 100644 (file)
@@ -168,5 +168,8 @@ $t3libClasses = array(
 
 $tslibClasses = require(PATH_typo3 . 'sysext/cms/ext_autoload.php');
 
-return array_merge($t3libClasses, $tslibClasses);
+$emClasses = array();
+$emClasses = require(PATH_typo3 . 'sysext/em/ext_autoload.php');
+
+return array_merge($t3libClasses, $tslibClasses, $emClasses);
 ?>
diff --git a/typo3/sysext/em/classes/exception/class.em_connection_exception.php b/typo3/sysext/em/classes/exception/class.em_connection_exception.php
new file mode 100644 (file)
index 0000000..7c2394a
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2010 Marcus Krause <marcus#exp2010@t3sec.info>
+*           Steffen Kamper <info@sk-typo3.de>
+*  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.
+*
+*  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!
+***************************************************************/
+/**
+ * Module: Extension manager - connection exception
+ *
+ * $Id: class.em_connection_exception.php 1876 2010-02-18 23:23:13Z mkrause $
+ */
+
+/**
+ * Exception for internet connection handling.
+ *
+ * This exception is supposed to be thrown when
+ * there are problems with the internet connections
+ * initialized by the web server.
+ *
+ * @author      Marcus Krause <marcus#exp2010@t3sec.info>
+ * @author      Steffen Kamper <info@sk-typo3.de>
+ *
+ * @since       2010-02-18
+ * @package     TYPO3
+ * @subpackage  EM
+ */
+class em_connection_Exception extends Exception {
+
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/em/classes/tasks/class.em_tasks_updateextensionlist.php b/typo3/sysext/em/classes/tasks/class.em_tasks_updateextensionlist.php
new file mode 100644 (file)
index 0000000..eaa3a8b
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2010 Christian Kuhn <lolli@schwarzbu.ch>
+*  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.
+*
+*  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!
+***************************************************************/
+
+/**
+ * Update extension list task
+ *
+ * @author Christian Kuhn <lolli@schwarzbu.ch>
+ * @package TYPO3
+ * @subpackage em
+ */
+class em_tasks_UpdateExtensionList extends tx_scheduler_Task {
+       /**
+        * Public method, usually called by scheduler.
+        *
+        * @return boolean True on success
+        */
+       public function execute() {
+                       // Throws exceptions if something goes wrong
+               $this->updateExtensionlist();
+
+               return(TRUE);
+       }
+
+       /**
+        * Update extension list
+        *
+        * @throws em_connection_Exception if fetch from mirror fails
+        * @return void
+        */
+       protected function updateExtensionlist() {
+               require_once(PATH_typo3 . 'template.php');
+
+               $extensionManager = t3lib_div::makeInstance('SC_mod_tools_em_index');
+               $extensionManager->init();
+
+               if (empty($extensionManager->MOD_SETTINGS['mirrorListURL'])) {
+                       $extensionManager->MOD_SETTINGS['mirrorListURL'] = $GLOBALS['TYPO3_CONF_VARS']['EXT']['em_mirrorListURL'];
+               }
+
+               if (is_file(PATH_site . 'typo3temp/extensions.xml.gz')) {
+                       $localMd5 = md5_file(PATH_site . 'typo3temp/extensions.xml.gz');
+               }
+
+               $mirror = $extensionManager->getMirrorURL();
+               $remoteMd5 = t3lib_div::getURL($mirror . 'extensions.md5', 0, array(TYPO3_user_agent));
+               if (!$remoteMd5) {
+                       throw new em_connection_Exception(
+                               'Unable to fetch extension list md5 file from remote mirror.',
+                               1288121556
+                       );
+               }
+
+               $localExtensionCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('extkey', 'cache_extensions');
+
+               if ($localMd5 !== $remoteMd5 || $localExtensionCount === '0') {
+                       $remoteXml = t3lib_div::getURL($mirror . 'extensions.xml.gz', 0, array(TYPO3_user_agent));
+
+                       if (!$remoteXml) {
+                               throw new em_connection_Exception(
+                                       'Unable to fetch extension list XML file from remote mirror.',
+                                       1288121557
+                               );
+                       }
+
+                       t3lib_div::writeFile(PATH_site . 'typo3temp/extensions.xml.gz', $remoteXml);
+                       $extensionManager->xmlhandler->parseExtensionsXML(PATH_site . 'typo3temp/extensions.xml.gz');
+               }
+       }
+}
+
+if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/em/classes/tasks/class.em_tasks_updateextensionlist.php']) {
+       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/em/classes/tasks/class.em_tasks_updateextensionlist.php']);
+}
+
+?>
diff --git a/typo3/sysext/em/ext_autoload.php b/typo3/sysext/em/ext_autoload.php
new file mode 100644 (file)
index 0000000..ab821f3
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+$emClassesPath = PATH_site . 'typo3/sysext/em/classes/';
+return array(
+       'sc_mod_tools_em_index' => $emClassesPath . '../mod1/class.em_index.php',
+       'em_connection_exception' => $emClassesPath . 'exception/class.em_connection_exception.php',
+       'em_tasks_updateextensionlist' => $emClassesPath . 'tasks/class.em_tasks_updateextensionlist.php',
+);
+?>
diff --git a/typo3/sysext/em/ext_localconf.php b/typo3/sysext/em/ext_localconf.php
new file mode 100644 (file)
index 0000000..d2d05ea
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+if (!defined ('TYPO3_MODE')) {
+       die ('Access denied.');
+}
+
+       // Register extension list update task
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['em_tasks_UpdateExtensionList'] = array(
+       'extension'        => $_EXTKEY,
+       'title'            => 'LLL:EXT:' . $_EXTKEY . '/language/locallang.xml:tasks_updateExtensionlistTask.name',
+       'description'      => 'LLL:EXT:' . $_EXTKEY . '/language/locallang.xml:tasks_updateExtensionlistTask.description',
+       'additionalFields' => '',
+);
+?>
diff --git a/typo3/sysext/em/language/locallang.xml b/typo3/sysext/em/language/locallang.xml
new file mode 100644 (file)
index 0000000..4c78265
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+<T3locallang>
+       <meta type="array">
+               <type>module</type>
+               <description>Labels for Extension Manager</description>
+       </meta>
+       <data type="array">
+               <languageKey index="default" type="array">
+                       <label index="tasks_updateExtensionlistTask.name">Update extension list</label>
+                       <label index="tasks_updateExtensionlistTask.description">Update extension list on a regular basis. Once a day is a good interval.</label>
+               </languageKey>
+       </data>
+</T3locallang>