[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 #!/usr/bin/env php 2 <?php 3 // 4 // Definition of updateeztimetype 5 // 6 // Created on: <17-May-2005 10:40:00 rl> 7 // 8 // SOFTWARE NAME: eZ publish 9 // SOFTWARE RELEASE: 3.9.0 10 // BUILD VERSION: 17785 11 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 12 // SOFTWARE LICENSE: GNU General Public License v2.0 13 // NOTICE: > 14 // This program is free software; you can redistribute it and/or 15 // modify it under the terms of version 2.0 of the GNU General 16 // Public License as published by the Free Software Foundation. 17 // 18 // This program is distributed in the hope that it will be useful, 19 // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 // GNU General Public License for more details. 22 // 23 // You should have received a copy of version 2.0 of the GNU General 24 // Public License along with this program; if not, write to the Free 25 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 26 // MA 02110-1301, USA. 27 // 28 // 29 30 /*! \file updateiscontainer.php 31 */ 32 33 include_once ( 'lib/ezutils/classes/ezcli.php' ); 34 include_once ( 'kernel/classes/ezscript.php' ); 35 36 37 $cli =& eZCLI::instance(); 38 $script =& eZScript::instance( array( 'description' => ( "eZ publish eZTimeType update script\n\n" . 39 "This script will transform all eZTimeType attributes value\n" . 40 "from GMT to the server local time.\n Please backup your database" . 41 "before to restore your old values if results will something else" . 42 "you expect.". 43 "\n" . 44 "Note: The script must be run for each siteaccess" . 45 "\n" . 46 "updateeztimetype.php -sSITEACCESS" ), 47 'use-session' => false, 48 'use-modules' => true, 49 'use-extensions' => true, 50 'min_version' => '3.4.7', 51 'max_version' => '3.5.3' ) ); 52 53 $script->startup(); 54 55 $options = $script->getOptions( "", "", array() ); 56 57 $script->initialize(); 58 59 if ( !$script->validateVersion() ) 60 { 61 $cli->output( "Unsuitable eZ publish version: " ); 62 $cli->output( eZPublishSDK::version() ); 63 $script->shutdown( 1 ); 64 } 65 66 include_once ( 'lib/ezlocale/classes/eztime.php' ); 67 include_once ( 'kernel/classes/ezcontentobjectattribute.php' ); 68 69 $db =& eZDB::instance(); 70 71 if ( !is_object( $db ) ) 72 { 73 $cli->error( 'Could not initialize database:' ); 74 $script->shutdown( 1 ); 75 } 76 77 $times_array = eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(), 78 /*$field_filters =*/null, 79 /*$conds =*/array( 'data_type_string' => 'eztime' ), 80 /*$sorts =*/null, 81 /*$limit =*/null, 82 /*$asObject =*/false, 83 /*$grouping =*/false, 84 /*$custom_fields =*/null ); 85 86 $timezone_offset = date( 'Z' ); 87 $count_updated = 0; 88 89 $cli->output( "Timezone offset: $timezone_offset sec." ); 90 $cli->output( "\nUpdating eZTimeType attributes..." ); 91 92 foreach( $times_array as $item ) 93 { 94 // if attribute was already update the clear old flag and skip it: 95 if ( $item[ 'data_float' ] == 1 ) 96 { 97 $sql = "UPDATE ezcontentobject_attribute " . 98 "SET data_float=0 " . 99 "WHERE id=" . $item[ 'id' ]; 100 101 if ( !$db->query( $sql ) ) 102 { 103 $cli->error( "Failed to run update query..." ); 104 $cli->error( $db->errorMessage() ); 105 } 106 continue; 107 } 108 109 $oldtimestamp = $item[ 'data_int' ]; 110 $timestamp = $item[ 'data_int' ]; 111 112 if ( !is_null( $timestamp ) ) 113 { 114 // if time stamp more when 24 hours then identify 115 // it as old style full timestamp, and update it 116 if ( $timestamp >= EZTIME_SECONDS_A_DAY ) 117 { 118 $date = getdate( $timestamp ); 119 $timestamp = $date[ 'hours' ] * EZTIME_SECONDS_AN_HOUR + 120 $date[ 'minutes' ] * EZTIME_SECONDS_A_MINUTE + 121 $date[ 'seconds' ]; 122 } 123 else 124 { 125 $timestamp = ( $timestamp + $timezone_offset ) % EZTIME_SECONDS_A_DAY; 126 } 127 } 128 129 if ( $timestamp != $oldtimestamp ) 130 { 131 $sql = "UPDATE ezcontentobject_attribute " . 132 "SET data_int=$timestamp, " . 133 "sort_key_int=$timestamp, " . 134 "data_float=0 " . 135 "WHERE id=" . $item[ 'id' ]; 136 137 if ( !$db->query( $sql ) ) 138 { 139 $cli->error( "Failed to run update query..." ); 140 $cli->error( $db->errorMessage() ); 141 142 if ( $count_updated > 0 ) 143 { 144 $cli->output( "The update are not finished properly and attributes are\n" . 145 "updated partially. Check you settings and restore your\n" . 146 "database from backup before running script again" ); 147 } 148 $script->shutdown( 1 ); 149 } 150 151 $cli->output( "contentobject_id = " . $item[ 'contentobject_id' ] . ", " . 152 "attribute id = " . $item[ 'id' ] . ": " . 153 "old_timestamp = $oldtimestamp, new_timestamp = $timestamp" ); 154 155 $count_updated++; 156 } 157 } 158 159 160 $cli->output( "\nNumber of updated eZTimeType attributes: $count_updated" ); 161 $script->shutdown(); 162 163 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |