Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcachehelper.php
Go to the documentation of this file.
1 <?php
11 class eZCacheHelper
12 {
16 private $cli;
17
21 private $script;
22
23 public function __construct( eZCLI $cli, eZScript $script )
24 {
25 $this->cli = $cli;
26 $this->script = $script;
27 }
28
29 public function clearItems( $cacheEntries, $name )
30 {
31 $this->internalClear( false, $cacheEntries, $name );
32 }
33
34 public function purgeItems( $cacheEntries, $name, $purgeSleep, $purgeMax, $purgeExpiry )
35 {
36 $this->internalClear( true, $cacheEntries, $name, $purgeSleep, $purgeMax, $purgeExpiry );
37 }
38
39 private function internalClear( $purge, $cacheEntries, $name, $purgeSleep = null, $purgeMax = null, $purgeExpiry = null )
40 {
41 $this->cli->output(
42 ( $purge ? 'Purging ' : 'Clearing ' ) . $this->cli->stylize( 'emphasize', $name ? $name : 'All cache' ) . ': '
43 );
44
45 $warnPaths = array();
46 foreach ( $cacheEntries as $cacheEntry )
47 {
48 $absPath = realpath( eZSys::cacheDirectory() . DIRECTORY_SEPARATOR . $cacheEntry['path'] );
49 $absPathElementCount = count( explode( DIRECTORY_SEPARATOR, rtrim( $absPath, DIRECTORY_SEPARATOR ) ) );
50 // Refuse to delete root directory ('/' or 'C:\')
51 // 2 => since one path element ('/foo') produces two exploded elements
52 if ( $absPath && $absPathElementCount < 2 )
53 {
54 $this->cli->error( 'Refusing to delete root directory! Please check your cache settings. Path: ' . $absPath );
55 $this->script->shutdown( 1 );
56 exit();
57 }
58
59 // Warn if the cache entry is not function based, and the path is outside ezp root, and the path has less than 2 elements
60 if (
61 $absPath
62 && ( !$purge || !isset( $cacheEntry['purge-function'] ) )
63 && !isset( $cacheEntry['function'] )
64 // 3 => since two path elements ('/foo/bar') produce three exploded elements
65 && $absPathElementCount < 3
66 && strpos( dirname( $absPath ) . DIRECTORY_SEPARATOR, realpath( eZSys::rootDir() ) . DIRECTORY_SEPARATOR ) === false
67 )
68 {
69 $warnPaths[] = $absPath;
70 }
71 }
72
73 if ( !empty( $warnPaths ) )
74 {
75 $this->cli->warning(
76 'The following cache paths are outside of the eZ Publish root directory, and have less than 2 path elements. ' .
77 'Are you sure you want to ' . ( $purge ? 'purge' : 'clear' ) . ' them?'
78 );
79
80 foreach ( $warnPaths as $warnPath )
81 {
82 $this->cli->output( $warnPath );
83 }
84
85 if ( function_exists( "getUserInput" ) )
86 {
87 $input = getUserInput( ( $purge ? 'Purge' : 'Clear' ) . '? yes/no:', array( 'yes', 'no' ) );
88 }
89 else
90 {
91 $validInput = false;
92 $readlineExists = function_exists( "readline" );
93 while ( !$validInput )
94 {
95 if ( $readlineExists )
96 {
97 $input = readline( $query );
98 }
99 else
100 {
101 echo $prompt . ' ';
102 $input = trim( fgets( STDIN ) );
103 }
104 if ( $acceptValues === false || in_array( $input, $acceptValues ) )
105 {
106 $validInput = true;
107 }
108 }
109 }
110
111 if ( $input === 'no' )
112 {
113 $this->script->shutdown();
114 exit();
115 }
116 }
117
118 $firstItem = true;
119 foreach ( $cacheEntries as $cacheEntry )
120 {
121 if ( $firstItem )
122 $firstItem = false;
123 else
124 $this->cli->output( ', ', false );
125
126 $this->cli->output( $this->cli->stylize( 'emphasize', $cacheEntry['name'] ), false );
127
128 if ( $purge )
129 eZCache::clearItem( $cacheEntry, true, array( $this, 'reportProgress'), $purgeSleep, $purgeMax, $purgeExpiry );
130 else
131 eZCache::clearItem( $cacheEntry );
132 }
133 $this->cli->output();
134 }
135
136 public function reportProgress( $filename, $count )
137 {
138 static $progress = array( '|', '/', '-', '\\' );
139
140 if ( $count == 0 )
141 {
142 $this->cli->output( $this->cli->storePosition() . " " . $this->cli->restorePosition(), false );
143 }
144 else
145 {
146 $text = array_shift( $progress );
147 $this->cli->output( $this->cli->storePosition() . $text . $this->cli->restorePosition(), false );
148 $progress[] = $text;
149 }
150 }
151 }
eZCLI
CLI handling.
Definition: ezcli.php:31
eZCacheHelper
Definition: ezcachehelper.php:12
eZCacheHelper\$cli
$cli
Definition: ezcachehelper.php:16
eZCacheHelper\$script
$script
Definition: ezcachehelper.php:21
eZCacheHelper\reportProgress
reportProgress( $filename, $count)
Definition: ezcachehelper.php:136
eZCacheHelper\__construct
__construct(eZCLI $cli, eZScript $script)
Definition: ezcachehelper.php:23
eZCacheHelper\purgeItems
purgeItems( $cacheEntries, $name, $purgeSleep, $purgeMax, $purgeExpiry)
Definition: ezcachehelper.php:34
eZCacheHelper\internalClear
internalClear( $purge, $cacheEntries, $name, $purgeSleep=null, $purgeMax=null, $purgeExpiry=null)
Definition: ezcachehelper.php:39
eZCacheHelper\clearItems
clearItems( $cacheEntries, $name)
Definition: ezcachehelper.php:29
eZCache\clearItem
static clearItem( $cacheItem, $purge=false, $reporter=false, $iterationSleep=false, $iterationMax=false, $expiry=false)
Definition: ezcache.php:461
eZScript
Handles the basics of script execution.
Definition: ezscript.php:49
eZSys\rootDir
static rootDir()
Definition: ezsys.php:547
eZSys\cacheDirectory
static cacheDirectory()
Definition: ezsys.php:527
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.