Adding Health-Check and Events to IndexPage of ACP
authorTim Düsterhus <timwolla@arcor.de>
Thu, 19 Apr 2012 19:25:43 +0000 (21:25 +0200)
committerTim Düsterhus <timwolla@arcor.de>
Thu, 19 Apr 2012 19:25:43 +0000 (21:25 +0200)
wcfsetup/install/files/acp/templates/index.tpl
wcfsetup/install/files/lib/acp/page/IndexPage.class.php

index d704086ec2e8d180f09211a04679cec719b095b7..d38f9e55601702c9efc03e3d1d93f2370e099aa2 100644 (file)
@@ -7,6 +7,10 @@
        //]]>
 </script>
 <style type="text/css">
+#health ul {
+       list-style: disc;
+       padding-left: 16px;
+}
 #credits dd > ul > li {
        display: inline;
 }
        content: "";
 }
 </style>
-{if $didYouKnow !== ''}<p class="info">{lang}wcf.acp.index.didYouKnow{/lang}: {$didYouKnow|language}</p>{/if}
+{if $didYouKnow !== ''}<p class="info">{lang}wcf.acp.index.didYouKnow{/lang}: {@$didYouKnow|language}</p>{/if}
+<p class="{@$health}">{lang}wcf.acp.index.health.summary.{@$health}{/lang}</p>
+{event name='boxes'}
 
-<div class="tabMenuContainer" data-active="credits" data-store="activeTabMenuItem">
+<div class="tabMenuContainer" data-active="{if $health !== 'success'}health{else}credits{/if}" data-store="activeTabMenuItem">
        <nav class="tabMenu">
                <ul>
+                       {if $health !== 'success'}<li><a href="#health" title="Health">Health</a></li>{/if}
                        <li><a href="#credits" title="Credits">Credits</a></li>
+                       {event name='tabs'}
                </ul>
        </nav>
-       
+       {if $health !== 'success'}
+               <div id="health" class="container containerPadding shadow hidden tabMenuContent">
+                       {foreach from=$healthDetails item='issues' key='healthType'}
+                               {hascontent}
+                               <fieldset><legend><img src="{$__wcf->getPath()}icon/system{$healthType|ucfirst}.svg" class="icon24" /> {lang}wcf.acp.index.health.detail.{@$healthType}{/lang}</legend>
+                                       <ul>
+                                       {content}
+                                               {foreach from=$issues item='issue'}
+                                                       <li>{@$issue}</li>
+                                               {/foreach}
+                                       {/content}
+                                       </ul>
+                               </fieldset>
+                               {/hascontent}
+                       {/foreach}
+               </div>
+       {/if}
        <fieldset id="credits" class="container containerPadding shadow hidden tabMenuContent">
                <dl>
                        <dt>{lang}wcf.acp.index.credits.developedBy{/lang}</dt>
@@ -45,7 +69,8 @@
                        <dt>{lang}wcf.acp.index.credits.developer{/lang}</dt>
                        <dd>
                                <ul>
-                                       <li>Alexander Ebert</li><li>Marcel Werk</li>
+                                       <li>Alexander Ebert</li>
+                                       <li>Marcel Werk</li>
                                </ul>
                        </dd>
                </dl>
@@ -54,7 +79,8 @@
                        <dt>{lang}wcf.acp.index.credits.designer{/lang}</dt>
                        <dd>
                                <ul>
-                                       <li>Harald Szekely</li><li>Marcel Werk</li>
+                                       <li>Harald Szekely</li>
+                                       <li>Marcel Werk</li>
                                </ul>
                        </dd>
                </dl>
                        <dt>{lang}wcf.acp.index.credits.contributor{/lang}</dt>
                        <dd>
                                <ul>
-                                       <li>Thorsten Buitkamp</li><li>Tim D&uuml;sterhus</li><li>Matthias Schmidt</li>
+                                       <li>Thorsten Buitkamp</li>
+                                       <li>Tim D&uuml;sterhus</li>
+                                       <li>Matthias Schmidt</li>
+                                       <li>
+                                               <a href="{@RELATIVE_WCF_DIR}acp/dereferrer.php?url={"https://github.com/WoltLab/WCF/contributors"|rawurlencode}" class="externalURL">
+                                                       {lang}wcf.acp.index.credits.contributor.more{/lang}
+                                               </a>
+                                       </li>
                                </ul>
                        </dd>
                </dl>
                        <dd>{lang}wcf.acp.index.credits.trademarks{/lang}</dd>
                </dl>
        </fieldset>
+       
+       {event name='tabContent'}
 </div>
 {include file='footer'}
\ No newline at end of file
index 8245bb95317285d00e55985993241107903c1b5d..9747d8636245b80912bf900fcb4dfdbfef0a6e63 100755 (executable)
@@ -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