-#! /usr/bin/php -q
+#! /usr/bin/env php
<?php
/***************************************************************
-* Copyright notice
-*
-* (c) 2005-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
-* 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!
-***************************************************************/
+ * Copyright notice
+ *
+ * (c) 2005-2013 Kasper Skaarhoj (kasperYYYY@typo3.com)
+ * 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 text file 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!
+ ***************************************************************/
/**
* Command Line Interface module dispatcher
*
- * $Id$
- *
- * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
- *
- * This script takes a "cliKey" as first argument and uses that to look up the path of the script to include in the end.
- * See configuration of this feature in $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys'].
- * The point is to have only ONE script dealing with the environment initialization while the actual processing is all a developer should care for.
+ * This script takes a "cliKey" as first argument and uses that to dispatch
+ * the call to a registered script with that key.
+ * Valid cliKeys must be registered in
+ * $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys'].
*
+ * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
*/
-
-if (substr(php_sapi_name(), 0, 3) == 'cgi') {
- // sanity check: ensure that we're running in a shell or cronjob (and NOT via HTTP)
- $checkEnvVars = array('HTTP_USER_AGENT', 'HTTP_HOST', 'SERVER_NAME', 'REMOTE_ADDR', 'REMOTE_PORT', 'SERVER_PROTOCOL');
- foreach ($checkEnvVars as $var) {
- if (array_key_exists($var, $_SERVER)) {
- echo 'SECURITY CHECK FAILD! This script cannot be used within your browser!' . chr(10);
- echo 'If you are sure that we run in a shell or cronjob, please unset' . chr(10);
- echo 'environment variable ' . $var . ' (usually using \'unset ' . $var . '\')' . chr(10);
- echo 'before starting this script.' . chr(10);
- exit;
- }
- }
- unset($checkEnvVars);
-
- // mimic CLI API in CGI API (you must use the -C/-no-chdir and the -q/--no-header switches!)
- ini_set('html_errors', 0);
- ini_set('implicit_flush', 1);
- ini_set('max_execution_time', 0);
- if (!ini_get('register_argc_argv')) {
- $argv = $_SERVER['argv'];
- $argc = $_SERVER['argc'];
- }
- define(STDIN, fopen('php://stdin', 'r'));
- define(STDOUT, fopen('php://stdout', 'w'));
- define(STDERR, fopen('php://stderr', 'w'));
-} elseif (php_sapi_name() != 'cli') {
- die('Not called from a command line interface (eg. a shell or scheduler).'.chr(10));
-}
-
- // Defining circumstances for CLI mode:
+define('TYPO3_MODE', 'BE');
define('TYPO3_cliMode', TRUE);
- // Get path to this script
-$temp_PATH_thisScript = isset($_SERVER['argv'][0]) ? $_SERVER['argv'][0] : (isset($_ENV['_']) ? $_ENV['_'] : $_SERVER['_']);
-
- // Figure out if the path is relative
-$relativePath = FALSE;
-if (stristr(PHP_OS,'win') && !stristr(PHP_OS,'darwin')) {
- // Windows
- if (!preg_match('/^([A-Z]:)?\\\/', $temp_PATH_thisScript)) {
- $relativePath = TRUE;
- }
-} else {
- // *nix, et al
- if ($temp_PATH_thisScript{0} != '/') {
- $relativePath = TRUE;
- }
-}
-
- // Resolve path
-if ($relativePath) {
- $workingDirectory = $_SERVER['PWD'] ? $_SERVER['PWD'] : getcwd();
- if ($workingDirectory) {
- $temp_PATH_thisScript =
- $workingDirectory.'/'.preg_replace('/\.\//','',$temp_PATH_thisScript);
- if (!@is_file($temp_PATH_thisScript)) {
- die ('Relative path found, but an error occured during resolving of the absolute path: '.$temp_PATH_thisScript.chr(10));
- }
- } else {
- die ('Relative path found, but resolving absolute path is not supported on this platform.'.chr(10));
- }
-}
+require __DIR__ . '/sysext/core/Classes/Core/CliBootstrap.php';
+\TYPO3\CMS\Core\Core\CliBootstrap::checkEnvironmentOrDie();
- // Define absolute path to this script
-define('PATH_thisScript',$temp_PATH_thisScript);
+require __DIR__ . '/sysext/core/Classes/Core/Bootstrap.php';
+\TYPO3\CMS\Core\Core\Bootstrap::getInstance()
+ ->baseSetup('typo3/')
+ ->loadConfigurationAndInitialize()
+ ->loadTypo3LoadedExtAndExtLocalconf(TRUE)
+ ->applyAdditionalConfigurationSettings()
+ ->initializeTypo3DbGlobal();
-if (!isset($_SERVER['argv'][1])) {
- die ('The first argument must be a valid key.'.chr(10));
-}
+\TYPO3\CMS\Core\Core\CliBootstrap::initializeCliKeyOrDie();
- // First argument is a key that points to the script configuration
-define('TYPO3_cliKey', $_SERVER['argv'][1]);
+\TYPO3\CMS\Core\Core\Bootstrap::getInstance()
+ ->loadExtensionTables(TRUE)
+ ->initializeBackendUser()
+ ->initializeBackendAuthentication()
+ ->initializeBackendUserMounts()
+ ->initializeLanguageObject();
- // Include init file:
-require(dirname(PATH_thisScript).'/init.php');
+ // Make sure output is not buffered, so command-line output and interaction can take place
+\TYPO3\CMS\Core\Utility\GeneralUtility::flushOutputBuffers();
-if (defined('TYPO3_cliInclude')) {
+try {
include(TYPO3_cliInclude);
-} else {
- die('No include file configured for key "'.TYPO3_cliKey.'".'.chr(10));
+} catch (\Exception $e) {
+ fwrite(STDERR, $e->getMessage() . LF);
+ exit(99);
}
-?>
+\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->shutdown();