eZ Publish  [4.0]
updatevatcountries.php
Go to the documentation of this file.
00001 #!/usr/bin/env php
00002 <?php
00003 //
00004 // Created on: <9-Jul-2007 14:00:25 dp>
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 require 'autoload.php';
00031 
00032 $cli = eZCLI::instance();
00033 $script = eZScript::instance( array( 'description' => ( "eZ Publish Country update script\n\n" .
00034                                                         "Upgrades db table in addition with upgrade from 3.9.2 to 3.9.3\n" .
00035                                                         "Fixes bug with aplying VAT rules" ),
00036                                       'use-session' => false,
00037                                       'use-modules' => true,
00038                                       'use-extensions' => true ) );
00039 $script->startup();
00040 
00041 $options = $script->getOptions(  );
00042 
00043 $script->initialize();
00044 
00045 $db = eZDB::instance();
00046 
00047 $countries = $db->arrayQuery( "SELECT country_code from ezvatrule;" );
00048 $iniCountries = eZCountryType::fetchCountryList();
00049 
00050 $updatedRules = 0;
00051 
00052 foreach ( $countries as $country )
00053 {
00054     foreach ( $iniCountries as $iniCountry )
00055     {
00056         if ( $iniCountry['Name'] == $country['country_code'] )
00057         {
00058             $countryName = $country['country_code'];
00059             $countryCode = $iniCountry['Alpha2'];
00060             $db->query( "UPDATE ezvatrule SET country_code='" . $db->escapeString( $countryCode ) . "' WHERE country_code='" . $db->escapeString( $countryName ) . "'" );
00061             $updatedRules++;
00062         }
00063     }
00064 }
00065 
00066 $cli->output( 'Updated VAT rules: ' . $updatedRules );
00067 
00068 $script->shutdown();
00069 
00070 ?>