From 6c26c69fbb42048ab02b984ef54ac57f05afa55e Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 3 Nov 2012 09:28:42 +0100 Subject: [PATCH] Improves cache list page --- .../install/files/acp/templates/cacheList.tpl | 78 +++--- .../lib/acp/page/CacheListPage.class.php | 238 ++++++++++-------- wcfsetup/install/lang/de.xml | 41 +-- wcfsetup/install/lang/en.xml | 41 +-- 4 files changed, 226 insertions(+), 172 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/cacheList.tpl b/wcfsetup/install/files/acp/templates/cacheList.tpl index eadbdd2bb4..1fa97d56d6 100644 --- a/wcfsetup/install/files/acp/templates/cacheList.tpl +++ b/wcfsetup/install/files/acp/templates/cacheList.tpl @@ -24,7 +24,11 @@
{lang}wcf.acp.cache.data.source{/lang}
-
{$cacheData.source}
+
+ {assign var='__source' value='\\'|explode:$cacheData.source} + {lang}wcf.acp.cache.source.type.{$__source|array_pop}{/lang} + {$cacheData.source} +
{if $cacheData.version}
@@ -55,41 +59,45 @@ -{foreach from=$caches key=cache item=files} - {counter name=cacheIndex assign=cacheIndex print=false start=0} - {if $files|count} -
-
-

