|
eZ Publish
[4.0]
|
00001 #!/usr/bin/env php 00002 <?php 00003 // 00004 // Created on: <19-Mar-2004 09:51:56 amos> 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 //include_once( 'lib/ezutils/classes/ezcli.php' ); 00031 //include_once( 'kernel/classes/ezscript.php' ); 00032 00033 require 'autoload.php'; 00034 00035 $cli = eZCLI::instance(); 00036 $script = eZScript::instance( array( 'description' => ( "eZ Publish Code Template Generator\n\n" . 00037 "This will apply any template blocks it finds in files\n" . 00038 "and writes back the new file\n" . 00039 "\n" . 00040 "The return code is set to 0 if no changes occured, 1 if a file is changed\n" . 00041 "or 2 if an error occurs" ), 00042 'use-session' => false, 00043 'use-modules' => true, 00044 'use-extensions' => true ) ); 00045 00046 $script->startup(); 00047 00048 $options = $script->getOptions( "[a|all][check-only]", 00049 "[file]", 00050 array( 'all' => 'Go trough all files defined in codetemplate.ini', 00051 'check-only' => 'Will only check if the files will be changed or have errors' ) ); 00052 $script->initialize(); 00053 00054 if ( !$options['all'] and count( $options['arguments'] ) < 1 ) 00055 { 00056 $cli->error( "Need at least one file" ); 00057 $script->shutdown( 1 ); 00058 } 00059 00060 //include_once( 'kernel/classes/ezcodetemplate.php' ); 00061 00062 $hasErrors = false; 00063 $hasModified = false; 00064 00065 $tpl = new eZCodeTemplate(); 00066 00067 if ( $options['all'] ) 00068 { 00069 $files = $tpl->allCodeFiles(); 00070 } 00071 else 00072 { 00073 $files = $options['arguments']; 00074 } 00075 00076 foreach ( $files as $file ) 00077 { 00078 $status = $tpl->apply( $file, $options['check-only'] ); 00079 if ( $status == eZCodeTemplate::STATUS_OK ) 00080 { 00081 $cli->output( "Updated " . $cli->stylize( 'file', $file ) ); 00082 $hasModified = true; 00083 } 00084 else if ( $status == eZCodeTemplate::STATUS_NO_CHANGE ) 00085 { 00086 $cli->output( "No change in " . $cli->stylize( 'file', $file ) ); 00087 } 00088 else if ( $status == eZCodeTemplate::STATUS_FAILED ) 00089 { 00090 $cli->output( "Template errors for " . $cli->stylize( 'file', $file ) ); 00091 $hasErrors = true; 00092 } 00093 } 00094 00095 if ( $hasErrors ) 00096 $script->shutdown( 2 ); 00097 else if ( $hasModified ) 00098 $script->shutdown( 1 ); 00099 00100 $script->shutdown(); 00101 00102 ?>