forked from crevillo/cacheblockpurge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
65 lines (52 loc) · 1.72 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
function expireCacheBlock( $template, $keyAttributeValue )
{
$functionPlacement = fetchCacheBlockPlacement( $template );
$placementKeyString = eZTemplateCacheBlock::placementString( $functionPlacement );
$keys = array(
// cache-block key attribute
$keyAttributeValue,
// cache-block placement in the template
$placementKeyString,
// siteaccess
$GLOBALS['eZCurrentAccess']['name'],
);
// subtree_expiry is NOT supported
$nodeID = false;
$cachePath = eZTemplateCacheBlock::cachePath(
eZTemplateCacheBlock::keyString( $keys ), $nodeID
);
// should use the cluster API here
unlink( $cachePath );
}
function fetchCacheBlockPlacement( $template )
{
$ini = eZINI::instance();
$ini->setVariable( 'TemplateSettings', 'TemplateCompile', 'disabled' );
$tpl = eZTemplate::factory();
$resource = $tpl->loadURIRoot(
"file:{$template}", $displayErrors = false, $extraParameters = array()
);
$tpl->process( $resource['root-node'], $text, "", "" );
$children = $resource['root-node'][1];
$functionPlacement = array();
// searching for the {cache-block ...} function
// and its placement
foreach ( $children as $child)
{
$nodeType = $child[0];
if( $nodeType == eZTemplate::NODE_FUNCTION )
{
$functionPlacement = $child[4];
}
}
return $functionPlacement;
}
//
// change the $template and $key variable and run
// this file with ezexec.php :
// php ./bin/php/ezexec.php -s <siteaccess> <thisfile>.php
$template = 'extension/varnishcache/design/varnishcachetests/templates/testcacheblock.tpl';
$key = 'varnishtest';
expireCacheBlock( $template, $key );
?>