| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 #!/usr/bin/env php 2 <?php 3 // 4 // Created on: <22-Aug-2006 12:05:27 ks> 5 // 6 // SOFTWARE NAME: eZ publish 7 // SOFTWARE RELEASE: 3.9.0 8 // BUILD VERSION: 17785 9 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 10 // SOFTWARE LICENSE: GNU General Public License v2.0 11 // NOTICE: > 12 // This program is free software; you can redistribute it and/or 13 // modify it under the terms of version 2.0 of the GNU General 14 // Public License as published by the Free Software Foundation. 15 // 16 // This program is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU General Public License for more details. 20 // 21 // You should have received a copy of version 2.0 of the GNU General 22 // Public License along with this program; if not, write to the Free 23 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 24 // MA 02110-1301, USA. 25 // 26 // 27 28 define( "QUERY_LIMIT", 100 ); 29 30 if( !file_exists( 'update/common/scripts' ) || !is_dir( 'update/common/scripts' ) ) 31 { 32 echo "Please run this script from the root document directory!\n"; 33 exit; 34 } 35 36 include_once ( 'lib/ezutils/classes/ezcli.php' ); 37 include_once ( 'kernel/classes/ezscript.php' ); 38 39 $cli =& eZCLI::instance(); 40 41 $script =& eZScript::instance( array( 'description' => "\nThis script performs tasks needed to upgrade to 3.9:\n" . 42 "\n- Converting <object> tags to <embed> tags" . 43 "\n- Adding existing 'class' attibute values to AvailableClasses arrays of content.ini" . 44 "\n- Adding existing custom attibutes to CustomAttributes arrays of content.ini\n" . 45 "\nYou can optionally perform only some of these tasks.", 46 'use-session' => false, 47 'use-modules' => false, 48 'use-extensions' => true ) ); 49 50 $script->startup(); 51 52 $options = $script->getOptions( "[db-host:][db-user:][db-password:][db-database:][db-type:][skip-objects][skip-classes][classes-dump-only][skip-custom][custom-dump-only][global]", 53 "", 54 array( 'db-host' => "Database host", 55 'db-user' => "Database user", 56 'db-password' => "Database password", 57 'db-database' => "Database name", 58 'db-type' => "Database type, e.g. mysql or postgresql", 59 'skip-objects' => "Skip converting <object> tags.", 60 'skip-classes' => "Skip checking and updating AvailableClasses settings of content.ini.", 61 'classes-dump-only' => "Check available classes lists, but do not update content.ini. Results will be displayed in the output.", 62 'skip-custom' => "Skip checking and updating CustomAttributes settings of content.ini.", 63 'custom-dump-only' => "Check available custom attributes lists, but do not update content.ini. Results will be displayed in the output.", 64 'global' => "Update global override content.ini.append instead of siteaccess" 65 ) ); 66 $script->initialize(); 67 68 $dbUser = $options['db-user']; 69 $dbPassword = $options['db-password']; 70 $dbHost = $options['db-host']; 71 $dbName = $options['db-database']; 72 $dbImpl = $options['db-type']; 73 74 $skipClasses = $options['skip-classes']; 75 $classesDumpOnly = $options['classes-dump-only']; 76 $skipCustom = $options['skip-custom']; 77 $customDumpOnly = $options['custom-dump-only']; 78 $skipObjects = $options['skip-objects']; 79 80 $global = $options['global']; 81 82 $isQuiet = $script->isQuiet(); 83 84 if ( $dbHost or $dbName or $dbUser or $dbImpl ) 85 { 86 $params = array( 'use_defaults' => false ); 87 if ( $dbHost !== false ) 88 $params['server'] = $dbHost; 89 if ( $dbUser !== false ) 90 { 91 $params['user'] = $dbUser; 92 $params['password'] = ''; 93 } 94 if ( $dbPassword !== false ) 95 $params['password'] = $dbPassword; 96 if ( $dbName !== false ) 97 $params['database'] = $dbName; 98 99 $db =& eZDB::instance( $dbImpl, $params, true ); 100 eZDB::setInstance( $db ); 101 } 102 else 103 { 104 $db =& eZDB::instance(); 105 } 106 107 if ( !$db->isConnected() ) 108 { 109 $cli->error( "Can't initialize database connection.\n" ); 110 $script->shutdown( 1 ); 111 } 112 113 include_once ( 'lib/ezxml/classes/ezxml.php' ); 114 include_once ( 'kernel/classes/datatypes/ezxmltext/ezxmltexttype.php' ); 115 116 include_once ( 'lib/version.php' ); 117 118 $eZPublishVersion = eZPublishSDK::majorVersion() + eZPublishSDK::minorVersion() * 0.1; 119 $siteaccess = $GLOBALS['eZCurrentAccess']['name']; 120 121 $xml = new eZXML(); 122 123 if ( !$skipClasses || !$skipCustom ) 124 { 125 $contentIni =& eZINI::instance( 'content.ini' ); 126 if ( $global ) 127 $iniPath = "settings/override"; 128 else 129 $iniPath = "settings/siteaccess/$siteaccess"; 130 $contentIniDirect =& eZINI::instance( 'content.ini.append', $iniPath, null, null, null, true, true ); 131 132 include_once ( 'kernel/classes/datatypes/ezxmltext/ezxmlschema.php' ); 133 $XMLSchema =& eZXMLSchema::instance(); 134 } 135 136 // update AvailableClasses setting 137 function updateAvailableClasses( &$doc, &$element, &$isIniModified, &$contentIniDirect, &$XMLSchema, $dumpOnly, $isQuiet = false ) 138 { 139 $children =& $element->Children; 140 foreach( array_keys( $children ) as $key ) 141 { 142 $child =& $children[$key]; 143 updateAvailableClasses( $doc, $child, $isIniModified, $contentIniDirect, $XMLSchema, $dumpOnly ); 144 } 145 146 $class = $element->getAttribute( 'class' ); 147 if ( !$class ) 148 return; 149 150 $classesList = $XMLSchema->getClassesList( $element->nodeName ); 151 if ( !in_array( $class, $classesList ) ) 152 { 153 if ( !$isQuiet ) 154 { 155 $cli =& eZCLI::instance(); 156 if ( $dumpOnly ) 157 $action = " is not defined."; 158 else 159 $action = " is added to the list."; 160 $cli->notice( "Element '$element->nodeName': class '$class'" . $action ); 161 } 162 163 $XMLSchema->addAvailableClass( $element->nodeName, $class ); 164 if ( !$dumpOnly ) 165 { 166 $classesList[] = $class; 167 $contentIniDirect->setVariable( $element->nodeName, 'AvailableClasses', $classesList ); 168 $isIniModified = true; 169 } 170 } 171 } 172 173 // update CustomAttributes setting 174 function updateCustomAttributes( &$doc, &$element, &$isIniModified, &$contentIniDirect, &$XMLSchema, $dumpOnly, $isQuiet = false ) 175 { 176 $children =& $element->Children; 177 foreach( array_keys( $children ) as $key ) 178 { 179 $child =& $children[$key]; 180 updateCustomAttributes( $doc, $child, $isIniModified, $contentIniDirect, $XMLSchema, $dumpOnly ); 181 } 182 183 if ( !$element->hasAttributes() ) 184 return; 185 186 $customAttrs = $XMLSchema->customAttributes( $element ); 187 $attrs =& $element->attributes(); 188 $newAttrFound = false; 189 foreach( $attrs as $attr ) 190 { 191 if ( $attr->Prefix == 'custom' && 192 !in_array( $attr->LocalName, $customAttrs ) ) 193 { 194 $newAttrFound = true; 195 $XMLSchema->addCustomAttribute( $element, $attr->LocalName ); 196 $customAttrs[] = $attr->LocalName; 197 if ( !$isQuiet ) 198 { 199 $cli =& eZCLI::instance(); 200 if ( $dumpOnly ) 201 $action = " is not defined."; 202 else 203 $action = " is added to the list."; 204 205 $cli->notice( "Element '$element->nodeName': custom attribute '$attr->LocalName'" . $action ); 206 } 207 } 208 } 209 210 if ( $newAttrFound && !$dumpOnly ) 211 { 212 if ( $element->nodeName == 'custom' ) 213 { 214 $contentIniDirect->setVariable( $element->getAttribute( 'name' ), 'CustomAttributes', $customAttrs ); 215 } 216 else 217 $contentIniDirect->setVariable( $element->nodeName, 'CustomAttributes', $customAttrs ); 218 $isIniModified = true; 219 } 220 } 221 222 223 function convertObjects( &$doc, &$element, &$isTextModified ) 224 { 225 $children =& $element->Children; 226 foreach( array_keys( $children ) as $key ) 227 { 228 $child =& $children[$key]; 229 convertObjects( $doc, $child, $isTextModified ); 230 } 231 232 // Convert 'objects' to 'embed' and 'embed-inline' 233 if ( $element->nodeName == 'object' ) 234 { 235 $objectID = $element->getAttribute( 'id' ); 236 $class = $element->getAttribute( 'class' ); 237 $size = $element->getAttribute( 'size' ); 238 $align = $element->getAttribute( 'align' ); 239 $view = $element->getAttribute( 'view' ); 240 241 $urlID = $element->getAttributeNS( 'http://ez.no/namespaces/ezpublish3/image/', 'ezurl_id' ); 242 $urlHref = $element->getAttributeNS( 'http://ez.no/namespaces/ezpublish3/image/', 'ezurl_href' ); 243 $urlTarget = $element->getAttributeNS( 'http://ez.no/namespaces/ezpublish3/image/', 'ezurl_target' ); 244 245 if ( $objectID ) 246 { 247 $embed =& $doc->createElement( 'embed' ); 248 $embed->setAttribute( 'object_id', $objectID ); 249 if ( $class ) 250 $embed->setAttribute( 'class', $class ); 251 if ( $size ) 252 $embed->setAttribute( 'size', $size ); 253 if ( $align ) 254 $embed->setAttribute( 'align', $align ); 255 if ( $view ) 256 $embed->setAttribute( 'view', $view ); 257 258 if ( $urlID || $urlHref ) 259 { 260 $link =& $doc->createElement( 'link' ); 261 if ( $urlID ) 262 $link->setAttribute( 'url_id', $urlID ); 263 elseif ( $urlHref ) 264 { 265 include_once ( 'kernel/classes/datatypes/ezurl/ezurl.php' ); 266 $urlHref = str_replace("&", "&", $urlHref ); 267 $urlID = eZURL::registerURL( $urlHref ); 268 $link->setAttribute( 'url_id', $urlID ); 269 } 270 if ( $urlTarget ) 271 $link->setAttribute( 'target', $urlTarget ); 272 273 $link->appendChild( $embed ); 274 $element->parentNode->insertBefore( $link, $element ); 275 } 276 else 277 { 278 $element->parentNode->insertBefore( $embed, $element ); 279 } 280 } 281 $element->parentNode->removeChild( $element ); 282 283 $isTextModified = true; 284 } 285 } 286 287 $isIniModified = false; 288 $totalAttrCount = 0; 289 290 $xmlFieldsQuery = "SELECT id, version, contentobject_id, data_text 291 FROM ezcontentobject_attribute 292 WHERE data_type_string = 'ezxmltext'"; 293 294 $xmlFieldsArray = $db->arrayQuery( $xmlFieldsQuery, array( "limit" => QUERY_LIMIT ) ); 295 if ( !is_array( $xmlFieldsArray ) ) 296 { 297 $cli->error( "SQL query error: $xmlFieldsQuery" ); 298 $script->shutdown( 1 ); 299 } 300 301 // We process the table by parts of QUERY_LIMIT number of records, $pass is the iteration number. 302 $pass = 1; 303 304 while( count( $xmlFieldsArray ) ) 305 { 306 foreach ( $xmlFieldsArray as $xmlField ) 307 { 308 $text = $xmlField['data_text']; 309 $doc =& $xml->domTree( $text, array( "TrimWhiteSpace" => false ) ); 310 311 if ( $doc ) 312 { 313 $isTextModified = false; 314 //fixParagraph( $doc, $doc->Root, $isTextModified ); 315 316 if ( !$skipObjects ) 317 convertObjects( $doc, $doc->Root, $isTextModified ); 318 319 if ( !$skipClasses ) 320 updateAvailableClasses( $doc, $doc->Root, $isIniModified, $contentIniDirect, $XMLSchema, $classesDumpOnly, $isQuiet ); 321 322 if ( !$skipCustom && $eZPublishVersion >= 3.9 ) 323 updateCustomAttributes( $doc, $doc->Root, $isIniModified, $contentIniDirect, $XMLSchema, $customDumpOnly, $isQuiet ); 324 325 if ( $isTextModified ) 326 { 327 $result = eZXMLTextType::domString( $doc ); 328 $sql = "UPDATE ezcontentobject_attribute SET data_text='" . $result . 329 "' WHERE id=" . $xmlField['id'] . " AND version=" . $xmlField['version']; 330 $db->query( $sql ); 331 332 if ( !$isQuiet ) 333 $cli->notice( "<object> tag(s) have been converted. Object ID: " . $xmlField['contentobject_id'] . ", version: ". $xmlField['version'] . 334 ", attribute ID :" . $xmlField['id'] ); 335 $totalAttrCount++; 336 } 337 $doc->cleanup(); 338 } 339 unset( $doc ); 340 } 341 $xmlFieldsArray = $db->arrayQuery( $xmlFieldsQuery, array( "limit" => QUERY_LIMIT, "offset" => $pass * QUERY_LIMIT ) ); 342 if ( !is_array( $xmlFieldsArray ) ) 343 { 344 $cli->error( "SQL query error: $xmlFieldsQuery" ); 345 $script->shutdown( 1 ); 346 } 347 $pass++; 348 } 349 350 if ( $isIniModified ) 351 { 352 $saved = $contentIniDirect->save(); 353 if ( !$saved && !$isQuiet ) 354 $cli->error( "\nCan't save ini file: '$iniPath/content.ini.append(.php)' !" ); 355 elseif ( !$isQuiet ) 356 $cli->notice( "\nSettings file '$iniPath/content.ini.append' has been updated." ); 357 } 358 elseif( ( !$skipClasses && !$classesDumpOnly ) || ( !$skipCustom && !$customDumpOnly ) ) 359 { 360 $cli->notice( "\ncontent.ini settings: OK" ); 361 } 362 363 if ( !$skipObjects && !$isQuiet ) 364 { 365 if ( $totalAttrCount ) 366 $cli->notice( "\nTotal: " . $totalAttrCount . " attribute(s) have been converted." ); 367 else 368 $cli->notice( "\nXML text blocks: OK" ); 369 } 370 371 $cli->notice( "\nDone." ); 372 373 $script->shutdown(); 374 375 ?>
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 |