Seit TYPO3 4.1 gibt es ein neues Command Line Interface! Leider ist dieses nirgendwo dokumentiert. Vorab, ich habe eine Beispiel Extension geschrieben die Ihr hier finden könnt. Und los gehts ...
Schritt 1:
Legt einen neuen Backend User an. Er sollte mit _cli_ beginnen also zB _cli_user, das Passwort ist egal da das CLI sich nicht ins Backend einloggt.
Schritt 2:
ext_localconf.php bearbeiten bzw. anlegen und folgenden Inhalt rein kopieren
if (TYPO3_MODE=='BE') {
// Setting up scripts that can be run from the cli_dispatch.phpsh script.
$TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys'][$_EXTKEY] = array('EXT:' . $_EXTKEY . '/cli/class.cli_example.php', '_CLI_user');
}
Schritt 3:
Einen neuen Ordner cli in euerer Extension anlegen. Eine neue Datei class.cli_example.php anlegen. Wenn Ihr der Datei einen anderen Namen gebt müsst Ihr den Namen auch in der ext_localconf.php anpassen.
Schritt 4:
Öffnet die neu angelegte Datei class.cli_example.php und kopiert folgendes Grundgerüst hinein
/***************************************************************
* Copyright notice
*
* (c) 2008 Julian Kleinhans (typo3@kj187.de)
* All rights reserved
*
* [...]
*
*/
if (!defined('TYPO3_cliMode')) die('You cannot run this script directly!');
// Include basis cli class
require_once(PATH_t3lib.'class.t3lib_cli.php');
class tx_cliexample_cli extends t3lib_cli {
/**
* Constructor
*/
function tx_mfcarticletocontent_cli () {
// Running parent class constructor
parent::t3lib_cli();
// Setting help texts:
$this->cli_help['name'] = 'Name of script';
$this->cli_help['synopsis'] = '###OPTIONS###';
$this->cli_help['description'] = 'Class with basic functionality for CLI scripts';
$this->cli_help['examples'] = '/.../cli_dispatch.phpsh EXTKEY TASK';
$this->cli_help['author'] = 'Julian Kleinhans, (c) 2008';
}
/**
* CLI engine
*
* @param array Command line arguments
* @return string
*/
function cli_main($argv) {
// get task (function)
$task = (string)$this->cli_args['_DEFAULT'][1];
if (!$task){
$this->cli_validateArgs();
$this->cli_help();
exit;
}
if ($task == 'myFunction') {
$this->myFunction();
}
/**
* Or other tasks
* Which task shoud be called can you define in the shell command
* /www/typo3/cli_dispatch.phpsh cli_example otherTask
*/
if ($task == 'otherTask') {
// ...
}
}
/**
* myFunction which is called over cli
*
*/
function myFunction(){
// Output
$this->cli_echo('Whats your name:');
// Input
$input = $this->cli_keyboardInput();
$this->cli_echo('Hi '.$input.', your CLI script works :)');
// Input yes/no
$input = $this->cli_keyboardInput_yes('You want money?');
if($b){
$this->cli_echo('nHaha.. go working! :)');
}else{
$this->cli_echo('nOh ok.. are you ill?');
}
}
}
// Call the functionality
$cleanerObj = t3lib_div::makeInstance('tx_cliexample_cli');
$cleanerObj->cli_main($_SERVER['argv']);
Ich denke der Quellcode ist soweit selbsterklärend, wenn nein stellt hier euere Fragen ;) Aufgerufen wird das ganze dann so
PFAD/www/typo3/cli_dispatch.phpsh EXTKEY TASK
Beispiel:
/server/www/typo3/cli_dispatch.phpsh cli_example myFunction
Somit wird die Funktion myFunction aufgerufen! Ihr könnt euer Script somit mit x weiteren Tasks/Methoden erweitern und diese dann per Shellcommando ausführen lassen..
Vor TYPO3 Version 4.1 musste man ein CLI Script anders bauen. Dazu schaut euch folgendes Tutorial an: http://www.typo3-tutorials.org/tutorials/entwicklung/cli-shell-scripte.html

