[TASK] Remove BackendUserRepository injection in NoteController 66/54166/5
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 19 Sep 2017 10:06:54 +0000 (12:06 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Wed, 20 Sep 2017 10:14:12 +0000 (12:14 +0200)
To improve the performance of sys_note rendering, the injection can
be skipped as the current user id can be used directly.

Resolves: #82506
Releases: master
Change-Id: I40b04ac725628f4dcfb3f1e5a280edf9c8e545f9
Reviewed-on: https://review.typo3.org/54166
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-82506-RemoveBackendUserRepositoryInjectionInNoteController.rst [new file with mode: 0644]
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php
typo3/sysext/sys_note/Classes/Controller/NoteController.php
typo3/sysext/sys_note/Classes/Domain/Repository/SysNoteRepository.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-82506-RemoveBackendUserRepositoryInjectionInNoteController.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-82506-RemoveBackendUserRepositoryInjectionInNoteController.rst
new file mode 100644 (file)
index 0000000..bc91be4
--- /dev/null
@@ -0,0 +1,32 @@
+.. include:: ../../Includes.txt
+
+==============================================================================
+Deprecation: #82506 - Remove BackendUserRepository injection in NoteController
+==============================================================================
+
+See :issue:`82506`
+
+Description
+===========
+
+To improve the performance of showing sys_note records the injection of the :php:`BackendUserRepository` has been removed in :php:`\TYPO3\CMS\SysNote\Controller\NoteController`.
+
+
+Impact
+======
+
+The method :php:`\TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository::findByPidsAndAuthor` has been marked as deprecated.
+
+
+Affected Installations
+======================
+
+Any installation using third-party extension that use the method :php:`\TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository::findByPidsAndAuthor`.
+
+
+Migration
+=========
+
+Use the method :php:`\TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository::findByPidsAndAuthorId`. and use the user id as 2nd argument instead of a `BackendUser` object.
+
+.. index:: Backend, PHP-API, FullyScanned
index 25852d9..4a88de3 100644 (file)
@@ -1226,4 +1226,11 @@ return [
             'Breaking-82398-RemoveSpecialConstantTSConstantEditor.rst',
         ],
     ],
+    '\TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository->findByPidsAndAuthor' => [
+        'numberOfMandatoryArguments' => 2,
+        'maximumNumberOfArguments' => 2,
+        'restFiles' => [
+            'Deprecation-82506-RemoveBackendUserRepositoryInjectionInNoteController.rst',
+        ],
+    ],
 ];
index 5757136..5ff609a 100644 (file)
@@ -25,11 +25,6 @@ class NoteController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
     protected $sysNoteRepository;
 
     /**
-     * @var \TYPO3\CMS\Extbase\Domain\Repository\BackendUserRepository
-     */
-    protected $backendUserRepository;
-
-    /**
      * @param \TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository $sysNoteRepository
      */
     public function injectSysNoteRepository(\TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository $sysNoteRepository)
@@ -38,14 +33,6 @@ class NoteController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
     }
 
     /**
-     * @param \TYPO3\CMS\Extbase\Domain\Repository\BackendUserRepository $backendUserRepository
-     */
-    public function injectBackendUserRepository(\TYPO3\CMS\Extbase\Domain\Repository\BackendUserRepository $backendUserRepository)
-    {
-        $this->backendUserRepository = $backendUserRepository;
-    }
-
-    /**
      * Render notes by single PID or PID list
      *
      * @param string $pids Single PID or comma separated list of PIDs
@@ -57,8 +44,7 @@ class NoteController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
         if (empty($pids) || empty($GLOBALS['BE_USER']->user['uid'])) {
             return '';
         }
-        $author = $this->backendUserRepository->findByUid($GLOBALS['BE_USER']->user['uid']);
-        $notes = $this->sysNoteRepository->findByPidsAndAuthor($pids, $author);
+        $notes = $this->sysNoteRepository->findByPidsAndAuthorId($pids, $GLOBALS['BE_USER']->user['uid']);
         $this->view->assign('notes', $notes);
     }
 }
index 6f7f9a7..adac5e8 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\SysNote\Domain\Repository;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Sys_note repository
  */
@@ -35,10 +37,39 @@ class SysNoteRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
      * @param string $pids Single PID or comma separated list of PIDs
      * @param \TYPO3\CMS\Extbase\Domain\Model\BackendUser $author The author
      * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
+     * @deprecated since TYPO3 v9, will be removed in TYPO3 v10
      */
     public function findByPidsAndAuthor($pids, \TYPO3\CMS\Extbase\Domain\Model\BackendUser $author)
     {
-        $pids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', (string)$pids);
+        GeneralUtility::logDeprecatedFunction();
+        $pids = GeneralUtility::intExplode(',', (string)$pids);
+        $query = $this->createQuery();
+        $query->setOrderings([
+            'sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
+            'creationDate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
+        ]);
+        $query->matching(
+            $query->logicalAnd(
+                $query->in('pid', $pids),
+                $query->logicalOr(
+                    $query->equals('personal', 0),
+                    $query->equals('author', $author)
+                )
+            )
+        );
+        return $query->execute();
+    }
+
+    /**
+     * Find notes by given pids and author
+     *
+     * @param string $pids Single PID or comma separated list of PIDs
+     * @param int $author author uid
+     * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
+     */
+    public function findByPidsAndAuthorId($pids, int $author)
+    {
+        $pids = GeneralUtility::intExplode(',', (string)$pids);
         $query = $this->createQuery();
         $query->setOrderings([
             'sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,