[TASK] Store last access of modules linked in the System Information menu 81/38781/4
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Sat, 18 Apr 2015 11:39:19 +0000 (13:39 +0200)
committerNicole Cordes <typo3@cordes.co>
Tue, 21 Apr 2015 15:24:33 +0000 (17:24 +0200)
Store the access time of modules linked in
the System Information menu in the UC of the current backend user
to make it possible to reset the counter.

Resolves: #66234
Releases: master
Change-Id: I605680e50a04974455a30837463f51fe77fec56b
Reviewed-on: http://review.typo3.org/38781
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/backend/Resources/Private/Templates/ToolbarMenu/SystemInformation.html
typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/SystemInformationMenu.js
typo3/sysext/belog/Classes/Controller/SystemInformationController.php
typo3/sysext/belog/Resources/Private/Language/locallang.xlf

index 79ce28f..0e05a13 100644 (file)
        <f:if condition="{messages -> f:count()} > 0">
                <f:then>
                        <f:for each="{messages}" as="message">
-                               <li><span class="text-{message.status}"><f:format.raw>{message.text}</f:format.raw></span></li>
+                               <f:if condition="{message.module}">
+                                       <f:then>
+                                               <li id="systeminformation_{message.module}" class="t3js-systeminformation-module dropdown-intro typo3-module-menu-item submodule mod-{message.module}" data-modulename="{message.module}">
+                                                       <span class="text-{message.status}"><f:format.raw>{message.text}</f:format.raw></span>
+                                               </li>
+                                       </f:then>
+                                       <f:else>
+                                               <li>
+                                                       <span class="text-{message.status}"><f:format.raw>{message.text}</f:format.raw></span>
+                                               </li>
+                                       </f:else>
+                               </f:if>
                        </f:for>
                </f:then>
                <f:else>
index 0333dd2..35a9ca2 100644 (file)
 /**
  * System information menu handler
  */
