From 529425284389597ea10ce4a5c2efb414e78476d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 19 Apr 2012 21:25:43 +0200 Subject: [PATCH] Adding Health-Check and Events to IndexPage of ACP --- .../install/files/acp/templates/index.tpl | 47 ++++++++++++++++--- .../files/lib/acp/page/IndexPage.class.php | 44 ++++++++++++++++- 2 files changed, 84 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/index.tpl b/wcfsetup/install/files/acp/templates/index.tpl index d704086ec2..d38f9e5560 100644 --- a/wcfsetup/install/files/acp/templates/index.tpl +++ b/wcfsetup/install/files/acp/templates/index.tpl @@ -7,6 +7,10 @@ //]]> -{if $didYouKnow !== ''}

{lang}wcf.acp.index.didYouKnow{/lang}: {$didYouKnow|language}

{/if} +{if $didYouKnow !== ''}

{lang}wcf.acp.index.didYouKnow{/lang}: {@$didYouKnow|language}

{/if} +

{lang}wcf.acp.index.health.summary.{@$health}{/lang}

+{event name='boxes'} -
+
- + {if $health !== 'success'} + + {/if} + + {event name='tabContent'}
{include file='footer'} \ No newline at end of file diff --git a/wcfsetup/install/files/lib/acp/page/IndexPage.class.php b/wcfsetup/install/files/lib/acp/page/IndexPage.class.php index 8245bb9531..9747d86362 100755 --- a/wcfsetup/install/files/lib/acp/page/IndexPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/IndexPage.class.php @@ -2,6 +2,7 @@ namespace wcf\acp\page; use wcf\page\AbstractPage; use wcf\system\cache\CacheHandler; +use wcf\system\event\EventHandler; use wcf\system\language\LanguageFactory; use wcf\system\package\PackageInstallationDispatcher; use wcf\system\WCF; @@ -30,23 +31,64 @@ class IndexPage extends AbstractPage { */ public $didYouKnow = ''; + /** + * Detailed Health-Status + * + * @var array + */ + public $healthDetails = array('error' => array(), 'warning' => array(), 'info' => array()); + /** * @see wcf\page\IPage::assignVariables() */ public function assignVariables() { parent::assignVariables(); + $health = 'success'; + if (!empty($this->healthDetails['error'])) $health = 'error'; + else if (!empty($this->healthDetails['warning'])) $health = 'warning'; + else if (!empty($this->healthDetails['info'])) $health = 'info'; + WCF::getTPL()->assign(array( - 'didYouKnow' => $this->didYouKnow + 'didYouKnow' => $this->didYouKnow, + 'health' => $health, + 'healthDetails' => $this->healthDetails )); } + /** + * Performs various health checks + */ + public function calculateHealth() { + try { + // TODO: Fill this list + $shouldBeWritable = array(WCF_DIR); + foreach ($shouldBeWritable as $file) { + if (!is_writable($file)) $this->healthDetails['warning'][] = WCF::getLanguage()->getDynamicVariable('wcf.acp.index.health.notWritable', array('file' => $file)); + } + + for($i = 0; $i < 7; $i++) { + if (file_exists(WCF_DIR.'log/'.date('Y-m-d', TIME_NOW - 86400 * $i).'.txt')) { + $this->healthDetails['error'][] = WCF::getLanguage()->getDynamicVariable('wcf.acp.index.health.exception', array('date' => TIME_NOW - 86400 * $i)); + break; + } + } + + EventHandler::getInstance()->fireAction($this, 'calculateHealth'); + } + catch (\Exception $e) { + $this->healthDetails['error'][] = $e->getMessage(); + } + } + /** * @see wcf\page\IPage::readData() */ public function readData() { parent::readData(); + $this->calculateHealth(); + $sql = "SELECT languageItem FROM -- 2.20.1