{$cache} {#$files|count}

-
- - - - - - - - {if $files.0.perm|isset} - - {/if} - - +{foreach from=$caches key='cacheType' item='cacheTypeCaches'} + {foreach from=$cacheTypeCaches key='cache' item='files'} + {counter name=cacheIndex assign=cacheIndex print=false start=0} + + {if $files|count} +
+
+

{lang}wcf.acp.cache.type.{$cacheType}{/lang} {#$files|count}

+

{$cache}

+
-
- {foreach from=$files item=file} - - - - - {if $file.perm|isset} - - {/if} - - {/foreach} - - -
- {/if} + + + + + + + {if $files.0.perm|isset} + + {/if} + + + + + {foreach from=$files item=file} + + + + + {if $file.perm|isset} + + {/if} + + {/foreach} + + + + {/if} + {/foreach} {/foreach}
diff --git a/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php b/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php index ee9fa388b2..169c59767e 100755 --- a/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php @@ -69,119 +69,151 @@ class CacheListPage extends AbstractPage { 'files' => 0 ); - $_this = $this; - $readFileCache = function($cacheDir, Regex $ignore = null) use ($_this) { - $_this->caches[$cacheDir] = array(); + switch ($this->cacheData['source']) { + case 'wcf\system\cache\source\DiskCacheSource': + // set version + $this->cacheData['version'] = WCF_VERSION; + + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); + $conditions->add("isApplication = ?", array(1)); + + // get package dirs + $sql = "SELECT packageDir + FROM wcf".WCF_N."_package + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + while ($row = $statement->fetchArray()) { + $packageDir = FileUtil::getRealPath(WCF_DIR.$row['packageDir']); + $this->readCacheFiles('data', $packageDir.'cache'); + } + break; - // get files in cache directory - try { - $directoryUtil = DirectoryUtil::getInstance($cacheDir); - } - catch(SystemException $e) { - return; - } - $files = $directoryUtil->getFileObjects(SORT_ASC, new Regex('\.php$')); - // get additional file information - if (is_array($files)) { - foreach ($files as $file) { - if ($ignore !== null) if ($ignore->match($file)) continue; - $_this->caches[$cacheDir][] = array( - 'filename' => $file->getBasename(), - 'filesize' => $file->getSize(), - 'mtime' => $file->getMtime(), - 'perm' => substr(sprintf('%o', $file->getPerms()), -3), - 'writable' => $file->isWritable() - ); - - $_this->cacheData['files']++; - $_this->cacheData['size'] += $file->getSize(); + case 'wcf\system\cache\source\MemcacheCacheSource': + // set version + $this->cacheData['version'] = WCF_VERSION; + + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); + $conditions->add("isApplication = ?", array(1)); + + // get package dirs + $sql = "SELECT packageDir + FROM wcf".WCF_N."_package + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + while ($row = $statement->fetchArray()) { + $packageDir = FileUtil::getRealPath(WCF_DIR.$row['packageDir']); + $this->readCacheFiles('data', $packageDir.'cache'); } - } - }; - - // filesystem cache - if ($this->cacheData['source'] == 'wcf\system\cache\source\DiskCacheSource') { - // set version - $this->cacheData['version'] = WCF_VERSION; + break; - $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); - $conditions->add("isApplication = ?", array(1)); + case 'wcf\system\cache\source\ApcCacheSource': + // set version + $this->cacheData['version'] = phpversion('apc'); + + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); + $conditions->add("isApplication = ?", array(1)); + + // get package dirs + $sql = "SELECT packageDir, packageName, instanceNo + FROM wcf".WCF_N."_package + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + + $packageNames = array(); + while ($row = $statement->fetchArray()) { + $packagePath = FileUtil::getRealPath(WCF_DIR.$row['packageDir']).'cache/'; + $packageNames[$packagePath] = $row['packageName'].' #'.$row['instanceNo']; + } + + $apcinfo = apc_cache_info('user'); + $cacheList = $apcinfo['cache_list']; + foreach ($cacheList as $cache) { + $cachePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(dirname($cache['info']))); + if (isset($packageNames[$cachePath])) { + // Use the packageName + the instance number, because pathes could confuse the administrator. + // He could think this is a file cache. If instanceName would be unique, we could use it instead. + $packageName = $packageNames[$cachePath]; + if (!isset($this->caches['data'])) { + $this->caches['data'] = array(); + } + if (!isset($this->caches['data'][$packageName])) { + $this->caches['data'][$packageName] = array(); + } + + // get additional cache information + $this->caches['data'][$packageName][] = array( + 'filename' => basename($cache['info'], '.php'), + 'filesize' => $cache['mem_size'], + 'mtime' => $cache['mtime'], + ); + + $this->cacheData['files']++; + $this->cacheData['size'] += $cache['mem_size']; + } + } + break; - // get package dirs - $sql = "SELECT packageDir - FROM wcf".WCF_N."_package - ".$conditions; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($conditions->getParameters()); - while ($row = $statement->fetchArray()) { - $packageDir = FileUtil::getRealPath(WCF_DIR.$row['packageDir']); - $readFileCache($packageDir.'cache'); - } + case 'wcf\system\cache\source\NoCacheSource': + $this->cacheData['version'] = WCF_VERSION; + $this->cacheData['files'] = $this->cacheData['size'] = 0; + break; } - // memcache - else if ($this->cacheData['source'] == 'wcf\system\cache\source\MemcacheCacheSource') { - // get version - $this->cacheData['version'] = MemcacheAdapter::getInstance()->getMemcache()->getVersion(); - - // get stats - $stats = MemcacheAdapter::getInstance()->getMemcache()->getStats(); - $this->cacheData['files'] = $stats['curr_items']; - $this->cacheData['size'] = $stats['bytes']; + + $this->readCacheFiles('language', WCF_DIR.'language'); + $this->readCacheFiles('template', WCF_DIR.'templates/compiled', new Regex('\.meta\.php$')); + $this->readCacheFiles('template', WCF_DIR.'acp/templates/compiled', new Regex('\.meta\.php$')); + } + + /** + * Reads the information of cached files + * + * @param string $cacheType + * @param strign $cacheDir + * @param wcf\system\Regex $ignore + */ + protected function readCacheFiles($cacheType, $cacheDir, Regex $ignore = null) { + if (!isset($this->cacheData[$cacheType])) { + $this->cacheData[$cacheType] = array(); } - // apc - else if ($this->cacheData['source'] == 'wcf\system\cache\source\ApcCacheSource') { - // set version - $this->cacheData['version'] = phpversion('apc'); - - $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); - $conditions->add("isApplication = ?", array(1)); - - // get package dirs - $sql = "SELECT packageDir, packageName, instanceNo - FROM wcf".WCF_N."_package - ".$conditions; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($conditions->getParameters()); - - $packageNames = array(); - while ($row = $statement->fetchArray()) { - $packagePath = FileUtil::getRealPath(WCF_DIR.$row['packageDir']).'cache/'; - $packageNames[$packagePath] = $row['packageName'].' #'.$row['instanceNo']; - } - - $apcinfo = apc_cache_info('user'); - $cacheList = $apcinfo['cache_list']; - foreach ($cacheList as $cache) { - $cachePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(dirname($cache['info']))); - if (isset($packageNames[$cachePath])) { - // Use the packageName + the instance number, because pathes could confuse the administrator. - // He could think this is a file cache. If instanceName would be unique, we could use it instead. - $packageName = $packageNames[$cachePath]; - if (!isset($this->caches[$packageName])) $this->caches[$packageName] = array(); - - // get additional cache information - $this->caches[$packageName][] = array( - 'filename' => basename($cache['info'], '.php'), - 'filesize' => $cache['mem_size'], - 'mtime' => $cache['mtime'], - ); - - $this->cacheData['files']++; - $this->cacheData['size'] += $cache['mem_size']; + + // get files in cache directory + try { + $directoryUtil = DirectoryUtil::getInstance($cacheDir); + } + catch (SystemException $e) { + return; + } + + $files = $directoryUtil->getFileObjects(SORT_ASC, new Regex('\.php$')); + + // get additional file information + $data = array(); + if (is_array($files)) { + foreach ($files as $file) { + if ($ignore !== null && $ignore->match($file)) { + continue; } + + $data[] = array( + 'filename' => $file->getBasename(), + 'filesize' => $file->getSize(), + 'mtime' => $file->getMtime(), + 'perm' => substr(sprintf('%o', $file->getPerms()), -3), + 'writable' => $file->isWritable() + ); + + $this->cacheData['files']++; + $this->cacheData['size'] += $file->getSize(); } } - // disabled - else if ($this->cacheData['source'] == 'wcf\system\cache\source\NoCacheSource') { - $this->cacheData['version'] = WCF_VERSION; - $this->cacheData['files'] = $this->cacheData['size'] = 0; - } - $readFileCache(WCF_DIR.'language'); - $readFileCache(WCF_DIR.'templates/compiled', new Regex('\.meta\.php$')); - $readFileCache(WCF_DIR.'acp/templates/compiled', new Regex('\.meta\.php$')); + $this->caches[$cacheType][$cacheDir] = $data; } /** diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 90764aac82..ab9922a6be 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -4,6 +4,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -107,23 +131,6 @@ - - - - - - - - - - - - - - - - - diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 29ccb09ef2..6240cd171d 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -4,6 +4,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -107,23 +131,6 @@ - - - - - - - - - - - - - - - - - -- 2.20.1