00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 define( 'EZ_PACKAGE_CONTENTOBJECT__MAX_LISTED_OBJECTS_NUMBER', 30 );
00041
00042
00043
00044
00045 define( 'EZ_PACKAGE_CONTENTOBJECT__STORE_OBJECTS_TO_SEPARATE_FILES_THRESHOLD', 100 );
00046
00047 define( 'EZ_PACKAGE_CONTENTOBJECT__INSTALL_OBJECTS_ERROR_RANGE_FROM', 1 );
00048 define( 'EZ_PACKAGE_CONTENTOBJECT__INSTALL_OBJECTS_ERROR_RANGE_TO', 100 );
00049 define( 'EZ_PACKAGE_CONTENTOBJECT__UNINSTALL_OBJECTS_ERROR_RANGE_FROM', 101 );
00050 define( 'EZ_PACKAGE_CONTENTOBJECT__UNINSTALL_OBJECTS_ERROR_RANGE_TO', 200 );
00051
00052 include_once( 'lib/ezxml/classes/ezxml.php' );
00053 include_once( 'kernel/classes/ezcontentobject.php' );
00054 include_once( 'kernel/classes/ezpackagehandler.php' );
00055
00056 class eZContentObjectPackageHandler extends eZPackageHandler
00057 {
00058
00059
00060
00061 function eZContentObjectPackageHandler()
00062 {
00063 $this->eZPackageHandler( 'ezcontentobject',
00064 array( 'extract-install-content' => true ) );
00065 }
00066
00067
00068
00069
00070 function fetchObjectFromFile( $objectFileNode )
00071 {
00072 $fileName = $objectFileNode->getAttribute( 'filename' );
00073 $filePath = $this->Package->path() . '/' . $this->contentObjectDirectory() . '/' . $fileName;
00074 $dom =& $this->Package->fetchDOMFromFile( $filePath );
00075
00076 if ( $dom )
00077 {
00078 $objectNode =& $dom->root();
00079 }
00080 else
00081 {
00082 eZDebug::writeError( "Can't fetch object from package file: $filePath", 'eZContentObjectPackageHandler::getObjectNodeFromFile' );
00083 $objectNode = false;
00084 }
00085
00086 return $objectNode;
00087 }
00088
00089 function getRealObjectNode( $objectNode )
00090 {
00091 if ( $objectNode->nodeName == 'object' )
00092 {
00093 $realObjectNode =& $objectNode;
00094 }
00095 else
00096 {
00097 $realObjectNode = $this->fetchObjectFromFile( $objectNode );
00098 }
00099 return $realObjectNode;
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 function explainInstallItem( &$package, $installItem )
00118 {
00119 $this->Package =& $package;
00120
00121 if ( $installItem['filename'] )
00122 {
00123 $filename = $installItem['filename'];
00124 $subdirectory = $installItem['sub-directory'];
00125 if ( $subdirectory )
00126 $filepath = $subdirectory . '/' . $filename . '.xml';
00127 else
00128 $filepath = $filename . '.xml';
00129
00130 $filepath = $package->path() . '/' . $filepath;
00131
00132 $dom =& $package->fetchDOMFromFile( $filepath );
00133
00134 if ( !$dom )
00135 return null;
00136
00137 $content =& $dom->root();
00138 $objectListNode = $content->elementByName( 'object-list' );
00139 if ( $objectListNode )
00140 {
00141 $realObjectNodes =& $objectListNode->Children;
00142 }
00143 else
00144 {
00145
00146 $objectListNode = $content->elementByName( 'object-files-list' );
00147 $objectNodes = $objectListNode->Children;
00148
00149 if ( count( $objectNodes ) > EZ_PACKAGE_CONTENTOBJECT__MAX_LISTED_OBJECTS_NUMBER )
00150 {
00151 return array( 'description' => ezi18n( 'kernel/package', '%number content objects', false,
00152 array( '%number' => count( $objectNodes ) ) ) );
00153 }
00154
00155 $realObjectNodes = array();
00156 foreach( $objectNodes as $objectNode )
00157 {
00158 $realObjectNode = $this->fetchObjectFromFile( $objectNode );
00159 if ( !$realObjectNode )
00160 continue;
00161
00162 $realObjectNodes[] =& $realObjectNode;
00163 unset( $realObjectNode );
00164 }
00165 }
00166
00167
00168 $objectNames = array();
00169 foreach( $realObjectNodes as $objectNode )
00170 {
00171
00172
00173 $objectName =
00174 $objectNode->getAttribute( 'name' ) .
00175 ' (' . $objectNode->attributeValue( 'class_identifier' ) .')';
00176 $objectNames[] = array( 'description' =>
00177 ezi18n( 'kernel/package', 'Content object %objectname', false,
00178 array( '%objectname' => $objectName ) ) );
00179 }
00180 return $objectNames;
00181 }
00182 }
00183
00184
00185
00186
00187
00188
00189
00190 function addNode( $nodeID, $isSubtree = true )
00191 {
00192 include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
00193 $this->RootNodeIDArray[] = $nodeID;
00194 $this->NodeIDArray[] = $nodeID;
00195
00196 if ( $isSubtree )
00197 {
00198 $nodeArray =& eZContentObjectTreeNode::subtree( array( 'AsObject' => false ), $nodeID );
00199 foreach( $nodeArray as $node )
00200 {
00201 $this->NodeIDArray[] = $node['node_id'];
00202 }
00203 }
00204 }
00205
00206
00207
00208
00209
00210
00211
00212 function generatePackage( &$package, $options )
00213 {
00214 $this->Package =& $package;
00215 $remoteIDArray = array();
00216 $this->NodeIDArray = array_unique( $this->NodeIDArray );
00217 foreach( $this->NodeIDArray as $nodeID )
00218 {
00219 $this->NodeObjectArray[(string)$nodeID] = eZContentObjectTreeNode::fetch( $nodeID );
00220 }
00221
00222 foreach( $this->RootNodeIDArray as $nodeID )
00223 {
00224 $this->RootNodeObjectArray[(string)$nodeID] = eZContentObjectTreeNode::fetch( $nodeID );
00225 }
00226
00227 $this->generateObjectArray( $options['node_assignment'] );
00228
00229 $classIDArray = false;
00230 if ( $options['include_classes'] )
00231 {
00232 $remoteIDArray['class'] = array();
00233 $classIDArray =& $this->generateClassIDArray();
00234
00235 include_once( 'kernel/classes/packagehandlers/ezcontentclass/ezcontentclasspackagehandler.php' );
00236 foreach ( $classIDArray as $classID )
00237 {
00238 eZContentClassPackageHandler::addClass( $package, $classID );
00239 }
00240 }
00241
00242 $packageRoot = eZDOMDocument::createElementNode( 'content-object' );
00243
00244 $objectListDOMNode = $this->createObjectListNode( $options );
00245 $packageRoot->appendChild( $objectListDOMNode );
00246
00247 $overrideSettingsArray = false;
00248 $templateFilenameArray = false;
00249 if ( $options['include_templates'] )
00250 {
00251 $overrideSettingsListNode =& $this->generateOverrideSettingsArray( $options['site_access_array'], $options['minimal_template_set'] );
00252 $packageRoot->appendChild( $overrideSettingsListNode );
00253
00254 $designTemplateListNode =& $this->generateTemplateFilenameArray();
00255 $packageRoot->appendChild( $designTemplateListNode );
00256
00257 $fetchAliasListNode =& $this->generateFetchAliasArray();
00258 $packageRoot->appendChild( $fetchAliasListNode );
00259 }
00260
00261 $siteAccessListDOMNode = $this->createSiteAccessListNode( $options );
00262 $packageRoot->appendChild( $siteAccessListDOMNode );
00263
00264 $topNodeListDOMNode = $this->createTopNodeListDOMNode( $options );
00265 $packageRoot->appendChild( $topNodeListDOMNode );
00266
00267
00268 $filename = 'contentobjects';
00269 $this->Package->appendInstall( 'ezcontentobject', false, false, true,
00270 $filename, $this->contentObjectDirectory(),
00271 array( 'content' => $packageRoot ) );
00272 $this->Package->appendInstall( 'ezcontentobject', false, false, false,
00273 $filename, $this->contentObjectDirectory(),
00274 array( 'content' => false ) );
00275 }
00276
00277
00278
00279
00280
00281
00282
00283 function createTopNodeListDOMNode( $options )
00284 {
00285 $topNodeListDOMNode = eZDOMDocument::createElementNode( 'top-node-list' );
00286
00287 foreach( $this->RootNodeObjectArray as $topNode )
00288 {
00289 $topNodeListDOMNode->appendChild( eZDOMDocument::createElementTextNode( 'top-node', $topNode->attribute( 'name' ),
00290 array( 'node-id' => $topNode->attribute( 'node_id' ),
00291 'remote-id' => $topNode->attribute( 'remote_id' ) ) ) );
00292 }
00293
00294 return $topNodeListDOMNode;
00295 }
00296
00297
00298
00299
00300
00301
00302
00303 function createSiteAccessListNode( $options )
00304 {
00305 $siteAccessListDOMNode = eZDOMDocument::createElementNode( 'site-access-list' );
00306 foreach( $options['site_access_array'] as $siteAccess )
00307 {
00308 $siteAccessListDOMNode->appendChild( eZDOMDocument::createElementTextNode( 'site-access', $siteAccess ) );
00309 }
00310
00311 return $siteAccessListDOMNode;
00312 }
00313
00314
00315
00316
00317
00318
00319
00320 function createObjectListNode( $options )
00321 {
00322 if ( $options['versions'] == 'current' )
00323 {
00324 $version = true;
00325 }
00326 else
00327 {
00328 $version = false;
00329 }
00330
00331 $path = $this->Package->path() . '/' . $this->contentObjectDirectory();
00332 if ( !file_exists( $path ) )
00333 eZDir::mkdir( $path, eZDir::directoryPermission(), true );
00334
00335
00336 $storeToMultiple = count( $this->ObjectArray ) >= EZ_PACKAGE_CONTENTOBJECT__STORE_OBJECTS_TO_SEPARATE_FILES_THRESHOLD ? true : false;
00337 if ( $storeToMultiple )
00338 $objectListNode = eZDOMDocument::createElementNode( 'object-files-list' );
00339 else
00340 $objectListNode = eZDOMDocument::createElementNode( 'object-list' );
00341
00342 foreach( array_keys( $this->ObjectArray ) as $objectID )
00343 {
00344 $objectNode = $this->ObjectArray[$objectID]->serialize( $this->Package, $version, $options, $this->NodeObjectArray, $this->RootNodeIDArray );
00345
00346 if ( $storeToMultiple )
00347 {
00348 $fileName = 'object-' . $objectNode->getAttribute( 'remote_id' ) . '.xml';
00349 $filePath = $path . '/' . $fileName;
00350
00351 $objectFileNode = eZDOMDocument::createElementNode( 'object-file' );
00352 $objectFileNode->setAttribute( 'filename', $fileName );
00353 $objectListNode->appendChild( $objectFileNode );
00354
00355 $partDOM = new eZDOMDocument();
00356 $partDOM->setRoot( $objectNode );
00357 $this->Package->storeDOM( $filePath, $partDOM );
00358 unset( $partDOM );
00359 unset( $objectFileNode );
00360 }
00361 else
00362 {
00363 $objectListNode->appendChild( $objectNode );
00364 }
00365 unset( $objectNode );
00366 }
00367
00368 return $objectListNode;
00369 }
00370
00371
00372
00373
00374
00375
00376
00377 function generateObjectArray( $nodeAssignment )
00378 {
00379 foreach( array_keys( $this->NodeObjectArray ) as $key )
00380 {
00381 $contentNode =& $this->NodeObjectArray[$key];
00382 if ( $nodeAssignment == 'main' )
00383 {
00384 if ( $contentNode->attribute( 'main_node_id' ) == $contentNode->attribute( 'node_id' ) )
00385 {
00386 $this->ObjectArray[(string)$contentNode->attribute( 'contentobject_id' )] =& $contentNode->object();
00387 }
00388 }
00389 else
00390 {
00391 $this->ObjectArray[(string)$contentNode->attribute( 'contentobject_id' )] =& $contentNode->object();
00392 }
00393 }
00394 }
00395
00396
00397
00398
00399 function &generateFetchAliasArray()
00400 {
00401 $fetchAliasListDOMNode = eZDOMDocument::createElementNode( 'fetch-alias-list' );
00402 $registeredAliases = array();
00403
00404 foreach( array_keys( $this->TemplateFileArray ) as $siteAccess )
00405 {
00406 $aliasINI =& eZINI::instance( 'fetchalias.ini', 'settings', null, null, true );
00407 $aliasINI->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' );
00408 $aliasINI->loadCache();
00409
00410 foreach ( $this->TemplateFileArray[$siteAccess] as $filename )
00411 {
00412 $fp = fopen( $filename, 'r' );
00413 if ( !$fp )
00414 {
00415 eZDebug::writeError( 'Could not open ' . $filename . ' during content object export.',
00416 'eZContentObjectPackageHandler::generateFethAliasArray()' );
00417 continue;
00418 }
00419
00420 $str = fread( $fp, filesize( $filename ) );
00421
00422 $matchArray = array();
00423 preg_match_all( "#.*fetch_alias\([ ]*([a-zA-Z0-9_]+)[ |,|)]+.*#U", $str, $matchArray, PREG_PATTERN_ORDER );
00424
00425 foreach( $matchArray[1] as $fetchAlias )
00426 {
00427 if ( isset( $registeredAliases[$fetchAlias] ) )
00428 {
00429 continue;
00430 }
00431 $registeredAliases[$fetchAlias] = true;
00432
00433 unset( $fetchAliasDOMNode );
00434 $fetchAliasDOMNode = eZDOMDocument::createElementNode( 'fetch-alias', array( 'name' => $fetchAlias,
00435 'site-access' => $siteAccess ) );
00436
00437 $fetchBlock = $aliasINI->group( $fetchAlias );
00438 if ( isset( $fetchBlock['Constant'] ) )
00439 {
00440 foreach ( $fetchBlock['Constant'] as $matchKey => $value )
00441 {
00442 if ( strpos( $matchKey, 'class_' ) === 0 &&
00443 is_int( $value ) )
00444 {
00445 $contentClass = eZContentClass::fetch( $value );
00446 $fetchBlock['Constant']['class_remote_id'] = $contentClass->attribute( 'remote_id' );
00447 }
00448 if ( strpos( $matchKey, 'node_' ) === 0 &&
00449 is_int( $value ) )
00450 {
00451 $contentTreeNode = eZContentObjectTreeNode::fetch( $value );
00452 $fetchBlock['Constant']['node_remote_id'] = $contentTreeNode->attribute( 'remote_id' );
00453 }
00454 if ( strpos( $matchKey, 'parent_node_' ) === 0 &&
00455 is_int( $value ) )
00456 {
00457 $contentTreeNode = eZContentObjectTreeNode::fetch( $value );
00458 $fetchBlock['Constant']['parent_node_remote_id'] = $contentTreeNode->attribute( 'remote_id' );
00459 }
00460 if ( strpos( $matchKey, 'object_' ) === 0 &&
00461 is_int( $value ) )
00462 {
00463 $contentObject = eZContentObject::fetch( $value );
00464 $fetchBlock['Constant']['object_remote_id'] = $contentObject->attribute( 'remote_id' );
00465 }
00466 }
00467 }
00468 $fetchAliasDOMNode->appendChild( eZDOMDocument::createElementNodeFromArray( $fetchAlias, $fetchBlock ) );
00469 $fetchAliasListDOMNode->appendChild( $fetchAliasDOMNode );
00470 }
00471 }
00472 }
00473 return $fetchAliasListDOMNode;
00474 }
00475
00476
00477
00478
00479 function &generateTemplateFilenameArray()
00480 {
00481 $templateListDOMNode = eZDOMDocument::createElementNode( 'template-list' );
00482
00483 include_once( 'kernel/common/eztemplatedesignresource.php' );
00484
00485 foreach( array_keys( $this->OverrideSettingsArray ) as $siteAccess )
00486 {
00487 $this->TemplateFileArray[$siteAccess] = array();
00488 $overrideArray = eZTemplateDesignResource::overrideArray( $siteAccess );
00489
00490 foreach( $this->OverrideSettingsArray[$siteAccess] as $override )
00491 {
00492 $customMatchArray = $overrideArray['/' . $override['Source']]['custom_match'];
00493
00494 foreach( $customMatchArray as $customMatch )
00495 {
00496 if ( $customMatch['conditions'] == null )
00497 {
00498
00499
00500 }
00501 else if ( count( array_diff( $customMatch['conditions'], $override['Match'] ) ) == 0 &&
00502 count( array_diff( $override['Match'], $customMatch['conditions'] ) ) == 0 )
00503 {
00504 $templateListDOMNode->appendChild( $this->createDOMNodeFromFile( $customMatch['match_file'], $siteAccess, 'design' ) );
00505 $this->TemplateFileArray[$siteAccess][] = $customMatch['match_file'];
00506 }
00507 }
00508 }
00509 }
00510 return $templateListDOMNode;
00511
00512
00513 }
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523 function createDOMNodeFromFile( $filename, $siteAccess, $filetype = false )
00524 {
00525 $fileAttributes = array( 'site-access' => $siteAccess );
00526 if ( $filetype !== false )
00527 {
00528 $fileAttributes['file-type'] = $filetype;
00529 }
00530
00531 $path = substr( $filename, strpos( $filename, '/', 7 ) );
00532
00533 $fileDOMNode = eZDOMDocument::createElementNode( 'file', $fileAttributes );
00534 $fileDOMNode->appendChild( eZDOMDocument::createElementTextNode( 'original-path', $filename ) );
00535 $fileDOMNode->appendChild( eZDOMDocument::createElementTextNode( 'path', $path ) );
00536
00537 $destinationPath = $this->Package->path() . '/' . eZContentObjectPackageHandler::contentObjectDirectory() . '/' . $path;
00538 eZDir::mkdir( eZDir::dirpath( $destinationPath ), eZDir::directoryPermission(), true );
00539 eZFileHandler::copy( $filename, $destinationPath );
00540
00541 return $fileDOMNode;
00542 }
00543
00544
00545
00546
00547
00548
00549
00550 function &generateOverrideSettingsArray( $siteAccessArray, $minimalTemplateSet )
00551 {
00552 $datatypeHash = array();
00553 $simpleMatchList = array();
00554 $regexpMatchList = array();
00555 foreach ( $siteAccessArray as $siteAccess )
00556 {
00557 $overrideINI =& eZINI::instance( 'override.ini', 'settings', null, null, true );
00558 $overrideINI->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' );
00559 $overrideINI->loadCache();
00560
00561 $matchBlock = false;
00562 $blockMatchArray = array();
00563
00564 foreach( array_keys( $this->NodeObjectArray ) as $nodeID )
00565 {
00566
00567 unset( $contentNode, $contentObject, $contentClass );
00568 $contentNode =& $this->NodeObjectArray[$nodeID];
00569 $contentObject =& $contentNode->attribute( 'object' );
00570 $contentClass =& $contentObject->attribute( 'content_class' );
00571 $attributeList = $contentClass->fetchAttributes( false, false, false );
00572 $datatypeList = array();
00573 foreach ( $attributeList as $attribute )
00574 {
00575 $datatypeList[] = $attribute['data_type_string'];
00576 if ( !isset( $datatypeHash[$attribute['data_type_string']] ) )
00577 {
00578 include_once( 'kernel/classes/ezdatatype.php' );
00579 $datatype = eZDataType::create( $attribute['data_type_string'] );
00580 $datatypeHash[$attribute['data_type_string']] =& $datatype;
00581 if ( !method_exists( $datatype, 'templateList' ) )
00582 continue;
00583 $templateList = $datatype->templateList();
00584 if ( $templateList === false )
00585 continue;
00586 foreach ( $templateList as $templateMatch )
00587 {
00588 if ( is_string( $templateMatch ) )
00589 {
00590 $simpleMatchList[] = $templateMatch;
00591 }
00592 else if ( is_array( $templateMatch ) )
00593 {
00594 if ( $templateMatch[0] == 'regexp' )
00595 {
00596 $regexpMatchList[] = $templateMatch[1];
00597 }
00598 }
00599 }
00600 }
00601 }
00602 $datatypeText = implode( '|', array_unique( $datatypeList ) );
00603
00604 foreach( array_keys( $overrideINI->groups() ) as $blockName )
00605 {
00606 if ( isset( $blockMatchArray[$blockName] ) )
00607 {
00608 continue;
00609 }
00610
00611 $blockData = $overrideINI->group( $blockName );
00612 $sourceName = $blockData['Source'];
00613 $matchSettings = false;
00614 if ( isset( $blockData['Match'] ) )
00615 $matchSettings = $blockData['Match'];
00616
00617 $matchValue = array();
00618 $validMatch = true;
00619 $hasMatchType = false;
00620 if ( $matchSettings )
00621 {
00622 foreach( array_keys( $matchSettings ) as $matchType )
00623 {
00624 switch( $matchType )
00625 {
00626 case 'object':
00627 {
00628 $hasMatchType = true;
00629 if ( $contentNode->attribute( 'contentobject_id' ) != $matchSettings[$matchType] )
00630 {
00631 $validMatch = false;
00632 }
00633 else
00634 {
00635 $matchValue[$this->OverrideObjectRemoteID] = $contentObject->attribute( 'remote_id' );
00636 }
00637 } break;
00638
00639 case 'node':
00640 {
00641 $hasMatchType = true;
00642 if ( $nodeID != $matchSettings[$matchType] )
00643 {
00644 $validMatch = false;
00645 }
00646 else
00647 {
00648 $matchValue[$this->OverrideNodeRemoteID] = $contentNode->attribute( 'remote_id' );
00649 }
00650 } break;
00651
00652 case 'parent_node':
00653 {
00654 $hasMatchType = true;
00655 if ( $contentNode->attribute( 'parent_node_id' ) != $matchSettings[$matchType] )
00656 {
00657 $validMatch = false;
00658 }
00659 else
00660 {
00661 $parentNode = $contentNode->attribute( 'parent' );
00662 $matchValue[$this->OverrideParentNodeRemoteID] = $parentNode->attribute( 'remote_id' );
00663 }
00664 } break;
00665
00666 case 'class':
00667 {
00668 $hasMatchType = true;
00669 if ( $contentObject->attribute( 'contentclass_id' ) != $matchSettings[$matchType] )
00670 {
00671 $validMatch = false;
00672 }
00673 else
00674 {
00675 $matchValue[$this->OverrideClassRemoteID] = $contentClass->attribute( 'remote_id' );
00676 }
00677 } break;
00678
00679 case 'class_identifier':
00680 {
00681 $hasMatchType = true;
00682 if ( $contentObject->attribute( 'class_identifier' ) != $matchSettings[$matchType] )
00683 {
00684 $validMatch = false;
00685 }
00686 } break;
00687
00688 case 'section':
00689 {
00690 $hasMatchType = true;
00691 if ( $contentObject->attribute( 'section_id' ) != $matchSettings[$matchType] )
00692 {
00693 $validMatch = false;
00694 }
00695 } break;
00696
00697 case 'depth':
00698 {
00699 $hasMatchType = true;
00700 if ( $contentNode->attribute( 'depth' ) != $matchSettings[$matchType] )
00701 {
00702 $validMatch = false;
00703 }
00704 } break;
00705 }
00706
00707 if ( !$validMatch )
00708 {
00709 break;
00710 }
00711 }
00712 }
00713 else
00714 {
00715 $validMatch = false;
00716 }
00717
00718 if ( !$hasMatchType )
00719 {
00720
00721 if ( preg_match( "#^content/datatype/[a-zA-Z]+/(" . $datatypeText . ")\\.tpl$#", $sourceName ) )
00722 {
00723 $validMatch = true;
00724 $hasMatchType = true;
00725 }
00726 else if ( in_array( $sourceName, $simpleMatchList ) )
00727 {
00728 $validMatch = true;
00729 $hasMatchType = true;
00730 }
00731 else
00732 {
00733 foreach ( $regexpMatchList as $regexpMatch )
00734 {
00735 if ( preg_match( $regexpMatch, $sourceName ) )
00736 {
00737 $validMatch = true;
00738 $hasMatchType = true;
00739 }
00740 }
00741 }
00742 }
00743
00744 if ( $validMatch )
00745 {
00746 if ( !$minimalTemplateSet or
00747 $hasMatchType )
00748 {
00749 $blockMatchArray[$blockName] = array_merge( $blockData,
00750 $matchValue );
00751 }
00752 }
00753 }
00754 }
00755 $this->OverrideSettingsArray[$siteAccess] = $blockMatchArray;
00756 }
00757
00758 $overrideSettingsListDOMNode = eZDOMDocument::createElementNode( 'override-list' );
00759 foreach ( $this->OverrideSettingsArray as $siteAccess => $blockMatchArray )
00760 {
00761 foreach( $blockMatchArray as $blockName => $iniGroup )
00762 {
00763 unset( $blockMatchNode );
00764 $blockMatchNode = eZDOMDocument::createElementNode( 'block', array( 'name' => $blockName,
00765 'site-access' => $siteAccess ) );
00766 $blockMatchNode->appendChild( eZDOMDocument::createElementNodeFromArray( $blockName, $iniGroup ) );
00767 $overrideSettingsListDOMNode->appendChild( $blockMatchNode );
00768 }
00769 }
00770
00771 return $overrideSettingsListDOMNode;
00772 }
00773
00774
00775
00776
00777
00778 function &generateClassIDArray()
00779 {
00780 $classIDArray = array();
00781 foreach( array_keys( $this->NodeObjectArray ) as $key )
00782 {
00783 $contentObject =& $this->NodeObjectArray[$key]->object();
00784 $classIDArray[] = $contentObject->attribute( 'contentclass_id' );
00785 }
00786 $classIDArray = array_unique( $classIDArray );
00787 return $classIDArray;
00788 }
00789
00790
00791
00792
00793
00794 function uninstall( &$package, $installType, $parameters,
00795 $name, $os, $filename, $subdirectory,
00796 &$content, &$installParameters,
00797 &$installData )
00798 {
00799 $this->Package =& $package;
00800
00801 if ( isset( $installParameters['error']['error_code'] ) )
00802 $errorCode = $installParameters['error']['error_code'];
00803 else
00804 $errorCode = false;
00805
00806
00807 if ( !$errorCode || ( $errorCode >= EZ_PACKAGE_CONTENTOBJECT__UNINSTALL_OBJECTS_ERROR_RANGE_FROM &&
00808 $errorCode <= EZ_PACKAGE_CONTENTOBJECT__UNINSTALL_OBJECTS_ERROR_RANGE_TO ) )
00809 {
00810 $objectListNode = $content->elementByName( 'object-list' );
00811 if ( !$objectListNode )
00812 {
00813 $objectListNode = $content->elementByName( 'object-files-list' );
00814 }
00815 $objectNodes = array_reverse( $objectListNode->Children );
00816
00817 foreach( $objectNodes as $objectNode )
00818 {
00819 $realObjectNode = $this->getRealObjectNode( $objectNode );
00820
00821 $objectRemoteID = $realObjectNode->getAttribute( 'remote_id' );
00822 $name = $realObjectNode->attributeValue( 'name' );
00823
00824 if ( isset( $installParameters['error']['error_code'] ) &&
00825 !$this->isErrorElement( $objectRemoteID, $installParameters ) )
00826 continue;
00827
00828 if ( isset( $object ) )
00829 {
00830 eZContentObject::clearCache( $object->attribute( 'id' ) );
00831 unset( $object );
00832 }
00833 $object = eZContentObject::fetchByRemoteID( $objectRemoteID );
00834
00835 if ( $object !== null )
00836 {
00837 $modified = $object->attribute( 'modified' );
00838 $published = $object->attribute( 'published' );
00839 if ( $modified > $published )
00840 {
00841 $choosenAction = $this->errorChoosenAction( EZ_PACKAGE_CONTENTOBJECT_ERROR_MODIFIED,
00842 $installParameters );
00843
00844 if ( $choosenAction == EZ_PACKAGE_CONTENTOBJECT_KEEP )
00845 {
00846 continue;
00847 }
00848 if ( $choosenAction != EZ_PACKAGE_CONTENTOBJECT_DELETE )
00849 {
00850 $installParameters['error'] = array( 'error_code' => EZ_PACKAGE_CONTENTOBJECT_ERROR_MODIFIED,
00851 'element_id' => $objectRemoteID,
00852 'description' => ezi18n( 'kernel/package',
00853 "Object '%objectname' has been modified since installation. Are you sure you want to remove it?",
00854 false, array( '%objectname' => $name ) ),
00855 'actions' => array( EZ_PACKAGE_CONTENTOBJECT_DELETE => ezi18n( 'kernel/package', 'Remove' ),
00856 EZ_PACKAGE_CONTENTOBJECT_KEEP => ezi18n( 'kernel/package', 'Keep object' ) ) );
00857 return false;
00858 }
00859 }
00860
00861 $assignedNodes = $object->attribute( 'assigned_nodes' );
00862 $assignedNodeIDArray = array();
00863 foreach( $assignedNodes as $node )
00864 {
00865 $assignedNodeIDArray[] = $node->attribute( 'node_id' );
00866 }
00867 if ( count( $assignedNodeIDArray ) == 0 )
00868 continue;
00869 $info = eZContentObjectTreeNode::subtreeRemovalInformation( $assignedNodeIDArray );
00870 $childrenCount = $info['total_child_count'];
00871
00872 if ( $childrenCount > 0 )
00873 {
00874 $choosenAction = $this->errorChoosenAction( EZ_PACKAGE_CONTENTOBJECT_ERROR_HAS_CHILDREN,
00875 $installParameters );
00876
00877 if ( $choosenAction == EZ_PACKAGE_CONTENTOBJECT_KEEP )
00878 {
00879 continue;
00880 }
00881 if ( $choosenAction != EZ_PACKAGE_CONTENTOBJECT_DELETE )
00882 {
00883 $installParameters['error'] = array( 'error_code' => EZ_PACKAGE_CONTENTOBJECT_ERROR_HAS_CHILDREN,
00884 'element_id' => $objectRemoteID,
00885 'description' => ezi18n( 'kernel/package',
00886 "Object '%objectname' has %childrencount sub-item(s) that will be removed.",
00887 false, array( '%objectname' => $name,
00888 '%childrencount' => $childrenCount ) ),
00889 'actions' => array( EZ_PACKAGE_CONTENTOBJECT_DELETE => ezi18n( 'kernel/package', "Remove object and it's sub-item(s)" ),
00890 EZ_PACKAGE_CONTENTOBJECT_KEEP => ezi18n( 'kernel/package', 'Keep object' ) ) );
00891 return false;
00892 }
00893 }
00894
00895 eZContentObjectTreeNode::removeSubtrees( $assignedNodeIDArray, false );
00896
00897
00898
00899
00900 }
00901 else
00902 {
00903 eZDebug::writeNotice( "Can't uninstall object '$name': object not found", 'eZContentObjectPackageHandler::uninstall' );
00904 }
00905
00906 unset( $realObjectNode );
00907 }
00908 }
00909 return true;
00910 }
00911
00912
00913
00914
00915
00916 function install( &$package, $installType, $parameters,
00917 $name, $os, $filename, $subdirectory,
00918 &$content, &$installParameters,
00919 &$installData )
00920 {
00921 $this->Package =& $package;
00922
00923 if ( isset( $installParameters['error']['error_code'] ) )
00924 $errorCode = $installParameters['error']['error_code'];
00925 else
00926 $errorCode = false;
00927
00928
00929 if ( !$errorCode || ( $errorCode >= EZ_PACKAGE_CONTENTOBJECT__INSTALL_OBJECTS_ERROR_RANGE_FROM &&
00930 $errorCode <= EZ_PACKAGE_CONTENTOBJECT__INSTALL_OBJECTS_ERROR_RANGE_TO ) )
00931 {
00932 $objectListNode = $content->elementByName( 'object-list' );
00933 if ( !$objectListNode )
00934 {
00935 $objectListNode = $content->elementByName( 'object-files-list' );
00936 }
00937 $objectNodes = $objectListNode->Children;
00938
00939 if ( !$this->installContentObjects( $objectNodes,
00940 $content->elementByName( 'top-node-list' ),
00941 $installParameters ) )
00942 return false;
00943 $errorCode = false;
00944 }
00945
00946 if ( !$this->installTemplates( $content->elementByName( 'template-list' ),
00947 $package,
00948 $subdirectory,
00949 $installParameters ) )
00950 return false;
00951
00952
00953 if ( !$this->installOverrides( $content->elementByName( 'override-list' ),
00954 $installParameters ) )
00955 return false;
00956
00957 if ( !$this->installFetchAliases( $content->elementByName( 'fetch-alias-list' ),
00958 $installParameters ) )
00959 return false;
00960
00961 return true;
00962 }
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972 function installContentObjects( $objectNodes, $topNodeListNode, &$installParameters )
00973 {
00974 include_once( 'kernel/classes/ezcontentobject.php' );
00975 if ( isset( $installParameters['user_id'] ) )
00976 $userID = $installParameters['user_id'];
00977 else
00978 $userID = eZUser::currentUserID();
00979
00980 $handlerType = $this->handlerType();
00981 $firstInstalledID = null;
00982
00983 foreach( $objectNodes as $objectNode )
00984 {
00985 $realObjectNode = $this->getRealObjectNode( $objectNode );
00986
00987
00988
00989 if ( isset( $installParameters['error']['error_code'] ) &&
00990 !$this->isErrorElement( $realObjectNode->attributeValue( 'remote_id' ), $installParameters ) )
00991 {
00992 continue;
00993 }
00994
00995
00996 if ( !$firstInstalledID )
00997 {
00998 $firstInstalledID = $realObjectNode->attributeValue( 'remote_id' );
00999 }
01000
01001 $newObject = eZContentObject::unserialize( $this->Package, $realObjectNode, $installParameters, $userID, $handlerType );
01002 if ( !$newObject )
01003 {
01004 return false;
01005 }
01006
01007 if ( is_object( $newObject ) )
01008 {
01009 eZContentObject::clearCache( $newObject->attribute( 'id' ) );
01010 unset( $newObject );
01011 }
01012 unset( $realObjectNode );
01013
01014 if ( isset( $installParameters['error'] ) && count( $installParameters['error'] ) )
01015 {
01016 $installParameters['error'] = array();
01017 }
01018 }
01019
01020 $this->installSuspendedNodeAssignment( $installParameters );
01021 $this->installSuspendedObjectRelations( $installParameters );
01022
01023
01024 foreach( $objectNodes as $objectNode )
01025 {
01026 if ( $objectNode->nodeName == 'object' )
01027 {
01028 $remoteID = $objectNode->getAttribute( 'remote_id' );
01029 }
01030 else
01031 {
01032 $remoteID = substr( $objectNode->getAttribute( 'filename' ), 7, 32 );
01033 }
01034
01035
01036 if ( $firstInstalledID && $remoteID != $firstInstalledID )
01037 {
01038 continue;
01039 }
01040 else
01041 {
01042 $firstInstalledID = null;
01043 }
01044
01045 $object =& eZContentObject::fetchByRemoteID( $remoteID );
01046 if ( is_object( $object ) )
01047 {
01048 $object->postUnserialize( $package );
01049 eZContentObject::clearCache( $object->attribute( 'id' ) );
01050 }
01051 unset( $object );
01052 }
01053
01054 return true;
01055 }
01056
01057
01058
01059
01060
01061
01062 function installSuspendedNodeAssignment( &$installParameters )
01063 {
01064 if ( !isset( $installParameters['suspended-nodes'] ) )
01065 {
01066 return;
01067 }
01068 foreach ( $installParameters['suspended-nodes'] as $parentNodeRemoteID => $suspendedNodeInfo )
01069 {
01070 $parentNode = eZContentObjectTreeNode::fetchByRemoteID( $parentNodeRemoteID );
01071 if ( $parentNode !== null )
01072 {
01073 $nodeInfo =& $suspendedNodeInfo['nodeinfo'];
01074 $nodeInfo['parent_node'] = $parentNode->attribute( 'node_id' );
01075
01076 $existNodeAssignment = eZPersistentObject::fetchObject( eZNodeAssignment::definition(),
01077 null,
01078 $nodeInfo );
01079 $nodeInfo['priority'] = $suspendedNodeInfo['priority'];
01080 if( !is_object( $existNodeAssignment ) )
01081 {
01082 $nodeAssignment =& eZNodeAssignment::create( $nodeInfo );
01083 $nodeAssignment->store();
01084 }
01085
01086 $contentObject = eZContentObject::fetch( $nodeInfo['contentobject_id'] );
01087 if ( is_object( $contentObject ) && $contentObject->attribute( 'current_version' ) == $nodeInfo['contentobject_version'] )
01088 {
01089 include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
01090 eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $nodeInfo['contentobject_id'],
01091 'version' => $nodeInfo['contentobject_version'] ) );
01092 }
01093 if ( isset( $nodeInfo['is_main'] ) && $nodeInfo['is_main'] )
01094 {
01095 $existingMainNode = eZContentObjectTreeNode::fetchByRemoteID( $nodeInfo['parent_remote_id'], false );
01096 if ( $existingMainNode )
01097 {
01098 eZContentObjectTreeNode::updateMainNodeID( $existingMainNode['node_id'],
01099 $nodeInfo['contentobject_id'],
01100 $nodeInfo['contentobject_version'],
01101 $nodeInfo['parent_node'] );
01102 }
01103 }
01104 }
01105 else
01106 {
01107 eZDebug::writeError( 'Can not find parent node by remote-id ID = ' . $parentNodeRemoteID, 'eZContentObjectPackageHandler::installSuspendedNodeAssignment()' );
01108 }
01109 unset( $installParameters['suspended-nodes'][$parentNodeRemoteID] );
01110 }
01111 }
01112
01113
01114
01115
01116
01117
01118
01119
01120 function installSuspendedObjectRelations( &$installParameters )
01121 {
01122 if ( !isset( $installParameters['suspended-relations'] ) )
01123 {
01124 return;
01125 }
01126 foreach( $installParameters['suspended-relations'] as $suspendedObjectRelation )
01127 {
01128 $contentObjectID = $suspendedObjectRelation['contentobject-id'];
01129 $contentObjectVersionID = $suspendedObjectRelation['contentobject-version'];
01130
01131 $contentObjectVersion = eZContentObjectVersion::fetchVersion( $contentObjectVersionID, $contentObjectID );
01132 if ( is_object( $contentObjectVersion ) )
01133 {
01134 $relatedObjectRemoteID = $suspendedObjectRelation['related-object-remote-id'];
01135 $relatedObject = eZContentObject::fetchByRemoteID( $relatedObjectRemoteID );
01136 $relatedObjectID = ( $relatedObject !== null ) ? $relatedObject->attribute( 'id' ) : null;
01137
01138 if ( $relatedObjectID )
01139 {
01140 $relatedObject->addContentObjectRelation( $relatedObjectID, $contentObjectVersionID, $contentObjectID );
01141 }
01142 else
01143 {
01144 eZDebug::writeError( 'Can not find related object by remote-id ID = ' . $relatedObjectRemoteID, 'eZContentObjectPackageHandler::installSuspendedObjectRelations()' );
01145 }
01146 }
01147 }
01148 unset( $installParameters['suspended-relations'] );
01149 }
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161 function installTemplates( $templateList, &$package, $subdirectory, &$installParameters )
01162 {
01163 if ( !$templateList )
01164 {
01165 return true;
01166 }
01167 include_once( 'kernel/common/eztemplatedesignresource.php' );
01168
01169 $siteAccessDesignPathArray = array();
01170 $templateRootPath = $package->path() . '/' . $subdirectory;
01171 foreach( $templateList->elementsByName( 'file' ) as $fileNode )
01172 {
01173 $originalSiteAccess = $fileNode->attributeValue( 'site-access' );
01174 if ( isset( $installParameters['site_access_map'][$originalSiteAccess] ) )
01175 {
01176 $newSiteAccess = $installParameters['site_access_map'][$originalSiteAccess];
01177 }
01178 else
01179 {
01180 $newSiteAccess = $installParameters['site_access_map']['*'];
01181 }
01182
01183 if ( !isset( $siteAccessDesignPathArray[$newSiteAccess] ) )
01184 {
01185 $ini =& eZINI::instance( 'site.ini', 'settings', null, null, true );
01186 $ini->prependOverrideDir( "siteaccess/$newSiteAccess", false, 'siteaccess' );
01187 $ini->loadCache();
01188
01189 if ( isset( $installParameters['design_map'] ) )
01190 {
01191 $designMap = $installParameters['design_map'];
01192 if ( isset( $designMap[$originalSiteAccess] ) )
01193 $siteAccessDesignPathArray[$newSiteAccess] = eZTemplateDesignResource::designStartPath() . '/' . $designMap[$originalSiteAccess];
01194 else
01195 $siteAccessDesignPathArray[$newSiteAccess] = eZTemplateDesignResource::designStartPath() . '/' . $designMap['*'];
01196 }
01197 else
01198 {
01199 $siteAccessDesignPathArray[$newSiteAccess] = eZTemplateDesignResource::designStartPath() . '/' . $ini->variable( "DesignSettings", "StandardDesign" );
01200 }
01201 }
01202
01203 $sourcePath = $templateRootPath . $fileNode->elementTextContentByName('path');
01204 $destinationPath = $siteAccessDesignPathArray[$newSiteAccess] . $fileNode->elementTextContentByName('path');
01205
01206 eZDir::mkdir( eZDir::dirpath( $destinationPath ), false, true );
01207 if ( !eZFileHandler::copy( $sourcePath, $destinationPath ) )
01208 return false;
01209
01210
01211
01212 }
01213 return true;
01214 }
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224 function installOverrides( $overrideListNode, &$parameters )
01225 {
01226 if ( !$overrideListNode )
01227 {
01228 return true;
01229 }
01230
01231 $overrideINIArray = array();
01232 foreach( $overrideListNode->elementsByName( 'block' ) as $blockNode )
01233 {
01234 if ( isset( $parameters['site_access_map'][$blockNode->attributeValue( 'site-access' )] ) )
01235 {
01236 $newSiteAccess = $parameters['site_access_map'][$blockNode->attributeValue( 'site-access' )];
01237 }
01238 else
01239 {
01240 $newSiteAccess = $parameters['site_access_map']['*'];
01241 }
01242
01243 if ( !$newSiteAccess )
01244 {
01245 eZDebug::writeError( 'SiteAccess map for : ' . $blockNode->attributeValue( 'site-access' ) . ' not set.',
01246 'eZContentObjectPackageHandler::installOverrides()' );
01247 continue;
01248 }
01249
01250 if ( !isset( $overrideINIArray[$newSiteAccess] ) )
01251 {
01252 $overrideINIArray[$newSiteAccess] =& eZINI::instance( 'override.ini.append.php', "settings/siteaccess/$newSiteAccess", null, null, true );
01253 }
01254
01255 $blockArray = array();
01256 $blockName = $blockNode->attributeValue( 'name' );
01257 $blockArray[$blockName] = eZDOMDocument::createArrayFromDOMNode( $blockNode->elementByName( $blockName ) );
01258
01259 if ( isset( $blockArray[$blockName][$this->OverrideObjectRemoteID] ) )
01260 {
01261 $contentObject =& eZContentObject::fetchByRemoteID( $blockArray[$blockName][$this->OverrideObjectRemoteID] );
01262 $blockArray[$blockName]['Match']['object'] = $contentObject->attribute( 'id' );
01263 unset( $blockArray[$blockName][$this->OverrideObjectRemoteID] );
01264
01265
01266 }
01267 if ( isset( $blockArray[$blockName][$this->OverrideNodeRemoteID] ) )
01268 {
01269 $contentNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName][$this->OverrideNodeRemoteID] );
01270 $blockArray[$blockName]['Match']['node'] = $contentNode->attribute( 'node_id' );
01271 unset( $blockArray[$blockName][$this->OverrideNodeRemoteID] );
01272
01273
01274 }
01275 if ( isset( $blockArray[$blockName][$this->OverrideParentNodeRemoteID] ) )
01276 {
01277 $parentContentNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName][$this->OverrideParentNodeRemoteID] );
01278 $blockArray[$blockName]['Match']['parent_node'] = $parentContentNode->attribute( 'node_id' );
01279 unset( $blockArray[$blockName][$this->OverrideParentNodeRemoteID] );
01280
01281
01282 }
01283 if ( isset( $blockArray[$blockName][$this->OverrideClassRemoteID] ) )
01284 {
01285 $contentClass = eZContentClass::fetchByRemoteID( $blockArray[$blockName][$this->OverrideClassRemoteID] );
01286 if ( !$contentClass )
01287 {
01288 eZDebug::writeError( 'No content class found for RemoteID: ' . $blockArray[$blockName][$this->OverrideClassRemoteID],
01289 'eZContentObjectPackageHandler::installOverrides()' );
01290 continue;
01291 }
01292 $blockArray[$blockName]['Match']['class'] = $contentClass->attribute( 'id' );
01293 unset( $blockArray[$blockName][$this->OverrideClassRemoteID] );
01294
01295
01296 }
01297
01298 $overrideINIArray[$newSiteAccess]->setVariables( $blockArray );
01299 }
01300
01301 foreach( $overrideINIArray as $siteAccess => $iniArray )
01302 {
01303 $overrideINIArray[$siteAccess]->save();
01304 }
01305
01306 return true;
01307 }
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317 function installFetchAliases( $fetchAliasListNode, &$parameters )
01318 {
01319 if ( !$fetchAliasListNode )
01320 {
01321 return true;
01322 }
01323
01324 $fetchAliasINIArray = array();
01325 foreach( $fetchAliasListNode->elementsByName( 'fetch-alias' ) as $blockNode )
01326 {
01327 if ( isset( $parameters['site_access_map'][$blockNode->attributeValue( 'site-access' )] ) )
01328 {
01329 $newSiteAccess = $parameters['site_access_map'][$blockNode->attributeValue( 'site-access' )];
01330 }
01331 else
01332 {
01333 $newSiteAccess = $parameters['site_access_map']['*'];
01334 }
01335
01336 if ( !isset( $fetchAliasINIArray[$newSiteAccess] ) )
01337 {
01338 $fetchAliasINIArray[$newSiteAccess] =& eZINI::instance( 'fetchalias.ini.append.php', "settings/siteaccess/$newSiteAccess", null, null, true );
01339 }
01340
01341 $blockArray = array();
01342 $blockName = $blockNode->attributeValue( 'name' );
01343 $blockArray[$blockName] = eZDOMDocument::createArrayFromDOMNode( $blockNode->elementByName( $blockName ) );
01344
01345
01346
01347 if ( isset( $blockArray[$blockName]['Constant'] ) && is_array( $blockArray[$blockName]['Constant'] ) && count( $blockArray[$blockName]['Constant'] ) > 0 )
01348 {
01349 foreach( $blockArray[$blockName]['Constant'] as $matchKey => $value )
01350 {
01351 if ( strpos( $matchKey, 'class_' ) === 0 &&
01352 is_int( $value ) )
01353 {
01354 $contentClass = eZContentClass::fetchByRemoteID( $blockArray[$blockName]['Constant']['class_remote_id'] );
01355 $blockArray[$blockName]['Constant'][$matchKey] = $contentClass->attribute( 'id' );
01356 unset( $blockArray[$blockName]['Constant']['class_remote_id'] );
01357 }
01358 if( strpos( $matchKey, 'node_' ) === 0 &&
01359 is_int( $value ) )
01360 {
01361 $contentTreeNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName]['Constant']['node_remote_id'] );
01362 $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'node_id' );
01363 unset( $blockArray[$blockName]['Constant']['node_remote_id'] );
01364 }
01365 if( strpos( $matchKey, 'parent_node_' ) === 0 &&
01366 is_int( $value ) )
01367 {
01368 $contentTreeNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName]['Constant']['parent_node_remote_id'] );
01369 $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'node_id' );
01370 unset( $blockArray[$blockName]['Constant']['parent_node_remote_id'] );
01371 }
01372 if( strpos( $matchKey, 'object_' ) === 0 &&
01373 is_int( $value ) )
01374 {
01375 $contentObject =& eZContentObject::fetchByRemoteID( $blockArray[$blockName]['Constant']['object_remote_id'] );
01376 $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'id' );
01377 unset( $blockArray[$blockName]['Constant']['object_remote_id'] );
01378 }
01379 }
01380 }
01381
01382 $fetchAliasINIArray[$newSiteAccess]->setVariables( $blockArray );
01383 }
01384
01385 foreach( $fetchAliasINIArray as $siteAccess => $iniFetchAlias )
01386 {
01387 $fetchAliasINIArray[$siteAccess]->save();
01388 }
01389
01390 return true;
01391 }
01392
01393
01394
01395
01396 function add( $packageType, &$package, &$cli, $parameters )
01397 {
01398 $options = array();
01399 foreach ( $parameters['node-list'] as $nodeItem )
01400 {
01401 $nodeIDList = $nodeItem['node-id-list'];
01402 foreach ( $nodeIDList as $nodeIDItem )
01403 {
01404 $this->addNode( $nodeIDItem['id'], $nodeIDItem['subtree'] );
01405 unset( $node );
01406 $node = false;
01407 if ( isset( $nodeIDItem['node'] ) )
01408 $node =& $nodeIDItem['node'];
01409 else
01410 $node = eZContentObjectTreeNode::fetch( $nodeIDItem['id'] );
01411 $cli->notice( "Adding node /" . $node->attribute( 'path_identification_string' ) . " to package" );
01412 }
01413 }
01414 $options['include_classes'] = $parameters['include-classes'];
01415 $options['include_templates'] = $parameters['include-templates'];
01416 $options['node_assignment'] = $parameters['node-assignment-type'];
01417 $options['site_access_array'] = $parameters['siteaccess-list'];
01418 $options['language_array'] = $parameters['language-list'];
01419 $options['versions'] = $parameters['version-type'];
01420 $options['related_objects'] = $parameters['related-type'];
01421 $options['embed_objects'] = $parameters['embed-type'];
01422 $options['minimal_template_set'] = $parameters['minimal-template-set'];
01423 $this->generatePackage( $package, $options );
01424 }
01425
01426
01427
01428
01429 function handleAddParameters( $packageType, &$package, &$cli, $arguments )
01430 {
01431 return $this->handleParameters( $packageType, $package, $cli, 'add', $arguments );
01432 }
01433
01434
01435
01436
01437 function handleParameters( $packageType, &$package, &$cli, $type, $arguments )
01438 {
01439 $nodeList = array();
01440 $includeClasses = true;
01441 $includeTemplates = true;
01442 $siteAccessList = array();
01443 $nodeAssignmentType = 'main';
01444 $relatedObjectType = 'selected';
01445 $embedObjectType = 'selected';
01446 $versionType = 'current';
01447 $languageList = array();
01448 $minimalTemplateSet = false;
01449 $nodeItem = array( 'node-id-list' => array() );
01450 $longOptions = array( 'include-classes' => 'include-classes',
01451 'include-templates' => 'include-templates',
01452 'exclude-classes' => 'exclude-classes',
01453 'exclude-templates' => 'exclude-templates',
01454 'language' => 'language',
01455 'current-version' => 'current-version',
01456 'all-versions' => 'all-versions',
01457 'node-main' => 'node-main',
01458 'node-selected' => 'node-selected',
01459 'siteaccess' => 'siteaccess',
01460 'minimal-template-set' => 'minimal-template-set' );
01461 $shortOptions = array();
01462 $error = false;
01463 foreach ( $arguments as $argument )
01464 {
01465 if ( $argument[0] == '-' )
01466 {
01467 if ( strlen( $argument ) > 1 and
01468 $argument[1] == '-' )
01469 {
01470 $option = substr( $argument, 2 );
01471 $valuePos = strpos( $option, '=' );
01472 $optionValue = false;
01473 if ( $valuePos !== false )
01474 {
01475 $optionValue = substr( $option, $valuePos + 1 );
01476 $option = substr( $option, 0, $valuePos );
01477 }
01478 if ( isset( $longOptions[$option] ) )
01479 $optionName = $longOptions[$option];
01480 else
01481 $optionName = false;
01482 }
01483 else
01484 {
01485 $option = substr( $argument, 1 );
01486 if ( isset( $shortOptions[$option] ) )
01487 $optionName = $shortOptions[$option];
01488 else
01489 $optionName = false;
01490 }
01491 if ( $optionName == 'include-classes' or $optionName == 'exclude-classes' )
01492 {
01493 if ( count( $nodeItem['node-id-list'] ) > 0 )
01494 {
01495 $nodeList[] = $nodeItem;
01496 $nodeItem['node-id-list'] = array();
01497 }
01498 $includeClasses = ( $optionName == 'include-classes' );
01499 }
01500 else if ( $optionName == 'include-templates' or $optionName == 'exclude-templates' )
01501 {
01502 if ( count( $nodeItem['node-id-list'] ) > 0 )
01503 {
01504 $nodeList[] = $nodeItem;
01505 $nodeItem['node-id-list'] = array();
01506 }
01507 $includeTemplates = ( $optionName == 'include-templates' );
01508 }
01509 else if ( $optionName == 'node-main' )
01510 {
01511 $nodeAssignmentType = 'main';
01512 }
01513 else if ( $optionName == 'node-selected' )
01514 {
01515 $nodeAssignmentType = 'selected';
01516 }
01517 else if ( $optionName == 'siteaccess' )
01518 {
01519 $siteAccessList = explode( ',', $optionValue );
01520 }
01521 else if ( $optionName == 'language' )
01522 {
01523 $languageList = explode( ',', $optionValue );
01524 }
01525 else if ( $optionName == 'current-version' )
01526 {
01527 $versionType = 'current';
01528 }
01529 else if ( $optionName == 'all-versions' )
01530 {
01531 $versionType = 'all';
01532 }
01533 else if ( $optionName == 'minimal-template-set' )
01534 {
01535 $minimalTemplateSet = true;
01536 }
01537 }
01538 else
01539 {
01540 $nodeID = false;
01541 $subtree = false;
01542 if ( is_numeric( $argument ) )
01543 {
01544 $nodeID = (int)$argument;
01545 $node = eZContentObjectTreeNode::fetch( $nodeID );
01546 if ( !is_object( $node ) )
01547 {
01548 $error = true;
01549 $nodeID = false;
01550 $cli->notice( "Could not find content-node using ID " . $cli->stylize( 'emphasize', $nodeID ) );
01551 }
01552 }
01553 else
01554 {
01555 $path = $argument;
01556 if ( preg_match( "#(.+)/\*$#", $path, $matches ) )
01557 {
01558 $path = $matches[1];
01559 $subtree = true;
01560 }
01561 $node = eZContentObjectTreeNode::fetchByURLPath( $path );
01562 if ( is_object( $node ) )
01563 {
01564 $nodeID = $node->attribute( 'node_id' );
01565 }
01566 else
01567 {
01568 $cli->notice( "Could not find content-node using path " . $cli->stylize( 'emphasize', $path ) );
01569 $error = true;
01570 }
01571 }
01572 if ( $nodeID )
01573 {
01574 $nodeItem['node-id-list'][] = array( 'id' => $nodeID,
01575 'subtree' => $subtree,
01576 'node' => &$node );
01577 }
01578 if ( $error )
01579 return false;
01580 }
01581 }
01582 if ( count( $nodeItem['node-id-list'] ) > 0 )
01583 {
01584 $nodeList[] = $nodeItem;
01585 }
01586 if ( count( $nodeList ) == 0 )
01587 {
01588 $cli->error( "No objects chosen" );
01589 return false;
01590 }
01591 if ( count( $languageList ) == 0 )
01592 {
01593
01594 include_once( 'kernel/classes/ezcontentlanguage.php' );
01595 $languageList = eZContentLanguage::fetchLocaleList();
01596 }
01597 if ( count( $siteAccessList ) == 0 )
01598 {
01599 $ini =& eZINI::instance();
01600 $siteAccessList[] = $ini->variable( 'SiteSettings', 'DefaultAccess' );
01601 }
01602 return array( 'node-list' => $nodeList,
01603 'include-classes' => $includeClasses,
01604 'include-templates' => $includeTemplates,
01605 'siteaccess-list' => $siteAccessList,
01606 'language-list' => $languageList,
01607 'node-assignment-type' => $nodeAssignmentType,
01608 'related-type' => $relatedObjectType,
01609 'embed-type' => $embedObjectType,
01610 'version-type' => $versionType,
01611 'minimal-template-set' => $minimalTemplateSet,
01612 );
01613 }
01614
01615 function contentObjectDirectory()
01616 {
01617 return 'ezcontentobject';
01618 }
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660 var $NodeIDArray = array();
01661 var $RootNodeIDArray = array();
01662 var $NodeObjectArray = array();
01663 var $ObjectArray = array();
01664 var $RootNodeObjectArray = array();
01665 var $OverrideSettingsArray = array();
01666 var $TemplateFileArray = array();
01667 var $Package = null;
01668
01669
01670 var $OverrideObjectRemoteID = 'content_object_remote_id';
01671 var $OverrideNodeRemoteID = 'content_node_remote_id';
01672 var $OverrideParentNodeRemoteID = 'parent_content_node_remote_id';
01673 var $OverrideClassRemoteID = 'content_class_remote_id';
01674 }
01675
01676 ?>