-define('TYPO3/CMS/Backend/Toolbar/SystemInformationMenu', ['jquery'], function($) {
-
+define('TYPO3/CMS/Backend/Toolbar/SystemInformationMenu', ['jquery', 'TYPO3/CMS/Backend/Storage'], function($) {
        var SystemInformationMenu = {
                identifier: {
                        containerSelector: '#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem',
                        toolbarIconSelector: '.dropdown-toggle span.t3-icon',
-                       menuContainerSelector: '.dropdown-menu'
+                       menuContainerSelector: '.dropdown-menu',
+                       moduleLinks: '.t3js-systeminformation-module'
                },
                elements: {
                        $counter: $('#t3js-systeminformation-counter'),
@@ -31,21 +31,36 @@ define('TYPO3/CMS/Backend/Toolbar/SystemInformationMenu', ['jquery'], function($
        };
 
        /**
+        * Initialize the events
+        */
+       SystemInformationMenu.initialize = function() {
+               $(SystemInformationMenu.identifier.moduleLinks).on('click', SystemInformationMenu.openModule);
+       };
+
+       /**
         * Updates the menu
         */
        SystemInformationMenu.updateMenu = function() {
                var $toolbarItemIcon = $(SystemInformationMenu.identifier.toolbarIconSelector, SystemInformationMenu.identifier.containerSelector),
                        $spinnerIcon = SystemInformationMenu.elements.$spinnerElement.clone(),
-                       $existingIcon = $toolbarItemIcon.replaceWith($spinnerIcon);
+                       $existingIcon = $toolbarItemIcon.replaceWith($spinnerIcon),
+                       $menuContainer = $(SystemInformationMenu.identifier.containerSelector).find(SystemInformationMenu.identifier.menuContainerSelector);
+
+               // hide the menu if it's active
+               if ($menuContainer.is(':visible')) {
+                       $menuContainer.click();
+               }
 
                $.ajax({
                        url: TYPO3.settings.ajaxUrls['SystemInformationMenu::load'],
                        type: 'post',
                        cache: false,
                        success: function(data) {
-                               $(SystemInformationMenu.identifier.containerSelector).find(SystemInformationMenu.identifier.menuContainerSelector).html(data);
+                               $menuContainer.html(data);
                                SystemInformationMenu.updateCounter();
                                $spinnerIcon.replaceWith($existingIcon);
+
+                               SystemInformationMenu.initialize();
                        }
                })
        };
@@ -67,6 +82,31 @@ define('TYPO3/CMS/Backend/Toolbar/SystemInformationMenu', ['jquery'], function($
        };
 
        /**
+        * Updates the UC and opens the linked module
+        */
+       SystemInformationMenu.openModule = function(e) {
+               e.preventDefault();
+               e.stopPropagation();
+
+               var storedSystemInformationSettings = {},
+                       moduleStorageObject = {},
+                       requestedModule = $(e.currentTarget).data('modulename'),
+                       timestamp = Math.floor((new Date).getTime() / 1000);
+
+               if (TYPO3.Storage.Persistent.isset('systeminformation')) {
+                       storedSystemInformationSettings = JSON.parse(TYPO3.Storage.Persistent.get('systeminformation'));
+               }
+
+               moduleStorageObject[requestedModule] = {lastAccess: timestamp};
+               $.extend(true, storedSystemInformationSettings, moduleStorageObject);
+               TYPO3.Storage.Persistent.set('systeminformation', JSON.stringify(storedSystemInformationSettings)).done(function() {
+                       // finally, open the module now
+                       TYPO3.ModuleMenu.App.showModule(requestedModule);
+                       SystemInformationMenu.updateMenu();
+               });
+       };
+
+       /**
         * Initialize and return the SystemInformationMenu object
         */
        $(document).ready(function() {
index 3255d66..bb10785 100644 (file)
@@ -14,7 +14,10 @@ namespace TYPO3\CMS\Belog\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus;
+use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Belog\Domain\Model\Constraint;
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
 
 /**
  * Count newest exceptions for the system information menu
@@ -32,16 +35,26 @@ class SystemInformationController extends AbstractController {
                        $constraint = $this->objectManager->get(Constraint::class);
                }
 
+               $timestamp = $constraint->getStartTimestamp();
+               $backendUser = $this->getBackendUserAuthentication();
+               if (isset($backendUser->uc['systeminformation'])) {
+                       $systemInformationUc = json_decode($backendUser->uc['systeminformation'], TRUE);
+                       if (isset($systemInformationUc['system_BelogLog']['lastAccess'])) {
+                               $timestamp = $systemInformationUc['system_BelogLog']['lastAccess'];
+                       }
+               }
+
                $this->setStartAndEndTimeFromTimeSelector($constraint);
                // we can't use the extbase repository here as the required TypoScript may not be parsed yet
-               $count = $this->getDatabaseConnection()->exec_SELECTcountRows('error', 'sys_log', 'tstamp >= ' . $constraint->getStartTimestamp() . ' AND tstamp <= ' . $constraint->getEndTimestamp() . ' AND error IN(-1,1,2)');
+               $count = $this->getDatabaseConnection()->exec_SELECTcountRows('error', 'sys_log', 'tstamp >= ' . $timestamp . ' AND error IN(-1,1,2)');
 
                if ($count > 0) {
                        return array(
                                array(
+                                       'module' => 'system_BelogLog',
                                        'count' => $count,
-                                       'status' => \TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus::STATUS_ERROR,
-                                       'text' => sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('systemmessage.errorsInPeriod', 'belog'), $count)
+                                       'status' => InformationStatus::STATUS_ERROR,
+                                       'text' => sprintf(LocalizationUtility::translate('systemmessage.errorsInPeriod', 'belog'), $count, BackendUtility::getModuleUrl('system_BelogLog'))
                                )
                        );
                }
@@ -54,7 +67,7 @@ class SystemInformationController extends AbstractController {
         * @return \TYPO3\CMS\Belog\Domain\Model\Constraint|NULL
         */
        protected function getConstraintFromBeUserData() {
-               $serializedConstraint = $GLOBALS['BE_USER']->getModuleData(ToolsController::class);
+               $serializedConstraint = $this->getBackendUserAuthentication()->getModuleData(ToolsController::class);
                if (!is_string($serializedConstraint) || empty($serializedConstraint)) {
                        return NULL;
                }
@@ -62,6 +75,13 @@ class SystemInformationController extends AbstractController {
        }
 
        /**
+        * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
+        */
+       protected function getBackendUserAuthentication() {
+               return $GLOBALS['BE_USER'];
+       }
+
+       /**
         * @return \TYPO3\CMS\Core\Database\DatabaseConnection
         */
        protected function getDatabaseConnection() {
index b533287..67a6f7a 100644 (file)
                                <source>Time</source>
                        </trans-unit>
                        <trans-unit id="systemmessage.errorsInPeriod">
-                               <source>We have found %1$d errors. Please check your system log.</source>
+                               <source><![CDATA[We have found %1$d errors. Please check your <a href="%2$s">system log</a>.]]></source>
                        </trans-unit>
                </body>
        </file>