eZ Publish  [4.0]
ezsqldumpisbndata.php
Go to the documentation of this file.
00001 #!/usr/bin/env php
00002 <?php
00003 //
00004 // Created on: <30-May-2007 16:19:12 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 writeisbn13schema.php
00031 */
00032 
00033 /*!
00034   \class Writeisbn13schema writeisbn13schema.php
00035   \brief The class Writeisbn13schema does
00036 
00037 */
00038 
00039 //include_once( 'lib/ezdbschema/classes/ezdbschema.php' );
00040 //include_once( 'lib/ezdb/classes/ezdb.php' );
00041 //include_once( 'lib/ezutils/classes/ezcli.php' );
00042 
00043 //include_once( 'kernel/classes/ezscript.php' );
00044 
00045 require 'autoload.php';
00046 
00047 $fileNameDba = 'db_data.dba';
00048 $fileNameSql = 'cleandata.sql';
00049 $stdOutSQL = null;
00050 $stdOutDBA = null;
00051 
00052 $cli = eZCLI::instance();
00053 $script = eZScript::instance( array( 'description' => ( "eZ Publish SQL Isbn data dump\n\n" .
00054                                                         "Dump sql data to file or standard output from the tables:\n" .
00055                                                         "  ezisbn_group\n" .
00056                                                         "  ezisbn_group_range\n" .
00057                                                         "  ezisbn_registrant_range\n\n" .
00058                                                         "Default is file, wich will be written to:\n" .
00059                                                         "  kernel/classes/datatypes/ezisbn/sql/<database>/cleandata.sql\n" .
00060                                                         "  kernel/classes/datatypes/ezisbn/share/db_data.dba\n\n" .
00061                                                         "Script can be runned as:\n" .
00062                                                         "php bin/php/ezsqldumpisbndata.php --stdout-sql\n" .
00063                                                         "                                  --stdout-dba\n" .
00064                                                         "                                  --filename-sql=customname.sql\n" .
00065                                                         "                                  --filename-dba=customname.dba" ),
00066                                      'use-session' => false,
00067                                      'use-modules' => true,
00068                                      'use-extensions' => true ) );
00069 
00070 $script->startup();
00071 
00072 $options = $script->getOptions( "[stdout-sql][stdout-dba][filename-sql:][filename-dba:]", "",
00073                                 array( 'stdout-sql' => "Result of sql output will be printed to standard output instead of to file.",
00074                                        'stdout-dba' => "Result of dba output will be printed to standard output instead of to file.",
00075                                        'filename-sql' => "Custom name for the sql file. Will be stored in the directory: \n" .
00076                                                          "kernel/classes/datatypes/ezisbn/sql/<database>/",
00077                                        'filename-dba' => "Custom name for the dba file. Will be stored in the directory: \n" .
00078                                                          "kernel/classes/datatypes/ezisbn/share/" ) );
00079 $script->initialize();
00080 $db = eZDB::instance();
00081 $dbSchema = eZDbSchema::instance( $db );
00082 
00083 if ( isset( $options['filename-sql'] ) )
00084 {
00085     $fileNameSql = $options['filename-sql'];
00086 }
00087 
00088 if ( isset( $options['filename-dba'] ) )
00089 {
00090     $fileNameDba = $options['filename-dba'];
00091 }
00092 
00093 if ( isset( $options['stdout-sql'] ) !== null )
00094 {
00095     $stdOutSQL = $options['stdout-sql'];
00096 }
00097 
00098 if ( isset( $options['stdout-dba'] ) !== null )
00099 {
00100     $stdOutDBA = $options['stdout-dba'];
00101 }
00102 
00103 $tableType = 'MyISAM';
00104 if ( $db->databaseName() != "mysql" )
00105 {
00106     $tableType = null;
00107 }
00108 
00109 $includeSchema = false;
00110 $includeData = true;
00111 
00112 $dbschemaParameters = array( 'schema' => $includeSchema,
00113                              'data' => $includeData,
00114                              'format' => 'generic',
00115                              'meta_data' => null,
00116                              'table_type' => $tableType,
00117                              'table_charset' => null,
00118                              'compatible_sql' => true,
00119                              'allow_multi_insert' => null,
00120                              'diff_friendly' => null,
00121                              'table_include' => array( 'ezisbn_group',
00122                                                        'ezisbn_group_range',
00123                                                        'ezisbn_registrant_range' ) );
00124 
00125 if ( $stdOutDBA === null and $stdOutSQL === null )
00126 {
00127     $path = 'kernel/classes/datatypes/ezisbn/sql/' . $db->databaseName() . '/';
00128     $file = $path . $fileNameSql;
00129     $dbSchema->writeSQLSchemaFile( $file,
00130                                    $dbschemaParameters );
00131     $cli->output( 'Write "' . $file . '" to disk.' );
00132 
00133     $path = 'kernel/classes/datatypes/ezisbn/share/';
00134     $file = $path . $fileNameDba;
00135 
00136     // Add the table schema.
00137     $dbSchema->writeArraySchemaFile( $file,
00138                                      $dbschemaParameters );
00139     $cli->output( 'Write "' . $file . '" to disk.' );
00140 }
00141 else
00142 {
00143     $filename = 'php://stdout';
00144     if ( $stdOutSQL !== null )
00145     {
00146         $dbSchema->writeSQLSchemaFile( $filename,
00147                                        $dbschemaParameters );
00148     }
00149 
00150     if ( $stdOutDBA !== null )
00151     {
00152         $dbschemaParameters['schema'] = true;
00153         $dbSchema->writeArraySchemaFile( $filename,
00154                                          $dbschemaParameters );
00155     }
00156 }
00157 
00158 
00159 $script->shutdown();
00160 ?>