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
00041
00042
00043
00044
00045
00046
00047
00048 define( 'EZ_VCSC_CLEAR_NODE_CACHE' , 1 );
00049 define( 'EZ_VCSC_CLEAR_PARENT_CACHE' , 2 );
00050 define( 'EZ_VCSC_CLEAR_RELATING_CACHE' , 4 );
00051 define( 'EZ_VCSC_CLEAR_KEYWORD_CACHE' , 8 );
00052 define( 'EZ_VCSC_CLEAR_SIBLINGS_CACHE' , 16 );
00053 define( 'EZ_VCSC_CLEAR_ALL_CACHE' , 31 );
00054 define( 'EZ_VCSC_CLEAR_DEFAULT' , 15 );
00055
00056
00057 include_once( 'kernel/classes/ezcontentobject.php' );
00058 include_once( 'lib/ezutils/classes/ezini.php' );
00059
00060 class eZContentCacheManager
00061 {
00062
00063
00064
00065 function eZContentCacheManager()
00066 {
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 function appendParentNodeIDs( &$object, $versionNum, &$nodeIDList )
00076 {
00077 $parentNodes =& $object->parentNodes( $versionNum );
00078 foreach ( array_keys( $parentNodes ) as $parentNodeKey )
00079 {
00080 $parentNode =& $parentNodes[$parentNodeKey];
00081 if ( is_object ( $parentNode ) )
00082 {
00083 $nodeIDList[] = $parentNode->attribute( 'node_id' );
00084 }
00085 }
00086 }
00087
00088
00089
00090
00091
00092
00093 function appendNodeIDs( &$nodeList, &$nodeIDList )
00094 {
00095 foreach ( array_keys( $nodeList ) as $nodeKey )
00096 {
00097 $assignedNode =& $nodeList[$nodeKey];
00098 $nodeIDList[] = $assignedNode->attribute( 'node_id' );
00099 }
00100 }
00101
00102
00103
00104
00105
00106
00107 function &fetchNodePathString( &$nodeList )
00108 {
00109 $pathList = array();
00110 foreach ( array_keys( $nodeList ) as $nodeKey )
00111 {
00112 $node =& $nodeList[$nodeKey];
00113 $pathList[] = $node->attribute( 'path_string' );
00114 }
00115 return $pathList;
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 function appendRelatingNodeIDs( &$object, &$nodeIDList )
00125 {
00126 $viewCacheIni = eZINI::instance( 'viewcache.ini' );
00127 if ( $viewCacheIni->hasVariable( 'ViewCacheSettings', 'ClearRelationTypes' ) )
00128 {
00129 $relTypes = $viewCacheIni->variable( 'ViewCacheSettings', 'ClearRelationTypes' );
00130
00131 if ( !count( $relTypes ) )
00132 return;
00133
00134 $relatedObjects = array();
00135
00136 $relationsMask = 0;
00137 if ( in_array( 'object', $relTypes ) )
00138 $relationsMask |= EZ_CONTENT_OBJECT_RELATION_COMMON | EZ_CONTENT_OBJECT_RELATION_EMBED;
00139
00140 if ( in_array( 'common', $relTypes ) )
00141 $relationsMask |= EZ_CONTENT_OBJECT_RELATION_COMMON;
00142
00143 if ( in_array( 'embedded', $relTypes ) )
00144 $relationsMask |= EZ_CONTENT_OBJECT_RELATION_EMBED;
00145
00146 if ( in_array( 'linked', $relTypes ) )
00147 $relationsMask |= EZ_CONTENT_OBJECT_RELATION_LINK;
00148
00149 if ( in_array( 'attribute', $relTypes ) )
00150 $relationsMask |= EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE;
00151
00152 if ( $relationsMask )
00153 {
00154 $objects = $object->relatedContentObjectList( false, false, false, false,
00155 array( 'AllRelations' => $relationsMask ) );
00156 $previousVersionObjects = array();
00157 $previousVersion = $object->previousVersion();
00158 if ( $previousVersion )
00159 {
00160 $previousVersionObjects = $object->relatedContentObjectList( $previousVersion, false, false, false,
00161 array( 'AllRelations' => $relationsMask ) );
00162 }
00163 $relatedObjects = array_merge( $relatedObjects, $objects, $previousVersionObjects );
00164 }
00165
00166 $relationsMask = 0;
00167 if ( in_array( 'reverse_object', $relTypes ) )
00168 $relationsMask |= EZ_CONTENT_OBJECT_RELATION_COMMON | EZ_CONTENT_OBJECT_RELATION_EMBED;
00169
00170 if ( in_array( 'reverse_common', $relTypes ) )
00171 $relationsMask |= EZ_CONTENT_OBJECT_RELATION_COMMON;
00172
00173 if ( in_array( 'reverse_embedded', $relTypes ) )
00174 $relationsMask |= EZ_CONTENT_OBJECT_RELATION_EMBED;
00175
00176 if ( in_array( 'reverse_linked', $relTypes ) )
00177 $relationsMask |= EZ_CONTENT_OBJECT_RELATION_LINK;
00178
00179 if ( in_array( 'reverse_attribute', $relTypes ) )
00180 $relationsMask |= EZ_CONTENT_OBJECT_RELATION_ATTRIBUTE;
00181
00182 if ( $relationsMask )
00183 {
00184 $objects = $object->reverseRelatedObjectList( false, false, false, false,
00185 array( 'AllRelations' => $relationsMask ) );
00186 $previousVersionObjects = array();
00187 $previousVersion = $object->previousVersion();
00188 if ( $previousVersion )
00189 {
00190 $previousVersionObjects = $object->relatedContentObjectList( $previousVersion, false, false, false,
00191 array( 'AllRelations' => $relationsMask ) );
00192 }
00193 $relatedObjects = array_merge( $relatedObjects, $objects, $previousVersionObjects );
00194 }
00195 }
00196 else
00197 {
00198 $normalRelated =& $object->relatedContentObjectArray();
00199 $reversedRelated =& $object->contentObjectListRelatingThis();
00200
00201 $relatedObjects = array_merge( $normalRelated, $reversedRelated );
00202 }
00203
00204 foreach ( array_keys( $relatedObjects ) as $relatedObjectKey )
00205 {
00206 $relatedObject =& $relatedObjects[$relatedObjectKey];
00207 $assignedNodes =& $relatedObject->assignedNodes( false );
00208 foreach ( array_keys( $assignedNodes ) as $assignedNodeKey )
00209 {
00210 $assignedNode =& $assignedNodes[$assignedNodeKey];
00211 $nodeIDList[] = $assignedNode['node_id'];
00212 }
00213 }
00214 $nodeIDList = array_unique( $nodeIDList );
00215 }
00216
00217
00218
00219
00220
00221
00222
00223 function appendKeywordNodeIDs( &$object, $versionNum, &$nodeIDList )
00224 {
00225 if ( $versionNum === true )
00226 $versionNum = false;
00227 $keywordArray = array();
00228 $attributes =& $object->contentObjectAttributes( true, $versionNum );
00229 foreach ( array_keys( $attributes ) as $key )
00230 {
00231 if ( get_class( $attributes[$key] ) == 'ezcontentobjectattribute' and
00232 $attributes[$key]->attribute( 'data_type_string' ) == 'ezkeyword' )
00233 {
00234 $keywordObject =& $attributes[$key]->content();
00235 if ( get_class( $keywordObject ) == 'ezkeyword' )
00236 {
00237 foreach ( $keywordObject->attribute( 'keywords' ) as $keyword )
00238 {
00239 $keywordArray[] = $keyword;
00240 }
00241 }
00242 }
00243 }
00244
00245
00246 if ( count( $keywordArray ) > 0 )
00247 {
00248 $keywordString = implode( "', '", $keywordArray );
00249 include_once( 'lib/ezdb/classes/ezdb.php' );
00250 $db = eZDB::instance();
00251 $keywordString = "'".$db->escapeString( $keyword )."'";
00252 $rows = $db->arrayQuery( "SELECT DISTINCT ezcontentobject_tree.node_id
00253 FROM
00254 ezcontentobject_tree,
00255 ezcontentobject_attribute,
00256 ezkeyword_attribute_link,
00257 ezkeyword
00258 WHERE
00259 ezcontentobject_tree.contentobject_id = ezcontentobject_attribute.contentobject_id AND
00260 ezcontentobject_attribute.id = ezkeyword_attribute_link.objectattribute_id AND
00261 ezkeyword_attribute_link.keyword_id = ezkeyword.id AND
00262 ezkeyword.keyword IN ( $keywordString )" );
00263
00264 foreach ( $rows as $row )
00265 {
00266 $nodeIDList[] = $row['node_id'];
00267 }
00268 }
00269 }
00270
00271
00272
00273
00274
00275
00276 function appendSiblingsNodeIDs( &$nodeList, &$nodeIDList )
00277 {
00278 $params = array( 'Depth' => 1,
00279 'AsObject' => false );
00280 foreach ( array_keys( $nodeList ) as $nodeKey )
00281 {
00282 $node =& $nodeList[$nodeKey];
00283 $siblingNodeList =& eZContentObjectTreeNode::subTree( $params, $node->attribute( 'parent_node_id' ) );
00284 if ( count( $siblingNodeList ) > 0 )
00285 {
00286 foreach ( array_keys( $siblingNodeList ) as $siblingKey )
00287 {
00288 $nodeIDList[] = $siblingNodeList[$siblingKey]['node_id'];
00289 }
00290 }
00291 }
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 function dependencyInfo( $classID, $ignoreINISettings = false )
00307 {
00308 $ini =& eZINI::instance( 'viewcache.ini' );
00309 $info = false;
00310
00311 if ( $ignoreINISettings || $ini->variable( 'ViewCacheSettings', 'SmartCacheClear' ) == 'enabled' )
00312 {
00313 if ( $ini->hasGroup( $classID ) )
00314 {
00315 $info = array();
00316 if ( $ini->hasVariable( $classID, 'DependentClassIdentifier' ) )
00317 $info['dependent_class_identifier'] = $ini->variable( $classID, 'DependentClassIdentifier' );
00318
00319 if ( $ini->hasVariable( $classID, 'MaxParents' ) )
00320 $info['max_parents'] = $ini->variable( $classID, 'MaxParents' );
00321 else
00322 $info['max_parents'] = 0;
00323
00324 if ( $ini->hasVariable( $classID, 'AdditionalObjectIDs' ) )
00325 $info['additional_objects'] = $ini->variable( $classID, 'AdditionalObjectIDs' );
00326
00327 $info['clear_cache_type'] = 0;
00328 if ( $ini->hasVariable( $classID, 'ClearCacheMethod' ) )
00329 {
00330 $type = $ini->variable( $classID, 'ClearCacheMethod' );
00331
00332 if ( is_array( $type ) )
00333 {
00334 if ( in_array( 'all', $type ) )
00335 {
00336 $info['clear_cache_type'] = EZ_VCSC_CLEAR_ALL_CACHE;
00337 }
00338 else
00339 {
00340 if ( in_array( 'object', $type ) )
00341 $info['clear_cache_type'] |= EZ_VCSC_CLEAR_NODE_CACHE;
00342
00343 if ( in_array( 'parent', $type ) )
00344 $info['clear_cache_type'] |= EZ_VCSC_CLEAR_PARENT_CACHE;
00345
00346 if ( in_array( 'relating', $type ) )
00347 $info['clear_cache_type'] |= EZ_VCSC_CLEAR_RELATING_CACHE;
00348
00349 if ( in_array( 'keyword', $type ) )
00350 $info['clear_cache_type'] |= EZ_VCSC_CLEAR_KEYWORD_CACHE;
00351
00352 if ( in_array( 'siblings', $type ) )
00353 $info['clear_cache_type'] |= EZ_VCSC_CLEAR_SIBLINGS_CACHE;
00354 }
00355 }
00356 else
00357 {
00358
00359 if ( $type == 'clear_all_caches' )
00360 {
00361 $info['clear_cache_type'] = EZ_VCSC_CLEAR_ALL_CACHE;
00362 }
00363 else
00364 {
00365 if ( $type == 'clear_object_caches_only' ||
00366 $type == 'clear_object_and_parent_nodes_caches' ||
00367 $type == 'clear_object_and_relating_objects_caches' )
00368 {
00369 $info['clear_cache_type'] |= EZ_VCSC_CLEAR_NODE_CACHE;
00370 }
00371
00372 if ( $type == 'clear_object_and_parent_nodes_caches' ||
00373 $type == 'clear_parent_nodes_caches_only' ||
00374 $type == 'clear_parent_nodes_and_relating_caches' )
00375 {
00376 $info['clear_cache_type'] |= EZ_VCSC_CLEAR_PARENT_CACHE;
00377 }
00378
00379 if ( $type == 'clear_object_and_relating_objects_caches' ||
00380 $type == 'clear_parent_nodes_and_relating_caches' ||
00381 $type == 'clear_relating_caches_only' )
00382 {
00383 $info['clear_cache_type'] |= EZ_VCSC_CLEAR_RELATING_CACHE;
00384 }
00385
00386 if ( $type == 'clear_keyword_caches_only' )
00387 {
00388 $info['clear_cache_type'] |= EZ_VCSC_CLEAR_KEYWORD_CACHE;
00389 }
00390 }
00391 }
00392 }
00393 else
00394 {
00395 $info['clear_cache_type'] = EZ_VCSC_CLEAR_DEFAULT;
00396 }
00397
00398 $info['object_filter'] = array();
00399 if ( $ini->hasVariable( $classID, 'ObjectFilter' ) )
00400 {
00401 $info['object_filter'] = $ini->variable( $classID, 'ObjectFilter' );
00402 }
00403 }
00404 }
00405
00406 return $info;
00407 }
00408
00409
00410
00411
00412
00413
00414 function writeDebugBits( $handledObjectList, $highestBit )
00415 {
00416 $bitPadLength = (int)( pow( $highestBit, 0.5 ) + 1 );
00417
00418
00419 $objectIDList = array_keys( $handledObjectList );
00420 $maxObjectID = max( $objectIDList );
00421 $padLength = strlen( $maxObjectID ) + 2;
00422
00423 $msg = '';
00424 foreach ( $handledObjectList as $objectID => $clearCacheType )
00425 {
00426 $bitString = decbin( $clearCacheType );
00427 $msg .= str_pad( $objectID, $padLength, ' ', STR_PAD_RIGHT ) . str_pad( $bitString, $bitPadLength, '0', STR_PAD_LEFT );
00428 $msg .= "\r\n";
00429 }
00430
00431 eZDebug::writeDebug( $msg, 'eZContentCacheManager::writeDebugBits()' );
00432 }
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455 function nodeListForObject( &$contentObject, $versionNum, $clearCacheType, &$nodeList, &$handledObjectList )
00456 {
00457 $contentObjectID = $contentObject->attribute( 'id' );
00458
00459 if ( isset( $handledObjectList[$contentObjectID] ) )
00460 {
00461 $handledObjectList[$contentObjectID] |= $clearCacheType;
00462 }
00463 else
00464 {
00465 $handledObjectList[$contentObjectID] = $clearCacheType;
00466 }
00467
00468
00469 $assignedNodes =& $contentObject->assignedNodes();
00470
00471 if ( $clearCacheType & EZ_VCSC_CLEAR_NODE_CACHE )
00472 {
00473 eZContentCacheManager::appendNodeIDs( $assignedNodes, $nodeList );
00474 }
00475
00476 if ( $clearCacheType & EZ_VCSC_CLEAR_PARENT_CACHE )
00477 {
00478 eZContentCacheManager::appendParentNodeIDs( $contentObject, $versionNum, $nodeList );
00479 }
00480
00481 if ( $clearCacheType & EZ_VCSC_CLEAR_RELATING_CACHE )
00482 {
00483 eZContentCacheManager::appendRelatingNodeIDs( $contentObject, $nodeList );
00484 }
00485
00486 if ( $clearCacheType & EZ_VCSC_CLEAR_KEYWORD_CACHE )
00487 {
00488 eZContentCacheManager::appendKeywordNodeIDs( $contentObject, $versionNum, $nodeList );
00489 }
00490
00491 if ( $clearCacheType & EZ_VCSC_CLEAR_SIBLINGS_CACHE )
00492 {
00493 eZContentCacheManager::appendSiblingsNodeIDs( $assignedNodes, $nodeList );
00494 }
00495
00496
00497 $objectClassIdentifier = $contentObject->attribute( 'class_identifier' );
00498 $dependentClassInfo = eZContentCacheManager::dependencyInfo( $objectClassIdentifier );
00499
00500 if ( $dependentClassInfo['clear_cache_type'] & EZ_VCSC_CLEAR_SIBLINGS_CACHE )
00501 {
00502 if ( !( $clearCacheType & EZ_VCSC_CLEAR_SIBLINGS_CACHE ) )
00503 {
00504 eZContentCacheManager::appendSiblingsNodeIDs( $assignedNodes, $nodeList );
00505 $handledObjectList[$contentObjectID] |= EZ_VCSC_CLEAR_SIBLINGS_CACHE;
00506 }
00507
00508
00509
00510 $dependentClassInfo['clear_cache_type'] &= ~EZ_VCSC_CLEAR_SIBLINGS_CACHE;
00511 }
00512
00513 if ( isset( $dependentClassInfo['additional_objects'] ) )
00514 {
00515 foreach( $dependentClassInfo['additional_objects'] as $objectID )
00516 {
00517
00518 if ( isset( $handledObjectList[$objectID] ) && $handledObjectList[$objectID] & EZ_VCSC_CLEAR_NODE_CACHE )
00519 {
00520 continue;
00521 }
00522
00523 $object =& eZContentObject::fetch( $objectID );
00524 if ( $object )
00525 {
00526
00527 eZContentCacheManager::nodeListForObject( $object, true, EZ_VCSC_CLEAR_NODE_CACHE, $nodeList, $handledObjectList );
00528 }
00529 }
00530 }
00531
00532 if ( isset( $dependentClassInfo['dependent_class_identifier'] ) )
00533 {
00534 $maxParents = $dependentClassInfo['max_parents'];
00535 $dependentClassIdentifiers = $dependentClassInfo['dependent_class_identifier'];
00536 $smartClearType = $dependentClassInfo['clear_cache_type'];
00537
00538
00539 $nodePathList =& eZContentCacheManager::fetchNodePathString( $assignedNodes );
00540
00541 foreach ( $nodePathList as $nodePath )
00542 {
00543 $step = 0;
00544
00545
00546 $nodeInfoList =& eZContentObjectTreeNode::fetchClassIdentifierListByPathString( $nodePath, false, $maxParents );
00547
00548
00549
00550 foreach ( $nodeInfoList as $item )
00551 {
00552 if ( in_array( $item['class_identifier'], $dependentClassIdentifiers ) )
00553 {
00554 $object =& eZContentObject::fetchByNodeID( $item['node_id'] );
00555 $objectID = $object->attribute( 'id' );
00556
00557 if ( isset( $handledObjectList[$objectID] ) )
00558 {
00559
00560 $smartClearType &= ~$handledObjectList[$objectID];
00561
00562
00563 if ( $smartClearType == 0 )
00564 {
00565 continue;
00566 }
00567 }
00568
00569 if ( count( $dependentClassInfo['object_filter'] ) > 0 )
00570 {
00571 if ( in_array( $objectID, $dependentClassInfo['object_filter'] ) )
00572 {
00573
00574 eZContentCacheManager::nodeListForObject( $object, true, $smartClearType, $nodeList, $handledObjectList );
00575 }
00576 }
00577 else
00578 {
00579
00580 eZContentCacheManager::nodeListForObject( $object, true, $smartClearType, $nodeList, $handledObjectList );
00581 }
00582 }
00583 }
00584 }
00585 }
00586
00587
00588 }
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604 function &nodeList( $objectID, $versionNum )
00605 {
00606 $nodeList = array();
00607
00608 $object =& eZContentObject::fetch( $objectID );
00609 if ( !$object )
00610 {
00611 $nodeList = false;
00612 return $nodeList;
00613 }
00614
00615 eZContentCacheManager::nodeListForObject( $object, $versionNum, EZ_VCSC_CLEAR_DEFAULT, $nodeList, $handledObjectList );
00616
00617 return $nodeList;
00618 }
00619
00620
00621
00622
00623
00624 function clearViewCache( $objectID, $versionNum = true , $additionalNodeList = false )
00625 {
00626 eZDebug::writeWarning( "'clearViewCache' function was depreciated. Use 'clearObjectViewCache' instead", 'eZContentCacheManager::clearViewCache' );
00627 eZContentCacheManager::clearObjectViewCache( $objectID, $versionNum, $additionalNodeList );
00628 }
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640 function clearObjectViewCache( $objectID, $versionNum = true, $additionalNodeList = false )
00641 {
00642 eZDebug::accumulatorStart( 'node_cleanup_list', '', 'Node cleanup list' );
00643
00644 $nodeList =& eZContentCacheManager::nodeList( $objectID, $versionNum );
00645
00646 if ( $nodeList === false and !is_array( $additionalNodeList ) )
00647 return false;
00648
00649 if ( $nodeList === false )
00650 {
00651 $nodeList = array();
00652 }
00653
00654 if ( is_array( $additionalNodeList ) )
00655 {
00656 array_splice( $nodeList, count( $nodeList ), 0, $additionalNodeList );
00657 }
00658
00659 if ( count( $nodeList ) == 0 )
00660 {
00661 return false;
00662 }
00663
00664 $nodeList = array_unique( $nodeList );
00665
00666 eZDebug::accumulatorStop( 'node_cleanup_list' );
00667
00668 eZDebugSetting::writeDebug( 'kernel-content-edit', count( $nodeList ), "count in nodeList" );
00669
00670 $ini =& eZINI::instance();
00671 if ( $ini->variable( 'ContentSettings', 'StaticCache' ) == 'enabled' )
00672 {
00673 include_once( 'kernel/classes/ezstaticcache.php' );
00674 include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
00675 $staticCache = new eZStaticCache();
00676 $staticCache->generateAlwaysUpdatedCache();
00677 $staticCache->generateNodeListCache( eZContentObjectTreeNode::fetchAliasesFromNodeList( $nodeList ) );
00678 }
00679
00680 include_once( 'kernel/classes/ezcontentcache.php' );
00681
00682 eZDebug::accumulatorStart( 'node_cleanup', '', 'Node cleanup' );
00683
00684 eZContentObject::expireComplexViewModeCache();
00685 $cleanupValue = eZContentCache::calculateCleanupValue( count( $nodeList ) );
00686
00687 if ( eZContentCache::inCleanupThresholdRange( $cleanupValue ) )
00688 eZContentCache::cleanup( $nodeList );
00689 else
00690 eZContentObject::expireAllViewCache();
00691
00692 eZDebug::accumulatorStop( 'node_cleanup' );
00693 return true;
00694 }
00695
00696
00697
00698
00699
00700
00701 function clearObjectViewCacheIfNeeded( $objectID, $versionNum = true, $additionalNodeList = false )
00702 {
00703 $ini = eZINI::instance();
00704 if ( $ini->variable( 'ContentSettings', 'ViewCaching' ) === 'enabled' )
00705 eZContentCacheManager::clearObjectViewCache( $objectID, $versionNum, $additionalNodeList );
00706 }
00707
00708
00709
00710
00711
00712
00713
00714 function clearTemplateBlockCacheIfNeeded( $objectID )
00715 {
00716 $ini = eZINI::instance();
00717 if ( $ini->variable( 'TemplateSettings', 'TemplateCache' ) === 'enabled' )
00718 eZContentCacheManager::clearTemplateBlockCache( $objectID );
00719 }
00720
00721
00722
00723
00724
00725
00726 function clearTemplateBlockCache( $objectID )
00727 {
00728
00729 eZContentObject::expireTemplateBlockCache();
00730
00731
00732 $nodeList = false;
00733 $object = false;
00734 if ( $objectID )
00735 $object = eZContentObject::fetch( $objectID );
00736 if ( $object )
00737 $nodeList =& $object->assignedNodes();
00738
00739 include_once( 'kernel/classes/ezsubtreecache.php' );
00740 eZSubtreeCache::cleanup( $nodeList );
00741 }
00742
00743
00744
00745
00746
00747
00748
00749
00750 function generateObjectViewCache( $objectID )
00751 {
00752
00753 $ini =& eZINI::instance();
00754 $object = eZContentObject::fetch( $objectID );
00755 $user =& eZUser::currentUser();
00756
00757 include_once( 'kernel/classes/eznodeviewfunctions.php' );
00758 eZDebug::accumulatorStart( 'generate_cache', '', 'Generating view cache' );
00759 if ( $ini->variable( 'ContentSettings', 'PreViewCache' ) == 'enabled' )
00760 {
00761 $preCacheSiteaccessArray = $ini->variable( 'ContentSettings', 'PreCacheSiteaccessArray' );
00762
00763 $currentSiteAccess = $GLOBALS['eZCurrentAccess']['name'];
00764
00765
00766 $viewParameters = array( 'offset' => 0,
00767 'year' => false,
00768 'month' => false,
00769 'day' => false,
00770 'namefilter' => false );
00771
00772 foreach ( $preCacheSiteaccessArray as $changeToSiteAccess )
00773 {
00774 $GLOBALS['eZCurrentAccess']['name'] = $changeToSiteAccess;
00775
00776 if ( $GLOBALS['eZCurrentAccess']['type'] == EZ_ACCESS_TYPE_URI )
00777 {
00778 eZSys::clearAccessPath();
00779 eZSys::addAccessPath( $changeToSiteAccess );
00780 }
00781
00782 include_once( 'kernel/common/template.php' );
00783 $tpl =& templateInit();
00784 $res =& eZTemplateDesignResource::instance();
00785
00786
00787 $siteini = eZINI::instance( 'site.ini', 'settings', null, null, false );
00788 $siteini->prependOverrideDir( "siteaccess/$changeToSiteAccess", false, 'siteaccess' );
00789 $siteini->loadCache();
00790 $designSetting = $siteini->variable( "DesignSettings", "SiteDesign" );
00791 $cachedViewPreferences = $siteini->variable( 'ContentSettings', 'CachedViewPreferences' );
00792 $res->setDesignSetting( $designSetting, 'site' );
00793
00794 $res->setOverrideAccess( $changeToSiteAccess );
00795
00796 $language = false;
00797 $viewMode = 'full';
00798
00799 $assignedNodes =& $object->assignedNodes();
00800 $assignedNodes_keys = array_keys( $assignedNodes );
00801 foreach ( $assignedNodes_keys as $key )
00802 {
00803 $node =& $assignedNodes[$key];
00804
00805
00806 $previewCacheUsers = $ini->variable( 'ContentSettings', 'PreviewCacheUsers' );
00807 foreach ( $previewCacheUsers as $previewCacheUserID )
00808 {
00809
00810 if ( $previewCacheUserID === 'anonymous' )
00811 {
00812 $previewCacheUserID = $siteini->variable( "UserSettings", "AnonymousUserID" );
00813 $previewCacheUser = eZUser::fetch( $previewCacheUserID );
00814 }
00815 else if ( $previewCacheUserID === 'current' )
00816 {
00817 $previewCacheUser =& $user;
00818 }
00819 else
00820 {
00821 $previewCacheUser = eZUser::fetch( $previewCacheUserID );
00822 }
00823 if ( !$previewCacheUser )
00824 continue;
00825
00826
00827
00828 $previewCacheUser->setCurrentlyLoggedInUser( $previewCacheUser, $previewCacheUser->attribute( 'contentobject_id' ) );
00829
00830
00831 $cacheFileArray = eZNodeviewfunctions::generateViewCacheFile( $previewCacheUser, $node->attribute( 'node_id' ), 0, false, $language, $viewMode, $viewParameters, $cachedViewPreferences );
00832 $tmpRes =& eZNodeviewfunctions::generateNodeView( $tpl, $node, $node->attribute( 'object' ), $language, $viewMode, 0, $cacheFileArray['cache_dir'], $cacheFileArray['cache_path'], true, $viewParameters );
00833
00834
00835 $parentNode =& $node->attribute( 'parent' );
00836 $objectID = $parentNode->attribute( 'contentobject_id' );
00837
00838 if ( $objectID )
00839 {
00840 $cacheFileArray = eZNodeviewfunctions::generateViewCacheFile( $previewCacheUser, $parentNode->attribute( 'node_id' ), 0, false, $language, $viewMode, $viewParameters, $cachedViewPreferences );
00841 $tmpRes =& eZNodeviewfunctions::generateNodeView( $tpl, $parentNode, $parentNode->attribute( 'object' ), $language, $viewMode, 0, $cacheFileArray['cache_dir'], $cacheFileArray['cache_path'], true, $viewParameters );
00842 }
00843 }
00844 }
00845 }
00846
00847 $user->setCurrentlyLoggedInUser( $user, $user->attribute( 'contentobject_id' ) );
00848
00849 $GLOBALS['eZCurrentAccess']['name'] = $currentSiteAccess;
00850 $res->setDesignSetting( $currentSiteAccess, 'site' );
00851 $res->setOverrideAccess( false );
00852 if ( $GLOBALS['eZCurrentAccess']['type'] == EZ_ACCESS_TYPE_URI )
00853 {
00854 eZSys::clearAccessPath();
00855 eZSys::addAccessPath( $currentSiteAccess );
00856 }
00857 }
00858
00859 if ( $ini->variable( 'ContentSettings', 'StaticCache' ) == 'enabled' )
00860 {
00861 include_once( 'kernel/classes/ezstaticcache.php' );
00862 include_once( 'kernel/classes/ezcontentcachemanager.php' );
00863
00864 $nodes = array();
00865 $ini =& eZINI::instance();
00866 $staticCache = new eZStaticCache();
00867 $useURLAlias =& $GLOBALS['eZContentObjectTreeNodeUseURLAlias'];
00868 $pathPrefix = $ini->variable( 'SiteAccessSettings', 'PathPrefix' );
00869
00870 if ( !isset( $useURLAlias ) )
00871 {
00872 $useURLAlias = $ini->variable( 'URLTranslator', 'Translation' ) == 'enabled';
00873 }
00874
00875 eZContentCacheManager::nodeListForObject( $object, true, EZ_VCSC_CLEAR_DEFAULT, $nodes, $handledObjectList );
00876 foreach ( $nodes as $nodeID )
00877 {
00878 if ( $useURLAlias )
00879 {
00880 $aNode = eZContentObjectTreeNode::fetch( $nodeID, false, false );
00881 if ( !isset( $aNode ) )
00882 continue;
00883
00884 $urlAlias = $aNode['path_identification_string'];
00885 if ( $pathPrefix != '' )
00886 {
00887 $tempAlias = substr( $pathPrefix, strlen( $pathPrefix ) -1 ) == '/'
00888 ? $urlAlias . '/'
00889 : $urlAlias;
00890 if ( strncmp( $tempAlias, $pathPrefix, strlen( $tempAlias) ) == 0 )
00891 $urlAlias = substr( $tempAlias, strlen( $pathPrefix ) );
00892 }
00893 }
00894 else
00895 {
00896 $urlAlias = 'content/view/full/' . $nodeID;
00897 }
00898 $staticCache->cacheURL( '/' . $urlAlias, $nodeID );
00899 }
00900 $staticCache->generateAlwaysUpdatedCache();
00901 }
00902 eZDebug::accumulatorStop( 'generate_cache' );
00903 }
00904
00905
00906
00907
00908
00909 function clearContentCacheIfNeededBySectionID( $sectionID )
00910 {
00911
00912 $objectList = eZContentObject::fetchList( false, array( 'section_id' => "$sectionID" ) );
00913
00914 foreach ( $objectList as $object )
00915 {
00916 eZContentCacheManager::clearContentCacheIfNeeded( $object['id'] );
00917 }
00918 return true;
00919 }
00920
00921
00922
00923
00924
00925
00926 function clearContentCacheIfNeeded( $objectID, $versionNum = true, $additionalNodeList = false )
00927 {
00928 eZDebug::accumulatorStart( 'check_cache', '', 'Check cache' );
00929
00930 eZContentCacheManager::clearObjectViewCacheIfNeeded( $objectID, $versionNum, $additionalNodeList );
00931 eZContentCacheManager::clearTemplateBlockCacheIfNeeded( $objectID );
00932
00933
00934 include_once( 'kernel/classes/ezsslzone.php' );
00935 eZSSLZone::clearCacheIfNeeded();
00936
00937 eZDebug::accumulatorStop( 'check_cache' );
00938 return true;
00939 }
00940
00941
00942
00943
00944
00945
00946 function clearContentCache( $objectID, $versionNum = true, $additionalNodeList = false )
00947 {
00948 eZDebug::accumulatorStart( 'check_cache', '', 'Check cache' );
00949
00950 eZContentCacheManager::clearObjectViewCache( $objectID, $versionNum, $additionalNodeList );
00951 eZContentCacheManager::clearTemplateBlockCache( $objectID );
00952
00953
00954 include_once( 'kernel/classes/ezsslzone.php' );
00955 eZSSLZone::clearCache();
00956
00957 eZDebug::accumulatorStop( 'check_cache' );
00958 return true;
00959 }
00960
00961
00962
00963
00964
00965 function clearAllContentCache( $ignoreINISettings = false )
00966 {
00967 if ( !$ignoreINISettings )
00968 {
00969 $ini = eZINI::instance();
00970 $viewCacheEnabled = ( $ini->variable( 'ContentSettings', 'ViewCaching' ) === 'enabled' );
00971 $templateCacheEnabled = ( $ini->variable( 'TemplateSettings', 'TemplateCache' ) === 'enabled' );
00972 }
00973 else
00974 {
00975 $viewCacheEnabled = true;
00976 $templateCacheEnabled = true;
00977 }
00978
00979 if ( $viewCacheEnabled || $templateCacheEnabled )
00980 {
00981
00982 eZContentObject::expireAllCache();
00983
00984
00985 if ( $templateCacheEnabled )
00986 {
00987 include_once( 'kernel/classes/ezsubtreecache.php' );
00988 eZSubtreeCache::cleanupAll();
00989 }
00990 }
00991 }
00992 }
00993
00994 ?>