[TASK] Bypass fetch of database record if already loaded 03/52003/5
authorXavier Perseguers <xavier@typo3.org>
Thu, 2 Mar 2017 14:51:38 +0000 (15:51 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 13 Mar 2017 12:38:06 +0000 (13:38 +0100)
Change-Id: I737f76e497ef4a9c2ce1439cfe09b0b1e75afd73
Resolves: #80100
Releases: master, 7.6
Reviewed-on: https://review.typo3.org/52003
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseEditRow.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseEditRowTest.php

index 4e5f918..a385bbf 100644 (file)
@@ -31,7 +31,7 @@ class DatabaseEditRow extends AbstractDatabaseRecordProvider implements FormData
      */
     public function addData(array $result)
     {
-        if ($result['command'] !== 'edit') {
+        if ($result['command'] !== 'edit' || !empty($result['databaseRow'])) {
             return $result;
         }
 
index b43f709..5d2f02f 100644 (file)
@@ -176,4 +176,28 @@ class DatabaseEditRowTest extends UnitTestCase
 
         $this->subject->addData($input);
     }
+
+    /**
+     * @test
+     */
+    public function addDataSkipsDatabaseLookupIfDatabaseRowIsPopulated()
+    {
+        $virtualRow = [
+            'uid' => 10,
+            'pid' => 123,
+            'title' => 'Title of the virtual record'
+        ];
+        $input = [
+            'tableName' => 'virtual_table',
+            'command' => 'edit',
+            'vanillaUid' => 10,
+            'databaseRow' => $virtualRow
+        ];
+        $resultRow = $virtualRow;
+        $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->shouldNotBeCalled();
+
+        $result = $this->subject->addData($input);
+
+        $this->assertSame($resultRow, $result['databaseRow']);
+    }
 }