eZ Publish  [4.0]
ezimportdbafile.php
Go to the documentation of this file.
00001 #!/usr/bin/env php
00002 <?php
00003 //
00004 // Created on: <27-Jul-2007 09:29:16 bjorn>
00005 //
00006 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00007 // SOFTWARE NAME: eZ Publish
00008 // SOFTWARE RELEASE: 4.0.x
00009 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00010 // SOFTWARE LICENSE: GNU General Public License v2.0
00011 // NOTICE: >
00012 //   This program is free software; you can redistribute it and/or
00013 //   modify it under the terms of version 2.0  of the GNU General
00014 //   Public License as published by the Free Software Foundation.
00015 //
00016 //   This program is distributed in the hope that it will be useful,
00017 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //   GNU General Public License for more details.
00020 //
00021 //   You should have received a copy of version 2.0 of the GNU General
00022 //   Public License along with this program; if not, write to the Free
00023 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 //   MA 02110-1301, USA.
00025 //
00026 //
00027 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00028 //
00029 
00030 /*! \file ezimportdbafile.php
00031 */
00032 
00033 //include_once( 'lib/ezutils/classes/ezcli.php' );
00034 //include_once( 'kernel/classes/ezscript.php' );
00035 //include_once( 'kernel/classes/ezdatatype.php' );
00036 
00037 require 'autoload.php';
00038 
00039 $cli = eZCLI::instance();
00040 $script = eZScript::instance( array( 'description' => ( "eZ Publish datatype sql update\n\n" .
00041                                                         "Script can be runned as:\n" .
00042                                                         "bin/php/ezimportdbafile.php --datatype=\n\n" .
00043                                                         "Example: bin/php/ezimportdbafile.php --datatype=ezisbn" ),
00044                                      'use-session' => false,
00045                                      'use-modules' => true,
00046                                      'use-extensions' => true ) );
00047 
00048 $script->startup();
00049 
00050 $options = $script->getOptions( "[datatype:]", "",
00051                                 array( 'datatype' => "The name of the datatype where the database should be updated." ) );
00052 $script->initialize();
00053 $dataTypeName = $options['datatype'];
00054 
00055 if ( $dataTypeName === null )
00056 {
00057     $cli->output( "Error: The option --datatype is required. Add --help for more information." );
00058 }
00059 
00060 $allowedDatatypes = eZDataType::allowedTypes();
00061 if ( $dataTypeName !== null and
00062      in_array( $dataTypeName, $allowedDatatypes ) )
00063 {
00064     // Inserting data from the dba-data files of the datatypes
00065     eZDataType::loadAndRegisterAllTypes();
00066     $registeredDataTypes = eZDataType::registeredDataTypes();
00067 
00068     if ( isset( $registeredDataTypes[$dataTypeName] ) )
00069     {
00070         $dataType = $registeredDataTypes[$dataTypeName];
00071         if ( $dataType->importDBDataFromDBAFile() )
00072         {
00073             $cli->output( "The database is updated for the datatype: " .
00074                           $cli->style( 'emphasize' ) . $dataType->DataTypeString . $cli->style( 'emphasize-end' ) . "\n" .
00075                           'dba-data is imported from the file: ' .
00076                           $cli->style( 'emphasize' ) . $dataType->getDBAFilePath() .  $cli->style( 'emphasize-end' ) );
00077         }
00078         else
00079         {
00080             include_once( 'lib/ezutils/classes/ezextension.php' );
00081             $activeExtensions = eZExtension::activeExtensions();
00082             $errorString = "Failed importing datatype related data into database: \n" .
00083                            '  datatype - ' . $dataType->DataTypeString . ", \n" .
00084                            '  checked dba-data file - ' . $dataType->getDBAFilePath( false );
00085             foreach ( $activeExtensions as $activeExtension )
00086             {
00087                 $fileName = eZExtension::baseDirectory() . '/' . $activeExtension .
00088                             '/datatypes/' . $dataType->DataTypeString . '/' . $dataType->getDBAFileName();
00089                 $errorString .= "\n" . str_repeat( ' ', 23 ) . ' - ' . $fileName;
00090                 if ( file_exists( $fileName ) )
00091                 {
00092                     $errorString .= " (found, but not successfully imported)";
00093                 }
00094             }
00095 
00096             $cli->error( $errorString );
00097         }
00098     }
00099     else
00100     {
00101         $cli->error( "Error: The datatype " . $dataTypeName . " does not exist." );
00102     }
00103 }
00104 else
00105 {
00106     $cli->error( "Error: The datatype " . $dataTypeName . " is not registered." );
00107 }
00108 $script->shutdown();
00109 
00110 ?>