Untermenü

TYPO3 Chat hosted by kj187kj.

Join now


Chat about what's on your mind. More about public chats.

Sunsite SourceForge.net

Statistik
Tutorials Gesamt:
56
Tutorials Hidden:
1
Kommentare:
499

Bücher zum Thema

Links / Friends
» typo3.org
» T3N Magazin
» CSS Tutorials
» TYPO3 SEO
» TYPO3 Blog



 

CLI - Das neue Command Line Interface


Tutorial abonnieren:
Author:
Julian Kleinhans
Author E-Mail:
Eingetragen:
07.07.2008 - 20:57

Quelle:
Keine Quelle vorhanden
Klicks:
247




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:
http://typo3.org/extensions/repository/view/cli_example/1.0.0/

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

0:   <?php
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');
}
?>
1:  
2:  
3:  
4:  
5:  
Hier koennen Sie sich den Quellcode kopieren.


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

0:   <?php

/***************************************************************
*  Copyright notice
*
*  (c) 2008 Julian Kleinhans (jk@web-factory.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']);

?>
1:  
2:  
3:  
4:  
5:  
6:  
7:  
8:  
9:  
10:  
11:  
12:  
13:  
14:  
15:  
16:  
17:  
18:  
19:  
20:  
21:  
22:  
23:  
24:  
25:  
26:  
27:  
28:  
29:  
30:  
31:  
32:  
33:  
34:  
35:  
36:  
37:  
38:  
39:  
40:  
41:  
42:  
43:  
44:  
45:  
46:  
47:  
48:  
49:  
50:  
51:  
52:  
53:  
54:  
55:  
56:  
57:  
58:  
59:  
60:  
61:  
62:  
63:  
64:  
65:  
66:  
67:  
68:  
69:  
70:  
71:  
72:  
73:  
74:  
75:  
76:  
77:  
78:  
79:  
80:  
81:  
82:  
83:  
84:  
85:  
86:  
87:  
88:  
89:  
90:  
91:  
92:  
93:  
Hier koennen Sie sich den Quellcode kopieren.


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/funktionen 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






Ergebnis: Kein Ergebnis vorhanden



Zum Eingabeformular

 
Carsten 15.10.2008 11:00 Uhr 

Super Sache das... funktioniert besten. Danke für das Beispiel...!
 
 
 
Ben 31.08.2008 12:12 Uhr 

In so einem Fall hilft Cache löschen. Die Beispielsextension läuft.
Wichtig ist auch noch, dass ihr die Extension mit absoluten Pfad über den Dispatcher aufruft, sprich:
/home/user/www/typo3/...
Relativ läufts nicht.

Greetz Ben
 
 
 
Thomas Waggershauser 19.07.2008 15:15 Uhr 

ich kriege das bisher nicht zum laufen. Das init.php verweigert mit

The supplied 'cliKey' cli_example was not valid. Please use one of the available from this list:

Array
(
[0] => lowlevel_refindex
[1] => lowlevel_cleaner
)

das cli_example findet sich bei den keys leider nicht, nur im BE unter configuration kann ichs sehen.. :(
 
 
 
Seite: 1