Ergebnis 1 bis 3 von 3

Thema: tx_impexp über cli

      
  1. #1
    Forum Zuschauer
    Registriert seit
    02.11.2011
    Beiträge
    3

    tx_impexp über cli

    Hallo,

    ich versuche die Import-Funktion für .t3d-Dateien über die Kommandozeile verfügbar zu machen. Funktionen für das Aktivieren von Erweiterungen, einschließlich automatischer Aktualisierung der Datenbank, laufen bereits über dieses Skript.

    Für den Import habe ich folgende Funktion meiner CLI-Klasse hinzugefügt:

    PHP-Code:
        /**
         * Import T3D File
         *
         * @return void
         */
        
    function importT3d() {
        
            
    // get file path
            
    $fileName = (string)$this->cli_args['_DEFAULT'][2];

            
    // get pid
            
    $pid = (int)$this->cli_args['_DEFAULT'][3];

            
    $import t3lib_div::makeInstance('tx_impexp');
            
    $import->init(0'import');
            
    $import->enableLogging true;

            if (
    $fileName && @is_file($fileName))    {    
                    
              if (
    $import->loadFile($fileName)) {
                
    $this->cli_echo('Importing "'.$fileName.'"');
                
    $import->importData($pid);
              } else {
                
    $this->cli_echo('Can\'t load file "'.$fileName.'"');
              }
            } else {
              
    $this->cli_echo('File "'.$fileName.'" not found');
            }
        } 
    Problem ist, dass ein Auruf mit: [...] -f [...]/cli_dispatch.phpsh wee_shell import [...]/my.t3d 1 erfolgreich beendet wird. D.h. tx_impexp::importData() wird zwar aufgrufen aber ohne den gewünschten Effekt in der Datenbank oder einer Fehlermeldung. Einen entsprechenden BE-Benutzer (_cli_wee_shell) für das CLI-Skript habe ich angelegt; bis auf die Import-Funktion, wo der Upload-Reiter im BE für diesen Benutzer nicht erscheint, kann ich mit diesem Konto im BE lesend und schreibend auf den Seitenbaum ab der PID 1 zugreifen.

    Ich vermute, dass ich ein Rechteproblem habe und damit t3lib_TCEmain::process_datamap() fehlschlägt.

    Im Einsatz ist TYPO3 4.5.7 (blankpackage) mit templavoila 1.6.0-dev, static_info_tables 2.2.0 und fb_magento 1.1.0-beta.

    Was mache ich falsch, worauf müsste ich noch achten?


    Vielen Dank für eure Zeit und liebe Grüße.


    ps: Grundsätzlich benötige ich eben ein brauchbares CLI für TYPO3 um meine ANT-Targets zu vereinfachen und flexibler zu gestalten. ANT benutze ich derzeit für das Deployment meiner Quellen und für die Grundinstallation von TYPO3 u.a. einschließlich aller zusätzlichen Module, so das ich derzeit keine Installation mehr manuell durchführen muss und einen gesicherten Konfigurations-Zustand habe. Bisher funktioniert das auch ganz gut (ca. 6 Minuten für eine Installation), bis auf die zusätzlichen Daten in der Datenbank (Seitenbaum, Templates etc.). Frühere Aktionen mit entsprechenden SQL-Dumps werde ich künftig auch net mehr machen, da diese Methode zu unflexibel im Deployment und der Release-Erstellung ist.
    Geändert von arno12 (02.11.2011 um 20:12 Uhr) Grund: Ergänzungen

  2. #2
    Forum Zuschauer
    Registriert seit
    02.11.2011
    Beiträge
    3
    Ok ich habe das Problem lösen können, nachdem ich mir die Fehler des jeweiligen TCEMain, der von tx_impexp verwendet wird, hab ausgeben lassen. Das Problem war, dass ich zunächst das all Flag im Aufruf von loadFile net gesetzt hatte, und dann immer die falsche ID für die übergeordnete Seite angegeben hatte.

    Das ganze Skript sieht derzeit so aus, falls es jemanden interessiert:

    PHP-Code:
    <?php
    /*
     *  Copyright notice
    *
    *  (c) 2011 Anonymous <anonymous@somwhere.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!
    */

    if (!defined('TYPO3_cliMode'))
    die(
    'You cannot run this script directly!');

    // Include basis cli class
    require_once(PATH_t3lib.'class.t3lib_cli.php');

    require_once (
    PATH_site.'typo3/sysext/impexp/class.tx_impexp.php');

    /**
     * tx_weeshell command line interface
     *
     * @author Anonymous <anonymous@somewhere.com>
     * @package TYPO3
     * @subpackage wee_shell
     * @todo Formating outputs
     */
    class tx_weeshell_cli extends t3lib_cli {

        var 
    $prefixId      'tx_weeshell_cli';
        var 
    $scriptRelPath 'cli/class.tx_weeshell_cli.php';
        var 
    $extKey        'wee_shell';

        
    /**
         * Constructor
         *
         * @return tx_weeshell_cli
         */
        
    function tx_weeshell_cli() {
            
    // Running parent class constructor
            
    parent::t3lib_cli();

            
    // Setting help texts:
            
    $this->cli_help['name'] = 'Wee Shell';
            
    $this->cli_help['synopsis'] = '###OPTIONS###';
            
    $this->cli_help['description'] = "Basic CLI for TYPO3";
            
    $this->cli_help['examples'] = '/.../cli_dispatch.phpsh '.$this->extKey.' <task> <args>';
            
    $this->cli_help['author'] = '(c) 2011 Anonymous <anonymous@somewhere.com>';
        }

        
    /**
         * Register handler for a hook
         *
         * @param array $hook
         * @param string $handler Method name
         * @return tx_weeshell_cli
         */
        
    function registerHandler(&$hook$handler) {
            
    $hook[] = 'EXT:wee_shell/cli/class.tx_weeshell_cli.php:&tx_weeshell_cli->'.$handler;
        }

        
    /**
         * Main entry point
         *
         * @param array Command line arguments
         * @return string
         */
        
    function cli_main($argv) {

            
    // validate input
            
    $this->cli_validateArgs();
                
            
    // get task (function)
            
    $task = (string)$this->cli_args['_DEFAULT'][1];

            if (!
    $task) {
                
    $this->cli_help();
                exit;
            }

            
    // select called function
            
    switch ($task) {
                case 
    'enable':
                    
    $this->enableExtension();
                    break;
                case 
    'import':
                    
    $this->importT3d();
                    break;
                default:
                    
    $this->cli_echo('Unknown task "'.$task.'"');
            }
        }

        
    /**
         * Enable extension
         *
         * @todo Error handling
         * @return void
         */
        
    function enableExtension() {
            
    // get extension key
            
    $key = (string)$this->cli_args['_DEFAULT'][2];

            
    t3lib_div::makeInstance('tx_em_Connection_ExtDirectServer')->enableExtension($key);
        }

        
    /**
         * Import T3D File
         *
         * @return void
         */
        
    function importT3d() {
            global 
    $GLOBALS;

            
    $hooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/impexp/class.tx_impexp.php'];

            
    // get file path
            
    $fileName = (string)$this->cli_args['_DEFAULT'][2];

            
    // get pid
            
    $pid = (int)$this->cli_args['_DEFAULT'][3];

            
    $import t3lib_div::makeInstance('tx_impexp');
            
    $import->init(0'import');
            
    $import->enableLogging true;

            if (
    $fileName && @is_file($fileName))    {
                if (
    $import->loadFile($fileName,true)) {
                    
    $this->cli_echo('Importing "'.$fileName.'"');

                    
    $this->registerHandler($hooks['after_writeRecordsPages'], 'showErrors');
                    
    $this->registerHandler($hooks['after_writeRecordsPagesOrder'], 'showErrors');
                    
    $this->registerHandler($hooks['after_writeRecordsRecords'], 'showErrors');
                    
    $this->registerHandler($hooks['after_writeRecordsRecordsOrder'], 'showErrors');

                    
    $import->importData($pid);
                } else {
                    
    $this->cli_echo('Can\'t load file "'.$fileName.'"');
                }
            } else {
                
    $this->cli_echo('File "'.$fileName.'" not found');
            }
        }

        function 
    showErrors(&$params, &$reference) {
            if (
    $params['tce'] && $params['tce']->errorLog) {
                foreach (
    $params['tce']->errorLog as $error) {
                    
    $this->cli_echo($error);
                }
            }
        }
    }

    // Call the functionality
    $cleanerObj t3lib_div::makeInstance('tx_weeshell_cli');
    $cleanerObj->cli_main($_SERVER['argv']);

    ?>

  3. #3
    Forum Zuschauer
    Registriert seit
    02.11.2011
    Beiträge
    3
    Hallo,

    hier noch eine kleine Ergänzung, da ich ohne volle Administrationsrechte erhebliche Probleme bekomme, alle möglichen Arten von Datensätzen (z.B. be_users) mittels .t3d- oder .xml-Dateien zu importieren. Daher habe ich mittels XCLASS die Methode t3lib_beuserauth::checkCLIuser() so überschrieben, dass auch Adminkonten über das CLI verwendet werden können.

    Allerdings kann ich derzeit nicht abschätzen, ob ich damit eine gravierende Sicherheitslücke erzeuge? Im ersten Ansatz dachte ich mir schlicht, solange ich über das Dateisystem, die Rechte korrekt setze, sollten keine Probleme entstehen. In Summe muss ich gestehen, dass die eingebauten Sicherheitsrestriktionen für das CLI mir nicht schmecken, aber ich vermute, dass diese nicht ohne Grund eingebaut wurden?


    Liebe Grüße

 

 

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Facebook Kommentare

Ähnliche Themen

  1. CLI ohne exec() möglich? Scheduler per http im safe mode.
    Von vbmazter im Forum TYPO3 4.x Fragen und Probleme
    Antworten: 5
    Letzter Beitrag: 06.04.2011, 16:47
  2. Benutzung Command Line Interface (CLI)
    Von ichbinsdoch im Forum TYPO3 4.x Backend
    Antworten: 1
    Letzter Beitrag: 08.07.2006, 15:36

Stichworte

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238