[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/classes/packagehandlers/ezcontentobject/ -> ezcontentobjectpackagehandler.php (source)

   1  <?php
   2  //
   3  // Definition of eZContentClassPackageHandler class
   4  //
   5  // Created on: <09-Mar-2004 16:11:42 kk>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezcontentobjectpackagehandler.php
  30  */
  31  
  32  /*!
  33    \class eZContentObjectPackageHandler ezcontentobjectpackagehandler.php
  34    \brief Handles content objects in the package system
  35  
  36  */
  37  
  38  define( 'EZ_PACKAGE_CONTENTOBJECT__MAX_LISTED_OBJECTS_NUMBER', 30 );
  39  
  40  // If number of objects in the package is bigger than this constant,
  41  // they are stored in separate files to prevent memory overflow.
  42  // 'null' means always use separate files
  43  define( 'EZ_PACKAGE_CONTENTOBJECT__STORE_OBJECTS_TO_SEPARATE_FILES_THRESHOLD', 100 );
  44  
  45  define( 'EZ_PACKAGE_CONTENTOBJECT__INSTALL_OBJECTS_ERROR_RANGE_FROM', 1 );
  46  define( 'EZ_PACKAGE_CONTENTOBJECT__INSTALL_OBJECTS_ERROR_RANGE_TO', 100 );
  47  define( 'EZ_PACKAGE_CONTENTOBJECT__UNINSTALL_OBJECTS_ERROR_RANGE_FROM', 101 );
  48  define( 'EZ_PACKAGE_CONTENTOBJECT__UNINSTALL_OBJECTS_ERROR_RANGE_TO', 200 );
  49  
  50  include_once ( 'lib/ezxml/classes/ezxml.php' );
  51  include_once ( 'kernel/classes/ezcontentobject.php' );
  52  include_once ( 'kernel/classes/ezpackagehandler.php' );
  53  
  54  class eZContentObjectPackageHandler extends eZPackageHandler
  55  {
  56      /*!
  57       Constructor
  58      */
  59      function eZContentObjectPackageHandler()
  60      {
  61          $this->eZPackageHandler( 'ezcontentobject',
  62                                   array( 'extract-install-content' => true ) );
  63      }
  64  
  65      /*!
  66         Fetches object stored in separate xml file
  67      */
  68      function fetchObjectFromFile( $objectFileNode )
  69      {
  70          $fileName = $objectFileNode->getAttribute( 'filename' );
  71          $filePath = $this->Package->path() . '/' . $this->contentObjectDirectory() . '/' . $fileName;
  72          $dom =& $this->Package->fetchDOMFromFile( $filePath );
  73  
  74          if ( $dom )
  75          {
  76              $objectNode =& $dom->root();
  77          }
  78          else
  79          {
  80              eZDebug::writeError( "Can't fetch object from package file: $filePath", 'eZContentObjectPackageHandler::getObjectNodeFromFile' );
  81              $objectNode = false;
  82          }
  83  
  84          return $objectNode;
  85      }
  86  
  87      function getRealObjectNode( $objectNode )
  88      {
  89          if ( $objectNode->nodeName == 'object' )
  90          {
  91              $realObjectNode =& $objectNode;
  92          }
  93          else
  94          {
  95              $realObjectNode = $this->fetchObjectFromFile( $objectNode );
  96          }
  97          return $realObjectNode;
  98      }
  99  
 100      /*!
 101       \reimp
 102       Returns an explanation for the content object install item.
 103  
 104       The explanaition is actually a list having the following structure:
 105            array( array( 'description' => 'Content object Foo' ),
 106                   array( 'description' => 'Content object Bar' ),
 107                   array( 'description' => 'Content object Baz' ) );
 108  
 109       When number of items in the above list is too high,
 110       the following array is returned instead:
 111           array( 'description' => 'NNN content objects' );
 112  
 113  
 114      */
 115      function explainInstallItem( &$package, $installItem )
 116      {
 117          $this->Package =& $package;
 118  
 119          if ( $installItem['filename'] )
 120          {
 121              $filename = $installItem['filename'];
 122              $subdirectory = $installItem['sub-directory'];
 123              if ( $subdirectory )
 124                  $filepath = $subdirectory . '/' . $filename . '.xml';
 125              else
 126                  $filepath = $filename . '.xml';
 127  
 128              $filepath = $package->path() . '/' . $filepath;
 129  
 130              $dom =& $package->fetchDOMFromFile( $filepath );
 131  
 132              if ( !$dom )
 133                  return null;
 134  
 135              $content =& $dom->root();
 136              $objectListNode = $content->elementByName( 'object-list' );
 137              if ( $objectListNode )
 138              {
 139                  $realObjectNodes =& $objectListNode->Children;
 140              }
 141              else
 142              {
 143                  // If objects are stored in separate files (new format)
 144                  $objectListNode = $content->elementByName( 'object-files-list' );
 145                  $objectNodes = $objectListNode->Children;
 146  
 147                  if ( count( $objectNodes ) > EZ_PACKAGE_CONTENTOBJECT__MAX_LISTED_OBJECTS_NUMBER )
 148                  {
 149                      return array( 'description' => ezi18n( 'kernel/package', '%number content objects', false,
 150                                                             array( '%number' => count( $objectNodes ) ) ) );
 151                  }
 152  
 153                  $realObjectNodes = array();
 154                  foreach( $objectNodes as $objectNode )
 155                  {
 156                      $realObjectNode = $this->fetchObjectFromFile( $objectNode );
 157                      if ( !$realObjectNode )
 158                          continue;
 159  
 160                      $realObjectNodes[] =& $realObjectNode;
 161                      unset( $realObjectNode );
 162                  }
 163              }
 164  
 165              // create descriptions array
 166              $objectNames = array();
 167              foreach( $realObjectNodes as $objectNode )
 168              {
 169                  // We use attributeValue() method to get value of 'ezremote:class_identifier' attribute
 170                  // since getAttribute() does not support specifying prefixes.
 171                  $objectName =
 172                      $objectNode->getAttribute( 'name' ) .
 173                      ' (' . $objectNode->attributeValue( 'class_identifier' ) .')';
 174                  $objectNames[] = array( 'description' =>
 175                                           ezi18n( 'kernel/package', 'Content object %objectname', false,
 176                                                   array( '%objectname' => $objectName ) ) );
 177              }
 178              return $objectNames;
 179          }
 180      }
 181  
 182      /*!
 183       Add Node list to ezcontentobject package handler.
 184  
 185       \param node id
 186       \param subtree (optional, default true )
 187      */
 188      function addNode( $nodeID, $isSubtree = true )
 189      {
 190          include_once ( 'kernel/classes/ezcontentobjecttreenode.php' );
 191          $this->RootNodeIDArray[] = $nodeID;
 192          $this->NodeIDArray[] = $nodeID;
 193  
 194          if ( $isSubtree )
 195          {
 196              $nodeArray =& eZContentObjectTreeNode::subtree( array( 'AsObject' => false ), $nodeID );
 197              foreach( $nodeArray as $node )
 198              {
 199                  $this->NodeIDArray[] = $node['node_id'];
 200              }
 201          }
 202      }
 203  
 204      /*!
 205       Generate package based on NodeArray and input options
 206  
 207       \param package
 208       \param options
 209      */
 210      function generatePackage( &$package, $options )
 211      {
 212          $this->Package =& $package;
 213          $remoteIDArray = array();
 214          $this->NodeIDArray = array_unique( $this->NodeIDArray );
 215          foreach( $this->NodeIDArray as $nodeID )
 216          {
 217              $this->NodeObjectArray[(string)$nodeID] = eZContentObjectTreeNode::fetch( $nodeID );
 218          }
 219  
 220          foreach( $this->RootNodeIDArray as $nodeID )
 221          {
 222              $this->RootNodeObjectArray[(string)$nodeID] = eZContentObjectTreeNode::fetch( $nodeID );
 223          }
 224  
 225          $this->generateObjectArray( $options['node_assignment'] );
 226  
 227          $classIDArray = false;
 228          if ( $options['include_classes'] )
 229          {
 230              $remoteIDArray['class'] = array();
 231              $classIDArray =& $this->generateClassIDArray();
 232  
 233              include_once ( 'kernel/classes/packagehandlers/ezcontentclass/ezcontentclasspackagehandler.php' );
 234              foreach ( $classIDArray as $classID )
 235              {
 236                  eZContentClassPackageHandler::addClass( $package, $classID );
 237              }
 238          }
 239  
 240          $packageRoot = eZDOMDocument::createElementNode( 'content-object' );
 241  
 242          $objectListDOMNode = $this->createObjectListNode( $options );
 243          $packageRoot->appendChild( $objectListDOMNode );
 244  
 245          $overrideSettingsArray = false;
 246          $templateFilenameArray = false;
 247          if ( $options['include_templates'] )
 248          {
 249              $overrideSettingsListNode =& $this->generateOverrideSettingsArray( $options['site_access_array'], $options['minimal_template_set'] );
 250              $packageRoot->appendChild( $overrideSettingsListNode );
 251  
 252              $designTemplateListNode =& $this->generateTemplateFilenameArray();
 253              $packageRoot->appendChild( $designTemplateListNode );
 254  
 255              $fetchAliasListNode =& $this->generateFetchAliasArray();
 256              $packageRoot->appendChild( $fetchAliasListNode );
 257          }
 258  
 259          $siteAccessListDOMNode = $this->createSiteAccessListNode( $options );
 260          $packageRoot->appendChild( $siteAccessListDOMNode );
 261  
 262          $topNodeListDOMNode = $this->createTopNodeListDOMNode( $options );
 263          $packageRoot->appendChild( $topNodeListDOMNode );
 264  
 265          //$filename = substr( md5( mt_rand() ), 0, 8 );
 266          $filename = 'contentobjects';
 267          $this->Package->appendInstall( 'ezcontentobject', false, false, true,
 268                                         $filename, $this->contentObjectDirectory(),
 269                                         array( 'content' => $packageRoot ) );
 270          $this->Package->appendInstall( 'ezcontentobject', false, false, false,
 271                                         $filename, $this->contentObjectDirectory(),
 272                                         array( 'content' => false ) );
 273      }
 274  
 275      /*!
 276       \private
 277       Create DOMNode for list of top nodes.
 278  
 279       \param options
 280      */
 281      function createTopNodeListDOMNode( $options )
 282      {
 283          $topNodeListDOMNode = eZDOMDocument::createElementNode( 'top-node-list' );
 284  
 285          foreach( $this->RootNodeObjectArray as $topNode )
 286          {
 287              $topNodeListDOMNode->appendChild( eZDOMDocument::createElementTextNode( 'top-node', $topNode->attribute( 'name' ),
 288                                                                                      array( 'node-id' => $topNode->attribute( 'node_id' ),
 289                                                                                             'remote-id' => $topNode->attribute( 'remote_id' ) ) ) );
 290          }
 291  
 292          return $topNodeListDOMNode;
 293      }
 294  
 295      /*!
 296       \private
 297       Create DOMNode for list of added siteaccesses.
 298  
 299       \param options
 300      */
 301      function createSiteAccessListNode( $options )
 302      {
 303          $siteAccessListDOMNode = eZDOMDocument::createElementNode( 'site-access-list' );
 304          foreach( $options['site_access_array'] as $siteAccess )
 305          {
 306              $siteAccessListDOMNode->appendChild( eZDOMDocument::createElementTextNode( 'site-access', $siteAccess ) );
 307          }
 308  
 309          return $siteAccessListDOMNode;
 310      }
 311  
 312      /*!
 313       \private
 314       Serializes and adds all contentobjects to package
 315  
 316       \param options
 317      */
 318      function createObjectListNode( $options )
 319      {
 320          if ( $options['versions'] == 'current' )
 321          {
 322              $version = true;
 323          }
 324          else
 325          {
 326              $version = false;
 327          }
 328  
 329          $path = $this->Package->path() . '/' . $this->contentObjectDirectory();
 330          if ( !file_exists( $path ) )
 331                  eZDir::mkdir( $path, eZDir::directoryPermission(), true );
 332  
 333          // Store objects to separate files or not
 334          $storeToMultiple = count( $this->ObjectArray ) >= EZ_PACKAGE_CONTENTOBJECT__STORE_OBJECTS_TO_SEPARATE_FILES_THRESHOLD ? true : false;
 335          if ( $storeToMultiple )
 336              $objectListNode = eZDOMDocument::createElementNode( 'object-files-list' );
 337          else
 338              $objectListNode = eZDOMDocument::createElementNode( 'object-list' );
 339  
 340          foreach( array_keys( $this->ObjectArray ) as $objectID )
 341          {
 342              $objectNode = $this->ObjectArray[$objectID]->serialize( $this->Package, $version, $options, $this->NodeObjectArray, $this->RootNodeIDArray );
 343  
 344              if ( $storeToMultiple )
 345              {
 346                  $fileName = 'object-' . $objectNode->getAttribute( 'remote_id' ) . '.xml';
 347                  $filePath = $path . '/' . $fileName;
 348  
 349                  $objectFileNode = eZDOMDocument::createElementNode( 'object-file' );
 350                  $objectFileNode->setAttribute( 'filename', $fileName );
 351                  $objectListNode->appendChild( $objectFileNode );
 352  
 353                  $partDOM = new eZDOMDocument();
 354                  $partDOM->setRoot( $objectNode );
 355                  $this->Package->storeDOM( $filePath, $partDOM );
 356                  unset( $partDOM );
 357                  unset( $objectFileNode );
 358              }
 359              else
 360              {
 361                  $objectListNode->appendChild( $objectNode );
 362              }
 363              unset( $objectNode );
 364          }
 365  
 366          return $objectListNode;
 367      }
 368  
 369      /*!
 370       \private
 371       Generate list of content objects to export, and store them to
 372  
 373       \param node_assignments, 'selected' or 'main'
 374      */
 375      function generateObjectArray( $nodeAssignment )
 376      {
 377          foreach( array_keys( $this->NodeObjectArray ) as $key )
 378          {
 379              $contentNode =& $this->NodeObjectArray[$key];
 380              if ( $nodeAssignment == 'main' )
 381              {
 382                  if ( $contentNode->attribute( 'main_node_id' ) == $contentNode->attribute( 'node_id' ) )
 383                  {
 384                      $this->ObjectArray[(string)$contentNode->attribute( 'contentobject_id' )] =& $contentNode->object();
 385                  }
 386              }
 387              else
 388              {
 389                  $this->ObjectArray[(string)$contentNode->attribute( 'contentobject_id' )] =& $contentNode->object();
 390              }
 391          }
 392      }
 393  
 394      /*!
 395        \private
 396      */
 397      function &generateFetchAliasArray()
 398      {
 399          $fetchAliasListDOMNode = eZDOMDocument::createElementNode( 'fetch-alias-list' );
 400          $registeredAliases = array();
 401  
 402          foreach( array_keys( $this->TemplateFileArray ) as $siteAccess )
 403          {
 404              $aliasINI =& eZINI::instance( 'fetchalias.ini', 'settings', null, null, true );
 405              $aliasINI->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' );
 406              $aliasINI->loadCache();
 407  
 408              foreach ( $this->TemplateFileArray[$siteAccess] as $filename )
 409              {
 410                  $fp = fopen( $filename, 'r' );
 411                  if ( !$fp )
 412                  {
 413                      eZDebug::writeError( 'Could not open ' . $filename . ' during content object export.',
 414                                           'eZContentObjectPackageHandler::generateFethAliasArray()' );
 415                      continue;
 416                  }
 417  
 418                  $str = fread( $fp, filesize( $filename ) );
 419  
 420                  $matchArray = array();
 421                  preg_match_all( "#.*fetch_alias\([ ]*([a-zA-Z0-9_]+)[ |,|)]+.*#U", $str, $matchArray, PREG_PATTERN_ORDER );
 422  
 423                  foreach( $matchArray[1] as $fetchAlias )
 424                  {
 425                      if ( isset( $registeredAliases[$fetchAlias] ) )
 426                      {
 427                          continue;
 428                      }
 429                      $registeredAliases[$fetchAlias] = true;
 430  
 431                      unset( $fetchAliasDOMNode );
 432                      $fetchAliasDOMNode = eZDOMDocument::createElementNode( 'fetch-alias', array( 'name' => $fetchAlias,
 433                                                                                                    'site-access' => $siteAccess ) );
 434  
 435                      $fetchBlock = $aliasINI->group( $fetchAlias );
 436                      if ( isset( $fetchBlock['Constant'] ) )
 437                      {
 438                          foreach ( $fetchBlock['Constant'] as $matchKey => $value )
 439                          {
 440                              if ( strpos( $matchKey, 'class_' ) === 0 &&
 441                                   is_int( $value ) )
 442                              {
 443                                  $contentClass = eZContentClass::fetch( $value );
 444                                  $fetchBlock['Constant']['class_remote_id'] = $contentClass->attribute( 'remote_id' );
 445                              }
 446                              if ( strpos( $matchKey, 'node_' ) === 0 &&
 447                                   is_int( $value ) )
 448                              {
 449                                  $contentTreeNode = eZContentObjectTreeNode::fetch( $value );
 450                                  $fetchBlock['Constant']['node_remote_id'] = $contentTreeNode->attribute( 'remote_id' );
 451                              }
 452                              if ( strpos( $matchKey, 'parent_node_' ) === 0 &&
 453                                   is_int( $value ) )
 454                              {
 455                                  $contentTreeNode = eZContentObjectTreeNode::fetch( $value );
 456                                  $fetchBlock['Constant']['parent_node_remote_id'] = $contentTreeNode->attribute( 'remote_id' );
 457                              }
 458                              if ( strpos( $matchKey, 'object_' ) === 0 &&
 459                                   is_int( $value ) )
 460                              {
 461                                  $contentObject = eZContentObject::fetch( $value );
 462                                  $fetchBlock['Constant']['object_remote_id'] = $contentObject->attribute( 'remote_id' );
 463                              }
 464                          }
 465                      }
 466                      $fetchAliasDOMNode->appendChild( eZDOMDocument::createElementNodeFromArray( $fetchAlias,  $fetchBlock ) );
 467                      $fetchAliasListDOMNode->appendChild( $fetchAliasDOMNode );
 468                  }
 469              }
 470          }
 471          return $fetchAliasListDOMNode;
 472      }
 473  
 474      /*!
 475       \private
 476      */
 477      function &generateTemplateFilenameArray()
 478      {
 479          $templateListDOMNode = eZDOMDocument::createElementNode( 'template-list' );
 480  
 481          include_once ( 'kernel/common/eztemplatedesignresource.php' );
 482  
 483          foreach( array_keys( $this->OverrideSettingsArray ) as $siteAccess )
 484          {
 485              $this->TemplateFileArray[$siteAccess] = array();
 486              $overrideArray = eZTemplateDesignResource::overrideArray( $siteAccess );
 487  
 488              foreach( $this->OverrideSettingsArray[$siteAccess] as $override )
 489              {
 490                  $customMatchArray = $overrideArray['/' . $override['Source']]['custom_match'];
 491  
 492                  foreach( $customMatchArray as $customMatch )
 493                  {
 494                      if ( $customMatch['conditions'] == null )
 495                      {
 496                          //$templateListDOMNode->appendChild( $this->createDOMNodeFromFile( $customMatch['match_file'], $siteAccess, 'design' ) );
 497                          //$this->TemplateFileArray[$siteAccess][] = $customMatch['match_file'];
 498                      }
 499                      else if ( count( array_diff( $customMatch['conditions'], $override['Match'] ) ) == 0 &&
 500                                count( array_diff( $override['Match'], $customMatch['conditions'] ) ) == 0 )
 501                      {
 502                          $templateListDOMNode->appendChild( $this->createDOMNodeFromFile( $customMatch['match_file'], $siteAccess, 'design' ) );
 503                          $this->TemplateFileArray[$siteAccess][] = $customMatch['match_file'];
 504                      }
 505                  }
 506              }
 507          }
 508          return $templateListDOMNode;
 509  
 510          //TODO : add templates included in templates here.
 511      }
 512  
 513      /*!
 514       \private
 515       Add file to repository and return DONNode description of file
 516  
 517       \param filename
 518       \param siteaccess
 519       \param filetype (optional)
 520      */
 521      function createDOMNodeFromFile( $filename, $siteAccess, $filetype = false )
 522      {
 523          $fileAttributes = array( 'site-access' => $siteAccess );
 524          if ( $filetype !== false )
 525          {
 526              $fileAttributes['file-type'] = $filetype;
 527          }
 528  
 529          $path = substr( $filename, strpos( $filename, '/', 7 ) );
 530  
 531          $fileDOMNode = eZDOMDocument::createElementNode( 'file', $fileAttributes );
 532          $fileDOMNode->appendChild( eZDOMDocument::createElementTextNode( 'original-path', $filename ) );
 533          $fileDOMNode->appendChild( eZDOMDocument::createElementTextNode( 'path', $path ) );
 534  
 535          $destinationPath = $this->Package->path() . '/' .  eZContentObjectPackageHandler::contentObjectDirectory() . '/' . $path;
 536          eZDir::mkdir( eZDir::dirpath( $destinationPath ),  eZDir::directoryPermission(),  true );
 537          eZFileHandler::copy( $filename, $destinationPath );
 538  
 539          return $fileDOMNode;
 540      }
 541  
 542      /*!
 543       \private
 544       Get all template overrides used by exported objects
 545  
 546       \param site access array
 547      */
 548      function &generateOverrideSettingsArray( $siteAccessArray, $minimalTemplateSet )
 549      {
 550          $datatypeHash = array();
 551          $simpleMatchList = array();
 552          $regexpMatchList = array();
 553          foreach ( $siteAccessArray as $siteAccess )
 554          {
 555              $overrideINI =& eZINI::instance( 'override.ini', 'settings', null, null, true );
 556              $overrideINI->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' );
 557              $overrideINI->loadCache();
 558  
 559              $matchBlock = false;
 560              $blockMatchArray = array();
 561  
 562              foreach( array_keys( $this->NodeObjectArray ) as $nodeID )
 563              {
 564                  // Extract some information that will be used
 565                  unset( $contentNode, $contentObject, $contentClass );
 566                  $contentNode =& $this->NodeObjectArray[$nodeID];
 567                  $contentObject =& $contentNode->attribute( 'object' );
 568                  $contentClass =& $contentObject->attribute( 'content_class' );
 569                  $attributeList = $contentClass->fetchAttributes( false, false, false );
 570                  $datatypeList = array();
 571                  foreach ( $attributeList as $attribute )
 572                  {
 573                      $datatypeList[] = $attribute['data_type_string'];
 574                      if ( !isset( $datatypeHash[$attribute['data_type_string']] ) )
 575                      {
 576                          include_once ( 'kernel/classes/ezdatatype.php' );
 577                          $datatype = eZDataType::create( $attribute['data_type_string'] );
 578                          $datatypeHash[$attribute['data_type_string']] =& $datatype;
 579                          if ( !method_exists( $datatype, 'templateList' ) )
 580                              continue;
 581                          $templateList = $datatype->templateList();
 582                          if ( $templateList === false )
 583                              continue;
 584                          foreach ( $templateList as $templateMatch )
 585                          {
 586                              if ( is_string( $templateMatch ) )
 587                              {
 588                                  $simpleMatchList[] = $templateMatch;
 589                              }
 590                              else if ( is_array( $templateMatch ) )
 591                              {
 592                                  if ( $templateMatch[0] == 'regexp' )
 593                                  {
 594                                      $regexpMatchList[] = $templateMatch[1];
 595                                  }
 596                              }
 597                          }
 598                      }
 599                  }
 600                  $datatypeText = implode( '|', array_unique( $datatypeList ) );
 601  
 602                  foreach( array_keys( $overrideINI->groups() ) as $blockName )
 603                  {
 604                      if ( isset( $blockMatchArray[$blockName] ) )
 605                      {
 606                          continue;
 607                      }
 608  
 609                      $blockData = $overrideINI->group( $blockName );
 610                      $sourceName = $blockData['Source'];
 611                      $matchSettings = false;
 612                      if ( isset( $blockData['Match'] ) )
 613                          $matchSettings = $blockData['Match'];
 614  
 615                      $matchValue = array();
 616                      $validMatch = true;
 617                      $hasMatchType = false;
 618                      if ( $matchSettings )
 619                      {
 620                          foreach( array_keys( $matchSettings ) as $matchType )
 621                          {
 622                              switch( $matchType )
 623                              {
 624                                  case 'object':
 625                                  {
 626                                      $hasMatchType = true;
 627                                      if ( $contentNode->attribute( 'contentobject_id' ) != $matchSettings[$matchType] )
 628                                      {
 629                                          $validMatch = false;
 630                                      }
 631                                      else
 632                                      {
 633                                          $matchValue[$this->OverrideObjectRemoteID] = $contentObject->attribute( 'remote_id' );
 634                                      }
 635                                  } break;
 636  
 637                                  case 'node':
 638                                  {
 639                                      $hasMatchType = true;
 640                                      if ( $nodeID != $matchSettings[$matchType] )
 641                                      {
 642                                          $validMatch = false;
 643                                      }
 644                                      else
 645                                      {
 646                                          $matchValue[$this->OverrideNodeRemoteID] = $contentNode->attribute( 'remote_id' );
 647                                      }
 648                                  } break;
 649  
 650                                  case 'parent_node':
 651                                  {
 652                                      $hasMatchType = true;
 653                                      if ( $contentNode->attribute( 'parent_node_id' ) != $matchSettings[$matchType] )
 654                                      {
 655                                          $validMatch = false;
 656                                      }
 657                                      else
 658                                      {
 659                                          $parentNode = $contentNode->attribute( 'parent' );
 660                                          $matchValue[$this->OverrideParentNodeRemoteID] = $parentNode->attribute( 'remote_id' );
 661                                      }
 662                                  } break;
 663  
 664                                  case 'class':
 665                                  {
 666                                      $hasMatchType = true;
 667                                      if ( $contentObject->attribute( 'contentclass_id' ) != $matchSettings[$matchType] )
 668                                      {
 669                                          $validMatch = false;
 670                                      }
 671                                      else
 672                                      {
 673                                          $matchValue[$this->OverrideClassRemoteID] = $contentClass->attribute( 'remote_id' );
 674                                      }
 675                                  } break;
 676  
 677                                  case 'class_identifier':
 678                                  {
 679                                      $hasMatchType = true;
 680                                      if ( $contentObject->attribute( 'class_identifier' ) != $matchSettings[$matchType] )
 681                                      {
 682                                          $validMatch = false;
 683                                      }
 684                                  } break;
 685  
 686                                  case 'section':
 687                                  {
 688                                      $hasMatchType = true;
 689                                      if ( $contentObject->attribute( 'section_id' ) != $matchSettings[$matchType] )
 690                                      {
 691                                          $validMatch = false;
 692                                      }
 693                                  } break;
 694  
 695                                  case 'depth':
 696                                  {
 697                                      $hasMatchType = true;
 698                                      if ( $contentNode->attribute( 'depth' ) != $matchSettings[$matchType] )
 699                                      {
 700                                          $validMatch = false;
 701                                      }
 702                                  } break;
 703                              }
 704  
 705                              if ( !$validMatch )
 706                              {
 707                                  break;
 708                              }
 709                          }
 710                      }
 711                      else
 712                      {
 713                          $validMatch = false;
 714                      }
 715  
 716                      if ( !$hasMatchType )
 717                      {
 718                          // Datatype match, we include overrides for datatype templates
 719                          if ( preg_match( "#^content/datatype/[a-zA-Z]+/(" . $datatypeText . ")\\.tpl$#", $sourceName ) )
 720                          {
 721                              $validMatch = true;
 722                              $hasMatchType = true;
 723                          }
 724                          else if ( in_array( $sourceName, $simpleMatchList ) )
 725                          {
 726                              $validMatch = true;
 727                              $hasMatchType = true;
 728                          }
 729                          else
 730                          {
 731                              foreach ( $regexpMatchList as $regexpMatch )
 732                              {
 733                                  if ( preg_match( $regexpMatch, $sourceName ) )
 734                                  {
 735                                      $validMatch = true;
 736                                      $hasMatchType = true;
 737                                  }
 738                              }
 739                          }
 740                      }
 741  
 742                      if ( $validMatch )
 743                      {
 744                          if ( !$minimalTemplateSet or
 745                               $hasMatchType )
 746                          {
 747                              $blockMatchArray[$blockName] = array_merge( $blockData,
 748                                                                          $matchValue );
 749                          }
 750                      }
 751                  }
 752              }
 753              $this->OverrideSettingsArray[$siteAccess] = $blockMatchArray;
 754          }
 755  
 756          $overrideSettingsListDOMNode = eZDOMDocument::createElementNode( 'override-list' );
 757          foreach ( $this->OverrideSettingsArray as $siteAccess => $blockMatchArray )
 758          {
 759              foreach( $blockMatchArray as $blockName => $iniGroup )
 760              {
 761                  unset( $blockMatchNode );
 762                  $blockMatchNode = eZDOMDocument::createElementNode( 'block', array( 'name' => $blockName,
 763                                                                                      'site-access' => $siteAccess ) );
 764                  $blockMatchNode->appendChild( eZDOMDocument::createElementNodeFromArray( $blockName,  $iniGroup ) );
 765                  $overrideSettingsListDOMNode->appendChild( $blockMatchNode );
 766              }
 767          }
 768  
 769          return $overrideSettingsListDOMNode;
 770      }
 771  
 772      /*!
 773       \private
 774       Get list of all class objects used in by the nodes in NodeArray
 775      */
 776      function &generateClassIDArray()
 777      {
 778          $classIDArray = array();
 779          foreach( array_keys( $this->NodeObjectArray ) as $key )
 780          {
 781              $contentObject =& $this->NodeObjectArray[$key]->object();
 782              $classIDArray[] = $contentObject->attribute( 'contentclass_id' );
 783          }
 784          $classIDArray = array_unique( $classIDArray );
 785          return $classIDArray;
 786      }
 787  
 788      /*!
 789       \reimp
 790       Uninstalls all previously installed content objects.
 791      */
 792      function uninstall( &$package, $installType, $parameters,
 793                          $name, $os, $filename, $subdirectory,
 794                          &$content, &$installParameters,
 795                          &$installData )
 796      {
 797          $this->Package =& $package;
 798  
 799          if ( isset( $installParameters['error']['error_code'] ) )
 800              $errorCode = $installParameters['error']['error_code'];
 801          else
 802              $errorCode = false;
 803  
 804          // Error codes reserverd for content object uninstallation
 805          if ( !$errorCode || ( $errorCode >= EZ_PACKAGE_CONTENTOBJECT__UNINSTALL_OBJECTS_ERROR_RANGE_FROM &&
 806                                $errorCode <= EZ_PACKAGE_CONTENTOBJECT__UNINSTALL_OBJECTS_ERROR_RANGE_TO ) )
 807          {
 808              $objectListNode = $content->elementByName( 'object-list' );
 809              if ( !$objectListNode )
 810              {
 811                  $objectListNode = $content->elementByName( 'object-files-list' );
 812              }
 813              $objectNodes = array_reverse( $objectListNode->Children );
 814  
 815              foreach( $objectNodes as $objectNode )
 816              {
 817                  $realObjectNode = $this->getRealObjectNode( $objectNode );
 818  
 819                  $objectRemoteID = $realObjectNode->getAttribute( 'remote_id' );
 820                  $name = $realObjectNode->attributeValue( 'name' );
 821  
 822                  if ( isset( $installParameters['error']['error_code'] ) &&
 823                       !$this->isErrorElement( $objectRemoteID, $installParameters ) )
 824                      continue;
 825  
 826                  if ( isset( $object ) )
 827                  {
 828                      eZContentObject::clearCache( $object->attribute( 'id' ) );
 829                      unset( $object );
 830                  }
 831                  $object = eZContentObject::fetchByRemoteID( $objectRemoteID );
 832  
 833                  if ( $object !== null )
 834                  {
 835                      $modified = $object->attribute( 'modified' );
 836                      $published = $object->attribute( 'published' );
 837                      if ( $modified > $published )
 838                      {
 839                          $choosenAction = $this->errorChoosenAction( EZ_PACKAGE_CONTENTOBJECT_ERROR_MODIFIED,
 840                                                                      $installParameters );
 841  
 842                          if ( $choosenAction == EZ_PACKAGE_CONTENTOBJECT_KEEP )
 843                          {
 844                              continue;
 845                          }
 846                          if ( $choosenAction != EZ_PACKAGE_CONTENTOBJECT_DELETE )
 847                          {
 848                              $installParameters['error'] = array( 'error_code' => EZ_PACKAGE_CONTENTOBJECT_ERROR_MODIFIED,
 849                                                                   'element_id' => $objectRemoteID,
 850                                                                   'description' => ezi18n( 'kernel/package',
 851                                                                                            "Object '%objectname' has been modified since installation. Are you sure you want to remove it?",
 852                                                                                            false, array( '%objectname' => $name ) ),
 853                                                                   'actions' => array( EZ_PACKAGE_CONTENTOBJECT_DELETE => ezi18n( 'kernel/package', 'Remove' ),
 854                                                                                       EZ_PACKAGE_CONTENTOBJECT_KEEP => ezi18n( 'kernel/package', 'Keep object' ) ) );
 855                              return false;
 856                          }
 857                      }
 858  
 859                      $assignedNodes = $object->attribute( 'assigned_nodes' );
 860                      $assignedNodeIDArray = array();
 861                      foreach( $assignedNodes as $node )
 862                      {
 863                          $assignedNodeIDArray[] = $node->attribute( 'node_id' );
 864                      }
 865                      if ( count( $assignedNodeIDArray ) == 0 )
 866                          continue;
 867                      $info = eZContentObjectTreeNode::subtreeRemovalInformation( $assignedNodeIDArray );
 868                      $childrenCount = $info['total_child_count'];
 869  
 870                      if ( $childrenCount > 0 )
 871                      {
 872                          $choosenAction = $this->errorChoosenAction( EZ_PACKAGE_CONTENTOBJECT_ERROR_HAS_CHILDREN,
 873                                                                      $installParameters );
 874  
 875                          if ( $choosenAction == EZ_PACKAGE_CONTENTOBJECT_KEEP )
 876                          {
 877                              continue;
 878                          }
 879                          if ( $choosenAction != EZ_PACKAGE_CONTENTOBJECT_DELETE )
 880                          {
 881                              $installParameters['error'] = array( 'error_code' => EZ_PACKAGE_CONTENTOBJECT_ERROR_HAS_CHILDREN,
 882                                                                   'element_id' => $objectRemoteID,
 883                                                                   'description' => ezi18n( 'kernel/package',
 884                                                                                            "Object '%objectname' has %childrencount sub-item(s) that will be removed.",
 885                                                                                            false, array( '%objectname' => $name,
 886                                                                                                          '%childrencount' => $childrenCount ) ),
 887                                                                   'actions' => array( EZ_PACKAGE_CONTENTOBJECT_DELETE => ezi18n( 'kernel/package', "Remove object and it's sub-item(s)" ),
 888                                                                                       EZ_PACKAGE_CONTENTOBJECT_KEEP => ezi18n( 'kernel/package', 'Keep object' ) ) );
 889                              return false;
 890                          }
 891                      }
 892  
 893                      eZContentObjectTreeNode::removeSubtrees( $assignedNodeIDArray, false );
 894  
 895                      //include_once( 'kernel/classes/ezcontentobjectoperations.php' );
 896  
 897                      //eZContentObjectOperations::remove( $object->attribute( 'id' ) );
 898                  }
 899                  else
 900                  {
 901                      eZDebug::writeNotice( "Can't uninstall object '$name': object not found", 'eZContentObjectPackageHandler::uninstall' );
 902                  }
 903  
 904                  unset( $realObjectNode );
 905              }
 906          }
 907          return true;
 908      }
 909  
 910      /*!
 911       \reimp
 912       Creates a new contentobject as defined in the xml structure.
 913      */
 914      function install( &$package, $installType, $parameters,
 915                        $name, $os, $filename, $subdirectory,
 916                        &$content, &$installParameters,
 917                        &$installData )
 918      {
 919          $this->Package =& $package;
 920  
 921          if ( isset( $installParameters['error']['error_code'] ) )
 922              $errorCode = $installParameters['error']['error_code'];
 923          else
 924              $errorCode = false;
 925  
 926          // Error codes reservered for content object installation
 927          if ( !$errorCode || ( $errorCode >= EZ_PACKAGE_CONTENTOBJECT__INSTALL_OBJECTS_ERROR_RANGE_FROM &&
 928                                $errorCode <= EZ_PACKAGE_CONTENTOBJECT__INSTALL_OBJECTS_ERROR_RANGE_TO ) )
 929          {
 930              $objectListNode = $content->elementByName( 'object-list' );
 931              if ( !$objectListNode )
 932              {
 933                  $objectListNode = $content->elementByName( 'object-files-list' );
 934              }
 935              $objectNodes = $objectListNode->Children;
 936  
 937              if ( !$this->installContentObjects( $objectNodes,
 938                                                  $content->elementByName( 'top-node-list' ),
 939                                                  $installParameters ) )
 940                  return false;
 941              $errorCode = false;
 942          }
 943  
 944          if ( !$this->installTemplates( $content->elementByName( 'template-list' ),
 945                                         $package,
 946                                         $subdirectory,
 947                                         $installParameters ) )
 948              return false;
 949  
 950  
 951          if ( !$this->installOverrides( $content->elementByName( 'override-list' ),
 952                                         $installParameters ) )
 953              return false;
 954  
 955          if ( !$this->installFetchAliases( $content->elementByName( 'fetch-alias-list' ),
 956                                            $installParameters ) )
 957              return false;
 958  
 959          return true;
 960      }
 961  
 962      /*!
 963       \private
 964  
 965       Serialize and install content objects
 966  
 967       \param object-list DOMNode
 968       \param install parameters
 969      */
 970      function installContentObjects( $objectNodes, $topNodeListNode, &$installParameters )
 971      {
 972          include_once ( 'kernel/classes/ezcontentobject.php' );
 973          if ( isset( $installParameters['user_id'] ) )
 974              $userID = $installParameters['user_id'];
 975          else
 976              $userID = eZUser::currentUserID();
 977  
 978          $handlerType = $this->handlerType();
 979  
 980          foreach( $objectNodes as $objectNode )
 981          {
 982              $realObjectNode = $this->getRealObjectNode( $objectNode );
 983  
 984              // Cycle until we reach an element where error has occured.
 985              // If action has been choosen, try install this item again, else skip it.
 986              if ( isset( $installParameters['error']['error_code'] ) &&
 987                   !$this->isErrorElement( $realObjectNode->attributeValue( 'remote_id' ), $installParameters ) )
 988                  continue;
 989  
 990              $newObject = eZContentObject::unserialize( $this->Package, $realObjectNode, $installParameters, $userID, $handlerType );
 991              if ( !$newObject )
 992                  return false;
 993  
 994              if ( is_object( $newObject ) )
 995              {
 996                  eZContentObject::clearCache( $newObject->attribute( 'id' ) );
 997                  unset( $newObject );
 998              }
 999              unset( $realObjectNode );
1000  
1001              if ( isset( $installParameters['error'] ) && count( $installParameters['error'] ) )
1002                  $installParameters['error'] = array();
1003          }
1004  
1005          $this->installSuspendedNodeAssignment( $installParameters );
1006          $this->installSuspendedObjectRelations( $installParameters );
1007  
1008          // Call postUnserialize on all installed objects
1009          foreach( $objectNodes as $objectNode )
1010          {
1011              if ( $objectNode->nodeName == 'object' )
1012              {
1013                  $remoteID = $objectNode->getAttribute( 'remote_id' );
1014              }
1015              else
1016              {
1017                  $remoteID = substr( $objectNode->getAttribute( 'filename' ), 7, 32 );
1018              }
1019  
1020              $object =& eZContentObject::fetchByRemoteID( $remoteID );
1021              $object->postUnserialize( $package );
1022              eZContentObject::clearCache( $object->attribute( 'id' ) );
1023              unset( $object );
1024          }
1025  
1026          return true;
1027      }
1028  
1029      /*!
1030      \private
1031  
1032      \param install parameters
1033      */
1034      function installSuspendedNodeAssignment( &$installParameters )
1035      {
1036          if ( !isset( $installParameters['suspended-nodes'] ) )
1037          {
1038              return;
1039          }
1040          foreach ( $installParameters['suspended-nodes'] as $parentNodeRemoteID => $suspendedNodeInfo )
1041          {
1042              $parentNode = eZContentObjectTreeNode::fetchByRemoteID( $parentNodeRemoteID );
1043              if ( $parentNode !== null )
1044              {
1045                  $nodeInfo =& $suspendedNodeInfo['nodeinfo'];
1046                  $nodeInfo['parent_node'] = $parentNode->attribute( 'node_id' );
1047  
1048                  $existNodeAssignment = eZPersistentObject::fetchObject( eZNodeAssignment::definition(),
1049                                                             null,
1050                                                             $nodeInfo );
1051                  $nodeInfo['priority'] = $suspendedNodeInfo['priority'];
1052                  if( !is_object( $existNodeAssignment ) )
1053                  {
1054                      $nodeAssignment =& eZNodeAssignment::create( $nodeInfo );
1055                      $nodeAssignment->store();
1056                  }
1057  
1058                  $contentObject = eZContentObject::fetch( $nodeInfo['contentobject_id'] );
1059                  if ( is_object( $contentObject ) && $contentObject->attribute( 'current_version' ) == $nodeInfo['contentobject_version'] )
1060                  {
1061                      include_once ( 'lib/ezutils/classes/ezoperationhandler.php' );
1062                     eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $nodeInfo['contentobject_id'],
1063                                                                                'version' =>  $nodeInfo['contentobject_version'] ) );
1064                  }
1065                  if ( isset( $nodeInfo['is_main'] ) && $nodeInfo['is_main'] )
1066                  {
1067                      $existingMainNode = eZContentObjectTreeNode::fetchByRemoteID( $nodeInfo['parent_remote_id'], false );
1068                      if ( $existingMainNode )
1069                      {
1070                          eZContentObjectTreeNode::updateMainNodeID( $existingMainNode['node_id'],
1071                                                                     $nodeInfo['contentobject_id'],
1072                                                                     $nodeInfo['contentobject_version'],
1073                                                                     $nodeInfo['parent_node'] );
1074                      }
1075                  }
1076              }
1077              else
1078              {
1079                  eZDebug::writeError( 'Can not find parent node by remote-id ID = ' . $parentNodeRemoteID, 'eZContentObjectPackageHandler::installSuspendedNodeAssignment()' );
1080              }
1081              unset( $installParameters['suspended-nodes'][$parentNodeRemoteID] );
1082          }
1083      }
1084  
1085      /*!
1086       \private
1087  
1088       Installs suspended content object relations (need for complex content-relations structure)
1089  
1090       \param install parameters
1091      */
1092      function installSuspendedObjectRelations( &$installParameters )
1093      {
1094          if ( !isset( $installParameters['suspended-relations'] ) )
1095          {
1096              return;
1097          }
1098          foreach( $installParameters['suspended-relations'] as $suspendedObjectRelation )
1099          {
1100              $contentObjectID =        $suspendedObjectRelation['contentobject-id'];
1101              $contentObjectVersionID = $suspendedObjectRelation['contentobject-version'];
1102  
1103              $contentObjectVersion = eZContentObjectVersion::fetchVersion( $contentObjectVersionID, $contentObjectID );
1104              if ( is_object( $contentObjectVersion ) )
1105              {
1106                  $relatedObjectRemoteID = $suspendedObjectRelation['related-object-remote-id'];
1107                  $relatedObject = eZContentObject::fetchByRemoteID( $relatedObjectRemoteID );
1108                  $relatedObjectID = ( $relatedObject !== null ) ? $relatedObject->attribute( 'id' ) : null;
1109  
1110                  if ( $relatedObjectID )
1111                  {
1112                      $relatedObject->addContentObjectRelation( $relatedObjectID, $contentObjectVersionID, $contentObjectID );
1113                  }
1114                  else
1115                  {
1116                      eZDebug::writeError( 'Can not find related object by remote-id ID = ' . $relatedObjectRemoteID, 'eZContentObjectPackageHandler::installSuspendedObjectRelations()' );
1117                  }
1118              }
1119          }
1120          unset( $installParameters['suspended-relations'] );
1121      }
1122  
1123      /*!
1124       \private
1125  
1126       Set and install templates
1127  
1128       \param template list
1129       \param package
1130       \param subdirectory
1131       \param install parameters.
1132      */
1133      function installTemplates( $templateList, &$package, $subdirectory, &$installParameters )
1134      {
1135          if ( !$templateList )
1136          {
1137              return true;
1138          }
1139          include_once ( 'kernel/common/eztemplatedesignresource.php' );
1140  
1141          $siteAccessDesignPathArray = array();
1142          $templateRootPath = $package->path() . '/' . $subdirectory;
1143          foreach( $templateList->elementsByName( 'file' ) as $fileNode )
1144          {
1145              $originalSiteAccess = $fileNode->attributeValue( 'site-access' );
1146              if ( isset( $installParameters['site_access_map'][$originalSiteAccess] ) )
1147              {
1148                  $newSiteAccess = $installParameters['site_access_map'][$originalSiteAccess];
1149              }
1150              else
1151              {
1152                  $newSiteAccess = $installParameters['site_access_map']['*'];
1153              }
1154  
1155              if ( !isset( $siteAccessDesignPathArray[$newSiteAccess] ) )
1156              {
1157                  $ini =& eZINI::instance( 'site.ini', 'settings', null, null, true );
1158                  $ini->prependOverrideDir( "siteaccess/$newSiteAccess", false, 'siteaccess' );
1159                  $ini->loadCache();
1160  
1161                  if ( isset( $installParameters['design_map'] ) )
1162                  {
1163                      $designMap = $installParameters['design_map'];
1164                      if ( isset( $designMap[$originalSiteAccess] ) )
1165                          $siteAccessDesignPathArray[$newSiteAccess] = eZTemplateDesignResource::designStartPath() . '/' . $designMap[$originalSiteAccess];
1166                      else
1167                          $siteAccessDesignPathArray[$newSiteAccess] = eZTemplateDesignResource::designStartPath() . '/' . $designMap['*'];
1168                  }
1169                  else
1170                  {
1171                      $siteAccessDesignPathArray[$newSiteAccess] = eZTemplateDesignResource::designStartPath() . '/' . $ini->variable( "DesignSettings", "StandardDesign" );
1172                  }
1173              }
1174  
1175              $sourcePath = $templateRootPath . $fileNode->elementTextContentByName('path');
1176              $destinationPath = $siteAccessDesignPathArray[$newSiteAccess] . $fileNode->elementTextContentByName('path');
1177  
1178              eZDir::mkdir( eZDir::dirpath( $destinationPath ), false, true );
1179              if ( !eZFileHandler::copy( $sourcePath, $destinationPath ) )
1180                  return false;
1181  
1182  //             eZDebug::writeNotice( 'Copied: "' . $sourcePath . '" to: "' . $destinationPath . '"',
1183  //                                   'eZContentObjectPackageHandler::installTemplates()' );
1184          }
1185          return true;
1186      }
1187  
1188      /*!
1189       \private
1190  
1191       Install overrides
1192  
1193       \param override list
1194       \param install parameters
1195      */
1196      function installOverrides( $overrideListNode, &$parameters )
1197      {
1198          if ( !$overrideListNode )
1199          {
1200              return true;
1201          }
1202  
1203          $overrideINIArray = array();
1204          foreach( $overrideListNode->elementsByName( 'block' ) as $blockNode )
1205          {
1206              if ( isset( $parameters['site_access_map'][$blockNode->attributeValue( 'site-access' )] ) )
1207              {
1208                  $newSiteAccess = $parameters['site_access_map'][$blockNode->attributeValue( 'site-access' )];
1209              }
1210              else
1211              {
1212                  $newSiteAccess = $parameters['site_access_map']['*'];
1213              }
1214  
1215              if ( !$newSiteAccess )
1216              {
1217                  eZDebug::writeError( 'SiteAccess map for : ' . $blockNode->attributeValue( 'site-access' ) . ' not set.',
1218                                       'eZContentObjectPackageHandler::installOverrides()' );
1219                  continue;
1220              }
1221  
1222              if ( !isset( $overrideINIArray[$newSiteAccess] ) )
1223              {
1224                  $overrideINIArray[$newSiteAccess] =& eZINI::instance( 'override.ini.append.php', "settings/siteaccess/$newSiteAccess", null, null, true );
1225              }
1226  
1227              $blockArray = array();
1228              $blockName = $blockNode->attributeValue( 'name' );
1229              $blockArray[$blockName] = eZDOMDocument::createArrayFromDOMNode( $blockNode->elementByName( $blockName ) );
1230  
1231              if ( isset( $blockArray[$blockName][$this->OverrideObjectRemoteID] ) )
1232              {
1233                  $contentObject =& eZContentObject::fetchByRemoteID( $blockArray[$blockName][$this->OverrideObjectRemoteID] );
1234                  $blockArray[$blockName]['Match']['object'] = $contentObject->attribute( 'id' );
1235                  unset( $blockArray[$blockName][$this->OverrideObjectRemoteID] );
1236  //                 eZDebug::writeNotice( 'Found object id: "' . $blockArray[$blockName]['Match']['object'] . '" for matchblock "[' . $blockName . '][Match][object]"',
1237  //                                       'eZContentObjectPackageHandler::installOverrides()' );
1238              }
1239              if ( isset( $blockArray[$blockName][$this->OverrideNodeRemoteID] ) )
1240              {
1241                  $contentNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName][$this->OverrideNodeRemoteID] );
1242                  $blockArray[$blockName]['Match']['node'] = $contentNode->attribute( 'node_id' );
1243                  unset( $blockArray[$blockName][$this->OverrideNodeRemoteID] );
1244  //                 eZDebug::writeNotice( 'Found node id: "' . $blockArray[$blockName]['Match']['node'] . '" for matchblock "[' . $blockName . '][Match][node]"',
1245  //                                       'eZContentObjectPackageHandler::installOverrides()' );
1246              }
1247              if ( isset( $blockArray[$blockName][$this->OverrideParentNodeRemoteID] ) )
1248              {
1249                  $parentContentNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName][$this->OverrideParentNodeRemoteID] );
1250                  $blockArray[$blockName]['Match']['parent_node'] = $parentContentNode->attribute( 'node_id' );
1251                  unset( $blockArray[$blockName][$this->OverrideParentNodeRemoteID] );
1252  //                 eZDebug::writeNotice( 'Found parent node id: "' . $blockArray[$blockName]['Match']['parent_node'] . '" for matchblock "[' . $blockName . '][Match][parent_node]"',
1253  //                                       'eZContentObjectPackageHandler::installOverrides()' );
1254              }
1255              if ( isset( $blockArray[$blockName][$this->OverrideClassRemoteID] ) )
1256              {
1257                  $contentClass = eZContentClass::fetchByRemoteID( $blockArray[$blockName][$this->OverrideClassRemoteID] );
1258                  if ( !$contentClass )
1259                  {
1260                      eZDebug::writeError( 'No content class found for RemoteID: ' . $blockArray[$blockName][$this->OverrideClassRemoteID],
1261                                           'eZContentObjectPackageHandler::installOverrides()' );
1262                      continue;
1263                  }
1264                  $blockArray[$blockName]['Match']['class'] = $contentClass->attribute( 'id' );
1265                  unset( $blockArray[$blockName][$this->OverrideClassRemoteID] );
1266  //                 eZDebug::writeNotice( 'Found class id: "' . $blockArray[$blockName]['Match']['class'] . '" for matchblock "[' . $blockName . '][Match][class]"',
1267  //                                       'eZContentObjectPackageHandler::installOverrides()' );
1268              }
1269  
1270              $overrideINIArray[$newSiteAccess]->setVariables( $blockArray );
1271          }
1272  
1273          foreach( $overrideINIArray as $siteAccess => $iniArray )
1274          {
1275              $overrideINIArray[$siteAccess]->save();
1276          }
1277  
1278          return true;
1279      }
1280  
1281      /*!
1282       \private
1283  
1284       Install fetch alias overrides
1285  
1286       \param fetch alias  list
1287       \param install parameters
1288      */
1289      function installFetchAliases( $fetchAliasListNode, &$parameters )
1290      {
1291          if ( !$fetchAliasListNode )
1292          {
1293              return true;
1294          }
1295  
1296          $fetchAliasINIArray = array();
1297          foreach( $fetchAliasListNode->elementsByName( 'fetch-alias' ) as $blockNode )
1298          {
1299              if ( isset( $parameters['site_access_map'][$blockNode->attributeValue( 'site-access' )] ) )
1300              {
1301                  $newSiteAccess = $parameters['site_access_map'][$blockNode->attributeValue( 'site-access' )];
1302              }
1303              else
1304              {
1305                  $newSiteAccess = $parameters['site_access_map']['*'];
1306              }
1307  
1308              if ( !isset( $fetchAliasINIArray[$newSiteAccess] ) )
1309              {
1310                  $fetchAliasINIArray[$newSiteAccess] =& eZINI::instance( 'fetchalias.ini.append.php', "settings/siteaccess/$newSiteAccess", null, null, true );
1311              }
1312  
1313              $blockArray = array();
1314              $blockName = $blockNode->attributeValue( 'name' );
1315              $blockArray[$blockName] = eZDOMDocument::createArrayFromDOMNode( $blockNode->elementByName( $blockName ) );
1316  
1317              //$blockArray[$blockName] = $blockArray[$blockName][0];
1318  
1319              if ( isset( $blockArray[$blockName]['Constant'] ) && is_array( $blockArray[$blockName]['Constant'] ) && count( $blockArray[$blockName]['Constant'] ) > 0 )
1320              {
1321                  foreach( $blockArray[$blockName]['Constant'] as $matchKey => $value )
1322                  {
1323                      if ( strpos( $matchKey, 'class_' ) === 0 &&
1324                           is_int( $value ) )
1325                      {
1326                          $contentClass = eZContentClass::fetchByRemoteID( $blockArray[$blockName]['Constant']['class_remote_id'] );
1327                          $blockArray[$blockName]['Constant'][$matchKey] = $contentClass->attribute( 'id' );
1328                          unset( $blockArray[$blockName]['Constant']['class_remote_id'] );
1329                      }
1330                      if( strpos( $matchKey, 'node_' ) === 0 &&
1331                          is_int( $value ) )
1332                      {
1333                          $contentTreeNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName]['Constant']['node_remote_id'] );
1334                          $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'node_id' );
1335                          unset( $blockArray[$blockName]['Constant']['node_remote_id'] );
1336                      }
1337                      if( strpos( $matchKey, 'parent_node_' ) === 0 &&
1338                          is_int( $value ) )
1339                      {
1340                          $contentTreeNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName]['Constant']['parent_node_remote_id'] );
1341                          $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'node_id' );
1342                          unset( $blockArray[$blockName]['Constant']['parent_node_remote_id'] );
1343                      }
1344                      if( strpos( $matchKey, 'object_' ) === 0 &&
1345                          is_int( $value ) )
1346                      {
1347                          $contentObject =& eZContentObject::fetchByRemoteID( $blockArray[$blockName]['Constant']['object_remote_id'] );
1348                          $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'id' );
1349                          unset( $blockArray[$blockName]['Constant']['object_remote_id'] );
1350                      }
1351                  }
1352              }
1353  
1354              $fetchAliasINIArray[$newSiteAccess]->setVariables( $blockArray );
1355          }
1356  
1357          foreach( $fetchAliasINIArray as $siteAccess => $iniFetchAlias )
1358          {
1359              $fetchAliasINIArray[$siteAccess]->save();
1360          }
1361  
1362          return true;
1363      }
1364  
1365      /*!
1366       \reimp
1367      */
1368      function add( $packageType, &$package, &$cli, $parameters )
1369      {
1370          $options = array();
1371          foreach ( $parameters['node-list'] as $nodeItem )
1372          {
1373              $nodeIDList = $nodeItem['node-id-list'];
1374              foreach ( $nodeIDList as $nodeIDItem )
1375              {
1376                  $this->addNode( $nodeIDItem['id'], $nodeIDItem['subtree'] );
1377                  unset( $node );
1378                  $node = false;
1379                  if ( isset( $nodeIDItem['node'] ) )
1380                      $node =& $nodeIDItem['node'];
1381                  else
1382                      $node = eZContentObjectTreeNode::fetch( $nodeIDItem['id'] );
1383                  $cli->notice( "Adding node /" . $node->attribute( 'path_identification_string' ) . " to package" );
1384              }
1385          }
1386          $options['include_classes'] = $parameters['include-classes'];
1387          $options['include_templates'] = $parameters['include-templates'];
1388          $options['node_assignment'] = $parameters['node-assignment-type'];
1389          $options['site_access_array'] = $parameters['siteaccess-list'];
1390          $options['language_array'] = $parameters['language-list'];
1391          $options['versions'] = $parameters['version-type'];
1392          $options['related_objects'] = $parameters['related-type'];
1393          $options['embed_objects'] = $parameters['embed-type'];
1394          $options['minimal_template_set'] = $parameters['minimal-template-set'];
1395          $this->generatePackage( $package, $options );
1396      }
1397  
1398      /*!
1399       \reimp
1400      */
1401      function handleAddParameters( $packageType, &$package, &$cli, $arguments )
1402      {
1403          return $this->handleParameters( $packageType, $package, $cli, 'add', $arguments );
1404      }
1405  
1406      /*!
1407       \private
1408      */
1409      function handleParameters( $packageType, &$package, &$cli, $type, $arguments )
1410      {
1411          $nodeList = array();
1412          $includeClasses = true;
1413          $includeTemplates = true;
1414          $siteAccessList = array();
1415          $nodeAssignmentType = 'main';
1416          $relatedObjectType = 'selected';
1417          $embedObjectType = 'selected';
1418          $versionType = 'current';
1419          $languageList = array();
1420          $minimalTemplateSet = false;
1421          $nodeItem = array( 'node-id-list' => array() );
1422          $longOptions = array( 'include-classes' => 'include-classes',
1423                                'include-templates' => 'include-templates',
1424                                'exclude-classes' => 'exclude-classes',
1425                                'exclude-templates' => 'exclude-templates',
1426                                'language' => 'language',
1427                                'current-version' => 'current-version',
1428                                'all-versions' => 'all-versions',
1429                                'node-main' => 'node-main',
1430                                'node-selected' => 'node-selected',
1431                                'siteaccess' => 'siteaccess',
1432                                'minimal-template-set' => 'minimal-template-set' );
1433          $shortOptions = array();
1434          $error = false;
1435          foreach ( $arguments as $argument )
1436          {
1437              if ( $argument[0] == '-' )
1438              {
1439                  if ( strlen( $argument ) > 1 and
1440                       $argument[1] == '-' )
1441                  {
1442                      $option = substr( $argument, 2 );
1443                      $valuePos = strpos( $option, '=' );
1444                      $optionValue = false;
1445                      if ( $valuePos !== false )
1446                      {
1447                          $optionValue = substr( $option, $valuePos + 1 );
1448                          $option = substr( $option, 0, $valuePos );
1449                      }
1450                      if ( isset( $longOptions[$option] ) )
1451                          $optionName = $longOptions[$option];
1452                      else
1453                          $optionName = false;
1454                  }
1455                  else
1456                  {
1457                      $option = substr( $argument, 1 );
1458                      if ( isset( $shortOptions[$option] ) )
1459                          $optionName = $shortOptions[$option];
1460                      else
1461                          $optionName = false;
1462                  }
1463                  if ( $optionName == 'include-classes' or $optionName == 'exclude-classes' )
1464                  {
1465                      if ( count( $nodeItem['node-id-list'] ) > 0 )
1466                      {
1467                          $nodeList[] = $nodeItem;
1468                          $nodeItem['node-id-list'] = array();
1469                      }
1470                      $includeClasses = ( $optionName == 'include-classes' );
1471                  }
1472                  else if ( $optionName == 'include-templates' or $optionName == 'exclude-templates' )
1473                  {
1474                      if ( count( $nodeItem['node-id-list'] ) > 0 )
1475                      {
1476                          $nodeList[] = $nodeItem;
1477                          $nodeItem['node-id-list'] = array();
1478                      }
1479                      $includeTemplates = ( $optionName == 'include-templates' );
1480                  }
1481                  else if ( $optionName == 'node-main' )
1482                  {
1483                      $nodeAssignmentType = 'main';
1484                  }
1485                  else if ( $optionName == 'node-selected' )
1486                  {
1487                      $nodeAssignmentType = 'selected';
1488                  }
1489                  else if ( $optionName == 'siteaccess' )
1490                  {
1491                      $siteAccessList = explode( ',', $optionValue );
1492                  }
1493                  else if ( $optionName == 'language' )
1494                  {
1495                      $languageList = explode( ',', $optionValue );
1496                  }
1497                  else if ( $optionName == 'current-version' )
1498                  {
1499                      $versionType = 'current';
1500                  }
1501                  else if ( $optionName == 'all-versions' )
1502                  {
1503                      $versionType = 'all';
1504                  }
1505                  else if ( $optionName == 'minimal-template-set' )
1506                  {
1507                      $minimalTemplateSet = true;
1508                  }
1509              }
1510              else
1511              {
1512                  $nodeID = false;
1513                  $subtree = false;
1514                  if ( is_numeric( $argument ) )
1515                  {
1516                      $nodeID = (int)$argument;
1517                      $node = eZContentObjectTreeNode::fetch( $nodeID );
1518                      if ( !is_object( $node ) )
1519                      {
1520                          $error = true;
1521                          $nodeID = false;
1522                          $cli->notice( "Could not find content-node using ID " . $cli->stylize( 'emphasize', $nodeID ) );
1523                      }
1524                  }
1525                  else
1526                  {
1527                      $path = $argument;
1528                      if ( preg_match( "#(.+)/\*$#", $path, $matches ) )
1529                      {
1530                          $path = $matches[1];
1531                          $subtree = true;
1532                      }
1533                      $node = eZContentObjectTreeNode::fetchByURLPath( $path );
1534                      if ( is_object( $node ) )
1535                      {
1536                          $nodeID = $node->attribute( 'node_id' );
1537                      }
1538                      else
1539                      {
1540                          $cli->notice( "Could not find content-node using path " . $cli->stylize( 'emphasize', $path ) );
1541                          $error = true;
1542                      }
1543                  }
1544                  if ( $nodeID )
1545                  {
1546                      $nodeItem['node-id-list'][] = array( 'id' => $nodeID,
1547                                                           'subtree' => $subtree,
1548                                                           'node' => &$node );
1549                  }
1550                  if ( $error )
1551                      return false;
1552              }
1553          }
1554          if ( count( $nodeItem['node-id-list'] ) > 0 )
1555          {
1556              $nodeList[] = $nodeItem;
1557          }
1558          if ( count( $nodeList ) == 0 )
1559          {
1560              $cli->error( "No objects chosen" );
1561              return false;
1562          }
1563          if ( count( $languageList ) == 0 )
1564          {
1565              // The default is to fetch all languages
1566              include_once ( 'kernel/classes/ezcontentlanguage.php' );
1567              $languageList = eZContentLanguage::fetchLocaleList();
1568          }
1569          if ( count( $siteAccessList ) == 0 )
1570          {
1571              $ini =& eZINI::instance();
1572              $siteAccessList[] = $ini->variable( 'SiteSettings', 'DefaultAccess' );
1573          }
1574          return array( 'node-list' => $nodeList,
1575                        'include-classes' => $includeClasses,
1576                        'include-templates' => $includeTemplates,
1577                        'siteaccess-list' => $siteAccessList,
1578                        'language-list' => $languageList,
1579                        'node-assignment-type' => $nodeAssignmentType,
1580                        'related-type' => $relatedObjectType,
1581                        'embed-type' => $embedObjectType,
1582                        'version-type' => $versionType,
1583                        'minimal-template-set' => $minimalTemplateSet,
1584                        );
1585      }
1586  
1587      function contentObjectDirectory()
1588      {
1589          return 'ezcontentobject';
1590      }
1591  
1592      /*!
1593       \reimp
1594      */
1595      /*function createInstallNode( &$package, &$installNode, $installItem, $installType )
1596      {
1597          if ( $installNode->attributeValue( 'type' ) == 'ezcontentobject' )
1598          {
1599              if ( $export )
1600              {
1601                  $objectFile = $installItem['filename'] . '.xml';
1602  
1603                  if ( $installItem['sub-directory'] )
1604                      $objectFile = $installItem['sub-directory'] . '/' . $objectFile;
1605                  $originalPath = $package->path() . '/' . $objectFile;
1606                  $exportPath = $export['path'];
1607                  $installDirectory = $exportPath . '/' . eZContentObjectPackageHandler::contentObjectDirectory();
1608                  if ( !file_exists(  $installDirectory ) )
1609                      eZDir::mkdir( $installDirectory, eZDir::directoryPermission(), true );
1610  
1611                  include_once( 'lib/ezfile/classes/ezfile.php' );
1612                  $eZXML = new eZXML();
1613                  $domDocument = $eZXML->domTree( eZFile::getContents( $originalPath ) );
1614                  $rootNode = $domDocument->root();
1615                  $templateListNode = $rootNode->elementByName( 'template-list' );
1616                  foreach( $templateListNode ? $templateListNode->elementsByName( 'file' ) : array() as $fileNode )
1617                  {
1618                      $newFilePath = $installDirectory . $fileNode->elementTextContentByName( 'path' );
1619                      if ( !file_exists( eZDir::dirpath( $newFilePath ) ) )
1620                      {
1621                          eZDir::mkdir( eZDir::dirpath( $newFilePath ), eZDir::directoryPermission(), true );
1622                      }
1623                      eZFileHandler::copy( $package->path() . '/' . eZContentObjectPackageHandler::contentObjectDirectory() . $fileNode->elementTextContentByName( 'path' ),
1624                                           $newFilePath );
1625                  }
1626                  eZFileHandler::copy( $originalPath, $installDirectory . '/' . $installItem['filename'] . '.xml' );
1627              }
1628          }
1629      }
1630      */
1631  
1632      var $NodeIDArray = array();
1633      var $RootNodeIDArray = array();
1634      var $NodeObjectArray = array();
1635      var $ObjectArray = array();
1636      var $RootNodeObjectArray = array();
1637      var $OverrideSettingsArray = array();
1638      var $TemplateFileArray = array();
1639      var $Package = null;
1640  
1641      // Static class variables - replacing match values in override.ini
1642      var $OverrideObjectRemoteID = 'content_object_remote_id';
1643      var $OverrideNodeRemoteID = 'content_node_remote_id';
1644      var $OverrideParentNodeRemoteID = 'parent_content_node_remote_id';
1645      var $OverrideClassRemoteID = 'content_class_remote_id';
1646  }
1647  
1648  ?>


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