| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 #!/usr/bin/env php 2 <?php 3 // 4 // Created on: <31-Mar-2005 12:24:01 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 /*! \file convertxmllinks.php 29 Database converter for eZ publish 3.6. 30 Don't forget to update database structute before running this script. 31 32 Updates 'ezcontentobject_link' table by adding related objects links made with 33 attributes of 'ezobjectrelation' and 'ezobjectrelationlist' types. 34 35 You should run this script before using a database created with eZ publish 36 version 3.5.* or lower. 37 */ 38 39 define( "QUERY_LIMIT", 100 ); 40 41 if( !file_exists( 'update/common/scripts' ) || !is_dir( 'update/common/scripts' ) ) 42 { 43 echo "Please run this script from the root document directory!\n"; 44 exit; 45 } 46 47 include_once ( 'lib/ezutils/classes/ezcli.php' ); 48 include_once ( 'kernel/classes/ezscript.php' ); 49 50 $cli =& eZCLI::instance(); 51 52 $script =& eZScript::instance( array( 'description' => ( "\nDatabase converter for eZ publish 3.6.\n" . 53 "Updates 'ezcontentobject_link' table by adding related objects links made with\n" . 54 "attributes of 'ezobjectrelation' and 'ezobjectrelationlist' types.\n\n" . 55 "Run this script before using a database created with eZ publish version 3.5.* or lower.\n" . 56 "Don't forget to update database's structure before running this script." ), 57 'use-session' => false, 58 'use-modules' => false, 59 'use-extensions' => false ) ); 60 61 $script->startup(); 62 63 $options = $script->getOptions( "[db-host:][db-user:][db-password:][db-database:][db-driver:]", 64 "", 65 array( 'db-host' => "Database host", 66 'db-user' => "Database user", 67 'db-password' => "Database password", 68 'db-database' => "Database name", 69 'db-driver' => "Database driver" 70 ) ); 71 $script->initialize(); 72 73 $dbUser = $options['db-user'] ? $options['db-user'] : false; 74 $dbPassword = $options['db-password'] ? $options['db-password'] : false; 75 $dbHost = $options['db-host'] ? $options['db-host'] : false; 76 $dbName = $options['db-database'] ? $options['db-database'] : false; 77 $dbImpl = $options['db-driver'] ? $options['db-driver'] : false; 78 $siteAccess = $options['siteaccess'] ? $options['siteaccess'] : false; 79 $isQuiet = $script->isQuiet(); 80 81 if ( $siteAccess ) 82 { 83 changeSiteAccessSetting( $siteaccess, $siteAccess ); 84 } 85 86 function changeSiteAccessSetting( &$siteaccess, $optionData ) 87 { 88 global $isQuiet; 89 $cli =& eZCLI::instance(); 90 if ( file_exists( 'settings/siteaccess/' . $optionData ) ) 91 { 92 $siteaccess = $optionData; 93 if ( !$isQuiet ) 94 $cli->notice( "Using siteaccess $siteaccess." ); 95 } 96 else 97 { 98 if ( !$isQuiet ) 99 $cli->notice( "Siteaccess $optionData does not exist, using default siteaccess" ); 100 } 101 } 102 103 if ( $dbHost or $dbName or $dbUser or $dbImpl ) 104 { 105 $params = array(); 106 if ( $dbHost !== false ) 107 $params['server'] = $dbHost; 108 if ( $dbUser !== false ) 109 { 110 $params['user'] = $dbUser; 111 $params['password'] = ''; 112 } 113 if ( $dbPassword !== false ) 114 $params['password'] = $dbPassword; 115 if ( $dbName !== false ) 116 $params['database'] = $dbName; 117 $db =& eZDB::instance( $dbImpl, $params, true ); 118 if ( !$db ) 119 { 120 $cli->notice( "Can't initialize database connection.\n" ); 121 $script->shutdown(); 122 } 123 eZDB::setInstance( $db ); 124 } 125 else 126 { 127 $db =& eZDB::instance(); 128 if ( !$db ) 129 { 130 $cli->notice( "Can't initialize database connection.\n" ); 131 $script->shutdown(); 132 } 133 } 134 135 include_once ( 'kernel/classes/ezcontentobjectattribute.php' ); 136 include_once ( 'lib/ezxml/classes/ezxml.php' ); 137 138 $links = array(); 139 $added_links_count = 0; 140 $links_total = 0; 141 142 function updateLinks() 143 { 144 global $added_links_count, $links, $db, $isQuiet, $cli; 145 146 foreach( $links as $link ) 147 { 148 $fromObjectID = $link['fromObjectID']; 149 $fromObjectVersion = $link['fromObjectVersion']; 150 $toObjectID = $link['toObjectID']; 151 $attributeID = $link['attributeID']; 152 153 $result = $db->arrayQuery( "SELECT ( COUNT( ezcontentobject_link.id ) ) AS count 154 FROM ezcontentobject_link 155 WHERE from_contentobject_id=$fromObjectID AND 156 from_contentobject_version=$fromObjectVersion AND 157 to_contentobject_id=$toObjectID AND 158 contentclassattribute_id=$attributeID" ); 159 160 $count = $result[0]['count']; 161 if ( !$count ) 162 { 163 $db->query( "INSERT INTO ezcontentobject_link ( from_contentobject_id, from_contentobject_version, to_contentobject_id, contentclassattribute_id ) 164 VALUES ( $fromObjectID, $fromObjectVersion, $toObjectID, $attributeID )" ); 165 $added_links_count++; 166 if ( !$isQuiet ) 167 $cli->notice( "Added link from object $fromObjectID, version $fromObjectVersion with attribute $attributeID to object $toObjectID" ); 168 } 169 } 170 } 171 172 $query = "SELECT attr.* 173 FROM ezcontentobject_attribute attr 174 WHERE attr.data_type_string='ezobjectrelation'"; 175 176 $result = $db->arrayQuery( $query, array( "limit" => QUERY_LIMIT ) ); 177 $pass = 1; 178 179 while( count( $result ) ) 180 { 181 $links = array(); 182 183 foreach( $result as $row ) 184 { 185 $attr = new eZContentObjectAttribute( $row ); 186 if ( $attr->attribute( 'data_int' ) ) 187 { 188 $links[] = array( 'fromObjectID' => $attr->attribute( 'contentobject_id' ), 189 'fromObjectVersion' => $attr->attribute( 'version' ), 190 'toObjectID' => $attr->attribute( 'data_int' ), 191 'attributeID' => $attr->attribute( 'contentclassattribute_id' ) ); 192 } 193 } 194 if ( count( $links ) ) 195 { 196 $links_total += count( $links ); 197 updateLinks(); 198 } 199 200 $result = $db->arrayQuery( $query, array( "limit" => QUERY_LIMIT, "offset" => $pass * QUERY_LIMIT ) ); 201 $pass++; 202 } 203 204 $query = "SELECT attr.* 205 FROM ezcontentobject_attribute attr 206 WHERE attr.data_type_string='ezobjectrelationlist'"; 207 208 $result = $db->arrayQuery( $query, array( "limit" => QUERY_LIMIT ) ); 209 $pass = 1; 210 211 while( count( $result ) ) 212 { 213 $links = array(); 214 215 foreach( $result as $row ) 216 { 217 $attr = new eZContentObjectAttribute( $row ); 218 if ( $attr->attribute( 'data_text' ) ) 219 { 220 $xml = new eZXML(); 221 $dom =& $xml->domTree( $attr->attribute( 'data_text' ) ); 222 223 $root =& $dom->root(); 224 $relationList =& $root->elementByName( 'relation-list' ); 225 if ( $relationList ) 226 { 227 $relationItems = $relationList->elementsByName( 'relation-item' ); 228 if ( count( $relationItems ) ) 229 { 230 foreach( $relationItems as $relationItem ) 231 { 232 $links[] = array( 'fromObjectID' => $attr->attribute( 'contentobject_id' ), 233 'fromObjectVersion' => $attr->attribute( 'version' ), 234 'toObjectID' => $relationItem->attributeValue( 'contentobject-id' ), 235 'attributeID' => $attr->attribute( 'contentclassattribute_id' ) ); 236 } 237 } 238 } 239 } 240 } 241 if ( count( $links ) ) 242 { 243 $links_total += count( $links ); 244 updateLinks(); 245 } 246 247 $result = $db->arrayQuery( $query, array( "limit" => QUERY_LIMIT, "offset" => $pass * QUERY_LIMIT ) ); 248 $pass++; 249 } 250 251 if ( !$isQuiet ) 252 $cli->notice( "\nFound $links_total references to related objects in attributes." ); 253 254 if ( !$isQuiet ) 255 if ( $added_links_count ) 256 $cli->notice( "$added_links_count links were added to 'ezcontentobject_link' table.\n" ); 257 else 258 $cli->notice( "No links were added.\n" ); 259 260 $script->shutdown(); 261 ?>
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 |