[CLEANUP] Cleanup EXT:rsaauth 12/33712/5
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Sun, 2 Nov 2014 13:30:47 +0000 (14:30 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 3 Nov 2014 15:46:56 +0000 (16:46 +0100)
EXT:rsaauth has several minor flaws codewise that make
PHPStorms inspection go wild:
* Clean up direct usage of $GLOBALS[TYPO3_DB].
* TCA of tx_rsaauth_keys is not needed and can be removed, as a
result, "Oops! You should not see this" no longer shows
up in db_lowlevel.

Resolves: #62623
Releases: master
Change-Id: I865a9bd3f3f0ff681ba0838a8cbb3a14b885e44f
Reviewed-on: http://review.typo3.org/33712
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Stefan Froemken <froemken@gmail.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
typo3/sysext/rsaauth/Classes/Storage/SplitStorage.php
typo3/sysext/rsaauth/Configuration/TCA/tx_rsaauth_keys.php [deleted file]

index 6854571..aeb2310 100644 (file)
@@ -13,22 +13,34 @@ namespace TYPO3\CMS\Rsaauth\Storage;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
+use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Utility;
+
 /**
  * This class contains a "split" storage for the data. It keeps part of the data
- * in the database, part in the database.
+ * in the database, part in the session.
  *
  * @author Dmitry Dulepov <dmitry@typo3.org>
  */
-class SplitStorage extends \TYPO3\CMS\Rsaauth\Storage\AbstractStorage {
+class SplitStorage extends AbstractStorage {
+
+       /**
+        * @var DatabaseConnection;
+        */
+       protected $databaseConnection;
 
        /**
         * Creates an instance of this class. It checks and initializes PHP
         * sessions if necessary.
+        *
+        * @param DatabaseConnection $databaseConnection A database connection may be injected here
         */
-       public function __construct() {
+       public function __construct(DatabaseConnection $databaseConnection = NULL) {
                if (session_id() === '') {
                        session_start();
                }
+               $this->databaseConnection = $databaseConnection ?: $GLOBALS['TYPO3_DB'];
        }
 
        /**
@@ -40,11 +52,11 @@ class SplitStorage extends \TYPO3\CMS\Rsaauth\Storage\AbstractStorage {
        public function get() {
                $result = NULL;
                list($keyId, $keyPart1) = $_SESSION['tx_rsaauth_key'];
-               if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($keyId)) {
+               if (Utility\MathUtility::canBeInterpretedAsInteger($keyId)) {
                        // Remove expired keys (more than 30 minutes old)
-                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_rsaauth_keys', 'crdate<' . ($GLOBALS['EXEC_TIME'] - 30 * 60));
+                       $this->databaseConnection->exec_DELETEquery('tx_rsaauth_keys', 'crdate<' . ($GLOBALS['EXEC_TIME'] - 30 * 60));
                        // Get our value
-                       $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('key_value', 'tx_rsaauth_keys', 'uid=' . $keyId);
+                       $row = $this->databaseConnection->exec_SELECTgetSingleRow('key_value', 'tx_rsaauth_keys', 'uid=' . $keyId);
                        if (is_array($row)) {
                                $result = $keyPart1 . $row['key_value'];
                        }
@@ -63,8 +75,8 @@ class SplitStorage extends \TYPO3\CMS\Rsaauth\Storage\AbstractStorage {
                if ($key == NULL) {
                        // Remove existing key
                        list($keyId) = $_SESSION['tx_rsaauth_key'];
-                       if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($keyId)) {
-                               $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_rsaauth_keys', 'uid=' . $keyId);
+                       if (Utility\MathUtility::canBeInterpretedAsInteger($keyId)) {
+                               $this->databaseConnection->exec_DELETEquery('tx_rsaauth_keys', 'uid=' . $keyId);
                                unset($_SESSION['tx_rsaauth_key']);
                        }
                } else {
@@ -81,17 +93,17 @@ class SplitStorage extends \TYPO3\CMS\Rsaauth\Storage\AbstractStorage {
                        // Notice: we may not use TCEmain below to insert key part into the
                        // table because TCEmain requires a valid BE user!
                        $time = $GLOBALS['EXEC_TIME'];
-                       $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_rsaauth_keys', array(
+                       $this->databaseConnection->exec_INSERTquery('tx_rsaauth_keys', array(
                                'pid' => 0,
                                'crdate' => $time,
                                'key_value' => $keyPart2
                        ));
-                       $keyId = $GLOBALS['TYPO3_DB']->sql_insert_id();
+                       $keyId = $this->databaseConnection->sql_insert_id();
                        // Store another part in session
                        $_SESSION['tx_rsaauth_key'] = array($keyId, $keyPart1);
                }
                // Remove expired keys (more than 30 minutes old)
-               $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_rsaauth_keys', 'crdate<' . ($GLOBALS['EXEC_TIME'] - 30 * 60));
+               $this->databaseConnection->exec_DELETEquery('tx_rsaauth_keys', 'crdate<' . ($GLOBALS['EXEC_TIME'] - 30 * 60));
        }
 
 }
diff --git a/typo3/sysext/rsaauth/Configuration/TCA/tx_rsaauth_keys.php b/typo3/sysext/rsaauth/Configuration/TCA/tx_rsaauth_keys.php
deleted file mode 100644 (file)
index 8bd4988..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-return array(
-       'ctrl' => array(
-               'adminOnly' => TRUE,
-               'hideTable' => TRUE,
-               'is_static' => TRUE,
-               'label' => 'uid',
-               'readOnly' => TRUE,
-               'rootLevel' => 1,
-               'title' => 'Oops! You should not see this!'
-       ),
-       'columns' => array(),
-       'types' => array(
-               '0' => array(
-                       'showitem' => ''
-               ),
-       ),
-);