[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/bin/php/ -> ezsubtreecopy.php (source)

   1  #!/usr/bin/env php
   2  <?php
   3  //
   4  // Created on: <20-Feb-2005 15:00:00 rl>
   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  // Subtree Copy Script
  29  // file  bin/php/ezsubtreecopy.php
  30  
  31  // script initializing
  32  include_once ( 'lib/ezutils/classes/ezcli.php' );
  33  include_once ( 'kernel/classes/ezscript.php' );
  34  
  35  $cli =& eZCLI::instance();
  36  $script =& eZScript::instance( array( 'description' => ( "\n" .
  37                                                           "This script will make a copy of a content object subtree and place it in a specified\n" .
  38                                                           "location.\n" ),
  39                                        'use-session' => false,
  40                                        'use-modules' => true,
  41                                        'use-extensions' => true,
  42                                        'user' => true ) );
  43  $script->startup();
  44  
  45  $scriptOptions = $script->getOptions( "[src-node-id:][dst-node-id:][all-versions][keep-creator][keep-time]",
  46                                        "",
  47                                        array( 'src-node-id' => "Source subtree parent node ID.",
  48                                               'dst-node-id' => "Destination node ID.",
  49                                               'all-versions' => "Copy all versions for each contentobject being copied.",
  50                                               'keep-creator'=> "Do not change the creator (user) for the copied content objects.",
  51                                               'keep-time'   => "Do not change the creation and modification time of the copied content objects."
  52                                               ),
  53                                        false,
  54                                        array( 'user' => true )
  55                                       );
  56  $script->initialize();
  57  
  58  $srcNodeID   = $scriptOptions[ 'src-node-id' ] ? $scriptOptions[ 'src-node-id' ] : false;
  59  $dstNodeID   = $scriptOptions[ 'dst-node-id' ] ? $scriptOptions[ 'dst-node-id' ] : false;
  60  $allVersions = $scriptOptions[ 'all-versions' ];
  61  $keepCreator = $scriptOptions[ 'keep-creator' ];
  62  $keepTime    = $scriptOptions[ 'keep-time' ];
  63  
  64  include_once ( "lib/ezdb/classes/ezdb.php" );
  65  include_once ( "kernel/classes/ezcontentobjecttreenode.php" );
  66  
  67  function copyPublishContentObject( &$sourceObject,
  68                                      &$sourceSubtreeNodeIDList,
  69                                      &$syncNodeIDListSrc, &$syncNodeIDListNew,
  70                                      &$syncObjectIDListSrc, &$syncObjectIDListNew,
  71                                      $allVersions = false, $keepCreator = false, $keepTime = false )
  72  {
  73      global $cli;
  74  
  75      $sourceObjectID = $sourceObject->attribute( 'id' );
  76  
  77      $key = array_search( $sourceObjectID, $syncObjectIDListSrc );
  78      if ( $key !== false )
  79      {
  80          return 1; // object already copied
  81      }
  82  
  83      $srcNodeList = $sourceObject->attribute( 'assigned_nodes' );
  84  
  85      // check if all parent nodes for given contentobject are already published:
  86      foreach ( $srcNodeList as $srcNode )
  87      {
  88          $sourceParentNodeID = $srcNode->attribute( 'parent_node_id' );
  89  
  90          // if parent node for this node is outside
  91          // of subtree being copied, then skip this node.
  92          $key = array_search( $sourceParentNodeID, $sourceSubtreeNodeIDList );
  93          if ( $key === false )
  94          {
  95              continue;
  96          }
  97  
  98          $key = array_search( $sourceParentNodeID, $syncNodeIDListSrc );
  99          if ( $key === false )
 100          {
 101              return 2; // one of parent nodes is not published yet - have to try to publish later.
 102          }
 103          else
 104          {
 105              $newParentNodeID = $syncNodeIDListNew[ $key ];
 106              if ( ( $newParentNode = eZContentObjectTreeNode::fetch( $newParentNodeID ) ) === null )
 107              {
 108                  return 3; // cannot fetch one of parent nodes - must be error somewhere above.
 109              }
 110          }
 111      }
 112  
 113      // make copy of source object
 114      $newObject             = $sourceObject->copy( $allVersions ); // insert source and new object's ids in $syncObjectIDList
 115      // We should reset section that will be updated in updateSectionID().
 116      // If sectionID is 0 than the object has been newly created
 117      $newObject->setAttribute( 'section_id', 0 );
 118      $newObject->store();
 119  
 120      $syncObjectIDListSrc[] = $sourceObjectID;
 121      $syncObjectIDListNew[] = $newObject->attribute( 'id' );
 122  
 123      $curVersion        = $newObject->attribute( 'current_version' );
 124      $curVersionObject  = $newObject->attribute( 'current' );
 125  
 126      $newObjAssignments = $curVersionObject->attribute( 'node_assignments' );
 127  
 128      // copy nodeassigments:
 129      $assignmentsForRemoving = array();
 130      $foundMainAssignment = false;
 131      foreach ( $newObjAssignments as $assignment )
 132      {
 133          $parentNodeID = $assignment->attribute( 'parent_node' );
 134  
 135          // if assigment is outside of subtree being copied then do not copy this assigment
 136          $key = array_search( $parentNodeID, $sourceSubtreeNodeIDList );
 137          if ( $key === false )
 138          {
 139              $assignmentsForRemoving[] = $assignment->attribute( 'id' );
 140              continue;
 141          }
 142  
 143          $key = array_search( $parentNodeID, $syncNodeIDListSrc );
 144          if ( $key === false )
 145          {
 146              $cli->error( "Subtree Copy Error!\nOne of parent nodes for contentobject (ID = $sourceObjectID) is not published yet." );
 147              return 4;
 148          }
 149  
 150          if ( $assignment->attribute( 'is_main' ) )
 151              $foundMainAssignment = true;
 152  
 153          $newParentNodeID = $syncNodeIDListNew[ $key ];
 154          $assignment->setAttribute( 'parent_node', $newParentNodeID );
 155          $assignment->store();
 156      }
 157      // remove assigments which are outside of subtree being copied:
 158      eZNodeAssignment::purgeByID( $assignmentsForRemoving ); // JB valid
 159  
 160      // if main nodeassigment was not copied then set as main first nodeassigment
 161      if ( $foundMainAssignment == false )
 162      {
 163          $newObjAssignments = $curVersionObject->attribute( 'node_assignments' );
 164          // JB start
 165          // We need to check if it has any assignments before changing the data.
 166          if ( isset( $newObjAssignments[0] ) )
 167          {
 168              $newObjAssignments[0]->setAttribute( 'is_main', 1 );
 169              $newObjAssignments[0]->store();
 170          }
 171          // JB end
 172      }
 173  
 174      // publish the newly created object
 175      include_once ( 'lib/ezutils/classes/ezoperationhandler.php' );
 176      $result = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $newObject->attribute( 'id' ),
 177                                                                          'version'   => $curVersion ) );
 178      // JB start
 179      // Refetch the object data since it might change in the database.
 180      $newObjectID = $newObject->attribute( 'id' );
 181      $newObject =& eZContentObject::fetch( $newObjectID );
 182      // JB end
 183      $newNodeList =& $newObject->attribute( 'assigned_nodes' );
 184      if ( count($newNodeList) == 0 )
 185      {
 186          $newObject->purge();
 187          $cli->error( "Subtree Copy Error!\nCannot publish contentobject." );
 188          return 5;
 189      }
 190  
 191      $objAssignments = $curVersionObject->attribute( 'node_assignments' );
 192      foreach ( $newNodeList as $newNode )
 193      {
 194          $newParentNodeID = $newNode->attribute( 'parent_node_id' );
 195          $keyA = array_search( $newParentNodeID, $syncNodeIDListNew );
 196  
 197          if ( $keyA === false )
 198          {
 199              die( "Copy Subtree Error: Algoritm ERROR! Cannot find new parent node ID in new ID's list" );
 200          }
 201  
 202          $srcParentNodeID = $syncNodeIDListSrc[ $keyA ];
 203  
 204          // Update attributes of node
 205          $bSrcParentFound = false;
 206          foreach ( $srcNodeList as $srcNode )
 207          {
 208              if ( $srcNode->attribute( 'parent_node_id' ) == $srcParentNodeID )
 209              {
 210                  $newNode->setAttribute( 'priority',     $srcNode->attribute( 'priority' ) );
 211                  $newNode->setAttribute( 'is_hidden',    $srcNode->attribute( 'is_hidden' ) );
 212                  $newNode->setAttribute( 'is_invisible', $srcNode->attribute( 'is_invisible' ) );
 213                  $syncNodeIDListSrc[] = $srcNode->attribute( 'node_id' );
 214                  $syncNodeIDListNew[] = $newNode->attribute( 'node_id' );
 215                  $bSrcParentFound = true;
 216                  break;
 217              }
 218          }
 219          if ( $bSrcParentFound == false )
 220          {
 221              die( "Copy Subtree Error: Algoritm ERROR! Cannot find source parent node ID in source parent node ID's list of contentobject being copied." );
 222          }
 223          // Create unique remote_id
 224          $newRemoteID = md5( (string)mt_rand() . (string)mktime() );
 225          $oldRemoteID = $newNode->attribute( 'remote_id' );
 226          $newNode->setAttribute( 'remote_id', $newRemoteID );
 227          // Change parent_remote_id for object assignments
 228          foreach ( $objAssignments as $assignment )
 229          {
 230              if ( $assignment->attribute( 'parent_remote_id' ) == $oldRemoteID )
 231              {
 232                   $assignment->setAttribute( 'parent_remote_id', $newRemoteID );
 233                   $assignment->store();
 234              }
 235          }
 236          $newNode->store();
 237      }
 238  
 239      // Update "is_invisible" attribute for the newly created node.
 240      $newNode =& $newObject->attribute( 'main_node' );
 241      eZContentObjectTreeNode::updateNodeVisibility( $newNode, $newParentNode ); // ??? do we need this here?
 242  
 243      // if $keepCreator == true then keep owner of contentobject being
 244      // copied and creator of its published version Unchaged
 245      $isModified = false;
 246      if ( $keepTime )
 247      {
 248          $srcPublished = $sourceObject->attribute( 'published' );
 249          $newObject->setAttribute( 'published', $srcPublished );
 250          $srcModified  = $sourceObject->attribute( 'modified' );
 251          $newObject->setAttribute( 'modified', $srcModified );
 252          $isModified = true;
 253      }
 254      if ( $keepCreator )
 255      {
 256          $srcOwnerID = $sourceObject->attribute( 'owner_id' );
 257          $newObject->setAttribute( 'owner_id', $srcOwnerID );
 258          $isModified = true;
 259      }
 260      if ( $isModified )
 261          $newObject->store();
 262  
 263      if ( $allVersions )
 264      {   // copy time of creation and modification and creator id for
 265          // all versions of content object being copied.
 266          $srcVersionsList = $sourceObject->versions();
 267  
 268          foreach ( $srcVersionsList as $srcVersionObject )
 269          {
 270              $newVersionObject = $newObject->version( $srcVersionObject->attribute( 'version' ) );
 271              if ( !is_object( $newVersionObject ) )
 272                  continue;
 273  
 274              $isModified = false;
 275              if ( $keepTime )
 276              {
 277                  $srcVersionCreated  = $srcVersionObject->attribute( 'created' );
 278                  $newVersionObject->setAttribute( 'created', $srcVersionCreated );
 279                  $srcVersionModified = $srcVersionObject->attribute( 'modified' );
 280                  $newVersionObject->setAttribute( 'modified', $srcVersionModified );
 281                  $isModified = true;
 282              }
 283              if ( $keepCreator )
 284              {
 285                  $srcVersionCreatorID = $srcVersionObject->attribute( 'creator_id' );
 286                  $newVersionObject->setAttribute( 'creator_id', $srcVersionCreatorID );
 287  
 288                  $isModified = true;
 289              }
 290              if ( $isModified )
 291                  $newVersionObject->store();
 292          }
 293      }
 294      else // if not all versions copied
 295      {
 296          $srcVersionObject = $sourceObject->attribute( 'current' );
 297          $newVersionObject = $newObject->attribute( 'current' );
 298  
 299          $isModified = false;
 300          if ( $keepTime )
 301          {
 302              $srcVersionCreated  = $srcVersionObject->attribute( 'created' );
 303              $newVersionObject->setAttribute( 'created', $srcVersionCreated );
 304              $srcVersionModified = $srcVersionObject->attribute( 'modified' );
 305              $newVersionObject->setAttribute( 'modified', $srcVersionModified );
 306              $isModified = true;
 307          }
 308          if ( $keepCreator )
 309          {
 310              $srcVersionCreatorID = $srcVersionObject->attribute( 'creator_id' );
 311              $newVersionObject->setAttribute( 'creator_id', $srcVersionCreatorID );
 312              $isModified = true;
 313          }
 314          if ( $isModified )
 315              $newVersionObject->store();
 316      }
 317  
 318      return 0; // source object was copied successfully.
 319  
 320  }   //function copyPublishContentObject END
 321  
 322  
 323  
 324  // 1. Copy subtree and form the arrays of accordance of the old and new nodes and content objects.
 325  
 326  $sourceSubTreeMainNode = ( $srcNodeID ) ? eZContentObjectTreeNode::fetch( $srcNodeID ) : false;
 327  $destinationNode = ( $dstNodeID ) ? eZContentObjectTreeNode::fetch( $dstNodeID ) : false;
 328  
 329  if ( !$sourceSubTreeMainNode )
 330  {
 331      $cli->error( "Subtree copy Error!\nCannot get subtree main node. Please check src-node-id argument and try again." );
 332      $script->showHelp();
 333      $script->shutdown( 1 );
 334  }
 335  if ( !$destinationNode )
 336  {
 337      $cli->error( "Subtree copy Error!\nCannot get destination node. Please check dst-node-id argument and try again." );
 338      $script->showHelp();
 339      $script->shutdown( 1 );
 340  }
 341  
 342  $sourceNodeList    = array();
 343  $syncNodeIDListSrc = array();
 344  $syncNodeIDListNew = array();
 345  
 346  $sourceSubTreeMainNodeID = $sourceSubTreeMainNode->attribute( 'node_id' );
 347  $sourceNodeList[] = $sourceSubTreeMainNode;
 348  
 349  $syncNodeIDListSrc[] = $sourceSubTreeMainNode->attribute( 'parent_node_id' );
 350  $syncNodeIDListNew[] = (int) $dstNodeID;
 351  
 352  $syncObjectIDListSrc = array();
 353  $syncObjectIDListNew = array();
 354  
 355  $sourceNodeList = array_merge( $sourceNodeList, eZContentObjectTreeNode::subTree( false, $sourceSubTreeMainNodeID ) );
 356  $countNodeList = count( $sourceNodeList );
 357  
 358  // Prepare list of source node IDs. We will need it in the future
 359  // for checking node is inside or outside of the subtree being copied.
 360  $sourceNodeIDList = array();
 361  foreach ( $sourceNodeList as $sourceNode )
 362      $sourceNodeIDList[] = $sourceNode->attribute( 'node_id' );
 363  
 364  $cli->output( "Copying subtree:" );
 365  
 366  $k = 0;
 367  while ( count( $sourceNodeList ) > 0 )
 368  {
 369      if ( $k > $countNodeList )
 370      {
 371          $cli->error( "Subtree Copy Error!\nToo many loops while copying nodes." );
 372          $script->shutdown( 6 );
 373      }
 374  
 375      for ( $i = 0; $i < count( $sourceNodeList ); $i)
 376      {
 377          $sourceNodeID = $sourceNodeList[ $i ]->attribute( 'node_id' );
 378  
 379          if ( in_array( $sourceNodeID, $syncNodeIDListSrc ) )
 380              array_splice( $sourceNodeList, $i, 1 );
 381          else
 382          {
 383              $sourceObject =& $sourceNodeList[ $i ]->object();
 384              $srcSubtreeNodeIDlist = ($sourceNodeID == $sourceSubTreeMainNodeID) ? $syncNodeIDListSrc : $sourceNodeIDList;
 385  
 386              $copyResult = copyPublishContentObject( $sourceObject,
 387                                                      $srcSubtreeNodeIDlist,
 388                                                      $syncNodeIDListSrc, $syncNodeIDListNew,
 389                                                      $syncObjectIDListSrc, $syncObjectIDListNew,
 390                                                      $allVersions, $keepCreator, $keepTime );
 391              if ( $copyResult === 0 )
 392              {   // if copying successful then remove $sourceNode from $sourceNodeList
 393                  array_splice( $sourceNodeList, $i, 1 );
 394                  $cli->output( ".", false );
 395              }
 396              else
 397                  $i++;
 398          }
 399      }
 400      $k++;
 401  }
 402  
 403  array_shift( $syncNodeIDListSrc );
 404  array_shift( $syncNodeIDListNew );
 405  
 406  $cli->output( "\nNumber of copied nodes: " . count( $syncNodeIDListNew ) );
 407  $cli->output( "Number of copied contentobjects: " . count( $syncObjectIDListNew ) );
 408  
 409  // 2. fetch all new subtree
 410  
 411  $key = array_search( $sourceSubTreeMainNodeID, $syncNodeIDListSrc );
 412  if ( $key === false )
 413  {
 414      $cli->error( "Subtree copy Error!\nCannot find subtree root node in array of IDs of copied nodes." );
 415      $script->shutdown( 1 );
 416  }
 417  
 418  $newSubTreeMainNodeID = $syncNodeIDListSrc[ $key ];
 419  $newSubTreeMainNode   = eZContentObjectTreeNode::fetch( $newSubTreeMainNodeID );
 420  
 421  $newNodeList[] = $newSubTreeMainNode;
 422  $newNodeList = $sourceNodeList = array_merge( $newNodeList,
 423                                                eZContentObjectTreeNode::subTree( false, $newSubTreeMainNodeID ) );
 424  
 425  $cli->output( "Fixing global and local links..." );
 426  
 427  // 3. fix local links (in ezcontentobject_link)
 428  
 429  $db =& eZDB::instance();
 430  
 431  if ( !$db )
 432  {
 433      $cli->error( "Subtree Copy Error!\nCannot create instance of eZDB for fixing local links (related objects)." );
 434      $script->shutdown( 3 );
 435  }
 436  
 437  $idListStr = implode( ',', $syncObjectIDListNew );
 438  $relatedRecordsList = $db->arrayQuery( "SELECT * FROM ezcontentobject_link WHERE from_contentobject_id IN ($idListStr)" );
 439  
 440  foreach ( array_keys( $relatedRecordsList ) as $key )
 441  {
 442      $relatedEntry =& $relatedRecordsList[ $key ];
 443      $kindex = array_search( $relatedEntry[ 'to_contentobject_id' ], $syncObjectIDListSrc );
 444      if ( $kindex !== false )
 445      {
 446          $newToContentObjectID = $syncObjectIDListNew[ $kindex ];
 447          $linkID = $relatedEntry[ 'id' ];
 448          $db->query( "UPDATE ezcontentobject_link SET  to_contentobject_id=$newToContentObjectID WHERE id=$linkID" );
 449      }
 450  }
 451  
 452  // 4. duplicating of global links for new contentobjects (in ezurl_object_link) are automatic during copy of contentobject.
 453  
 454  // 5. loop on new nodes and REPLACE node_ids and object_ids
 455  
 456  $conditions = array( 'contentobject_id' => '', // 5
 457                       'data_type_string' => 'ezxmltext' );
 458  
 459  foreach ( $syncObjectIDListNew as $contentObjectID )
 460  {
 461      $conditions[ 'contentobject_id' ] = $contentObjectID;
 462      $attributeList = eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(), null, $conditions );
 463      if ( count( $attributeList ) == 0 )
 464      {
 465          continue;
 466      }
 467      foreach ( array_keys( $attributeList ) as $key )
 468      {
 469          $xmlAttribute =& $attributeList[ $key ];
 470          $xmlText = $xmlAttribute->attribute( 'data_text' );
 471          $xmlTextLen = strlen ( $xmlText );
 472          $isTextModified = false;
 473          $curPos = 0;
 474  
 475          while ( $curPos < $xmlTextLen )
 476          {
 477              // JK: find out what is the first tag
 478              // This is not the optimal solution, there is better way how to do. This is just a quick fix.
 479              $tmpArray = array();
 480              if ( $literalTagBeginPos = strpos( $xmlText, "<literal", $curPos ) )
 481                  $tmpArray[] = $literalTagBeginPos;
 482              if ( $linkTagBeginPos = strpos( $xmlText, "<link", $curPos ) )
 483                  $tmpArray[] = $linkTagBeginPos;
 484              if ( $aTagBeginPos = strpos( $xmlText, "<a", $curPos ) )
 485                  $tmpArray[] = $aTagBeginPos;
 486              if ( $embedTagBeginPos = strpos( $xmlText, "<embed", $curPos ) )
 487                  $tmpArray[] = $embedTagBeginPos;
 488              if ( $objectTagBeginPos = strpos( $xmlText, "<object", $curPos ) )
 489                  $tmpArray[] = $objectTagBeginPos;
 490  
 491              if ( !$tmpArray )
 492              {
 493                  break;
 494              }
 495  
 496              $tagBeginPos = min( $tmpArray );
 497  
 498              if ( $tagBeginPos == $literalTagBeginPos )
 499              {
 500                  $literalTagEndPos = strpos( $xmlText, "</literal>", $literalTagBeginPos );
 501                  if ( $literalTagEndPos === false )
 502                      break;
 503                  $curPos = $literalTagEndPos + 9;
 504              }
 505  
 506              if ( $tagBeginPos == $linkTagBeginPos || $tagBeginPos == $aTagBeginPos || $tagBeginPos == $embedTagBeginPos )
 507              {
 508                  $tagEndPos = strpos( $xmlText, ">", $tagBeginPos + 1 );
 509                  if ( $tagEndPos === false )
 510                      break;
 511  
 512                  $tagText = substr( $xmlText, $tagBeginPos, $tagEndPos - $tagBeginPos );
 513  
 514                  if ( ($nodeIDAttributePos = strpos( $tagText, " node_id=\"" )) !== false )
 515                  {
 516                      $idNumberPos = $nodeIDAttributePos + 10;
 517                      $quoteEndPos = strpos( $tagText, "\"", $idNumberPos );
 518  
 519                      if ( $quoteEndPos !== false )
 520                      {
 521                          $idNumber = substr( $tagText, $idNumberPos, $quoteEndPos - $idNumberPos );
 522                          $key = array_search( (int) $idNumber, $syncNodeIDListSrc );
 523  
 524                          if ( $key !== false )
 525                          {
 526                              $tagText = substr_replace( $tagText, (string) $syncNodeIDListNew[ $key ], $idNumberPos, $quoteEndPos - $idNumberPos );
 527                              $xmlText = substr_replace( $xmlText, $tagText, $tagBeginPos, $tagEndPos - $tagBeginPos );
 528                              $isTextModified = true;
 529                          }
 530                      }
 531                  }
 532                  else if ( ($objectIDAttributePos = strpos( $tagText, " object_id=\"" )) !== false )
 533                  {
 534                      $idNumberPos = $objectIDAttributePos + 12;
 535                      $quoteEndPos = strpos( $tagText, "\"", $idNumberPos );
 536  
 537                      if ( $quoteEndPos !== false )
 538                      {
 539                          $idNumber = substr( $tagText, $idNumberPos, $quoteEndPos - $idNumberPos );
 540                          $key = array_search( (int) $idNumber, $syncObjectIDListSrc );
 541                          if ( $key !== false )
 542                          {
 543                              $tagText = substr_replace( $tagText, (string) $syncObjectIDListNew[ $key ], $idNumberPos, $quoteEndPos - $idNumberPos );
 544                              $xmlText = substr_replace( $xmlText, $tagText, $tagBeginPos, $tagEndPos - $tagBeginPos );
 545                              $isTextModified = true;
 546                          }
 547                      }
 548                  }
 549                  $curPos = $tagEndPos;
 550              }
 551              else if ( $tagBeginPos == $objectTagBeginPos )
 552              {
 553                  $tagEndPos = strpos( $xmlText, ">", $tagBeginPos + 1 );
 554                  if ( !$tagEndPos )
 555                      break;
 556  
 557                  $tagText = substr( $xmlText, $tagBeginPos, $tagEndPos - $tagBeginPos );
 558  
 559                  if ( ($idAttributePos = strpos( $tagText, " id=\"" )) !== false )
 560                  {
 561                      $idNumberPos = $idAttributePos + 5;
 562                      $quoteEndPos = strpos( $tagText, "\"", $idNumberPos );
 563  
 564                      if ( $quoteEndPos !== false )
 565                      {
 566                          $idNumber = substr( $tagText, $idNumberPos, $quoteEndPos - $idNumberPos );
 567                          $key = array_search( (int) $idNumber, $syncObjectIDListSrc );
 568                          if ( $key !== false )
 569                          {
 570                              $tagText = substr_replace( $tagText, (string) $syncObjectIDListNew[ $key ], $idNumberPos, $quoteEndPos - $idNumberPos );
 571                              $xmlText = substr_replace( $xmlText, $tagText, $tagBeginPos, $tagEndPos - $tagBeginPos );
 572                              $isTextModified = true;
 573                          }
 574                      }
 575                  }
 576                  $curPos = $tagEndPos;
 577              }
 578  
 579          } // while END
 580  
 581          if ( $isTextModified )
 582          {
 583              $xmlAttribute->setAttribute( 'data_text', $xmlText );
 584              $xmlAttribute->store();
 585          }
 586      } // foreach END
 587  }
 588  
 589  $cli->output( "Done." );
 590  
 591  $script->shutdown();
 592  
 593  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7