[+BUGFIX] extbase (Persistence): Added the missing pid property to the AbstractDomain...
authorJochen Rau <j.rau@web.de>
Tue, 18 Jan 2011 14:52:18 +0000 (14:52 +0000)
committerJochen Rau <j.rau@web.de>
Tue, 18 Jan 2011 14:52:18 +0000 (14:52 +0000)
* The pid property is a "special" property as the uid property.
* If your table does not contain a pid field, the property value will be NULL.
* There are now getPid() and setPid() methods available in the AbstractDomainObject.
* The support for workspaces ist still missing. You can't move objects from one page top another within a workspace view.

Related to #11361.

typo3/sysext/extbase/Classes/DomainObject/AbstractDomainObject.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php
typo3/sysext/extbase/Tests/Unit/DomainObject/AbstractEntityTest.php
typo3/sysext/extbase/Tests/Unit/MVC/Web/Routing/UriBuilderTest.php

index 09601f8..abf4a72 100644 (file)
@@ -34,7 +34,7 @@
 abstract class Tx_Extbase_DomainObject_AbstractDomainObject implements Tx_Extbase_DomainObject_DomainObjectInterface, Tx_Extbase_Persistence_ObjectMonitoringInterface {
 
        /**
-        * @var int The uid
+        * @var int The uid of the record. The uid is only unique in the context of the database table.
         */
        protected $uid;
 
@@ -49,6 +49,11 @@ abstract class Tx_Extbase_DomainObject_AbstractDomainObject implements Tx_Extbas
        protected $_languageUid;
 
        /**
+        * @var int The id of the page the record is "stored".
+        */
+       protected $pid;
+
+       /**
         * TRUE if the object is a clone
         * @var boolean
         */
@@ -80,6 +85,32 @@ abstract class Tx_Extbase_DomainObject_AbstractDomainObject implements Tx_Extbas
                        return NULL;
                }
        }
+
+       /**
+        * Setter for the pid.
+        *
+        * @return void
+        */
+       final public function setPid($pid) {
+               if ($pid === NULL) {
+                       $this->pid = NULL;
+               } else {
+                       $this->pid = (int)$pid;
+               }
+       }
+
+       /**
+        * Getter for the pid.
+        *
+        * @return int The pid or NULL if none set yet.
+        */
+       final public function getPid() {
+               if ($this->pid === NULL) {
+                       return NULL;
+               } else {
+                       return (int)$this->pid;
+               }
+       }
        
        /**
         * Reconstitutes a property. Only for internal use.
index a481784..24ebc91 100644 (file)
@@ -236,6 +236,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                $className = get_class($object);
                $dataMap = $this->getDataMap($className);
                $object->_setProperty('uid', intval($row['uid']));
+               $object->_setProperty('pid', intval($row['pid']));
                $object->_setProperty('_localizedUid', intval($row['uid']));
                if ($dataMap->getLanguageIdColumnName() !== NULL) {
                        $object->_setProperty('_languageUid', intval($row[$dataMap->getLanguageIdColumnName()]));
index 5156201..ef03984 100644 (file)
@@ -27,6 +27,49 @@ class Tx_Extbase_Tests_Unit_DomainObject_AbstractEntityTest extends Tx_Extbase_T
        /**
         * @test
         */
+       public function theObjectReturnsItsCorrectUid() {
+               $domainObjectName = uniqid('DomainObject_');
+               eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {}');
+               $domainObject = new $domainObjectName();
+               $domainObject->_setProperty('uid', 42);
+               $this->assertEquals($domainObject->getUid(), 42);
+       }
+
+       /**
+        * @test
+        */
+       public function theObjectReturnsItsCorrectUidIfTheUidIsNull() {
+               $domainObjectName = uniqid('DomainObject_');
+               eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {}');
+               $domainObject = new $domainObjectName();
+               $this->assertNull($domainObject->getUid());
+       }
+
+       /**
+        * @test
+        */
+       public function theObjectReturnsItsCorrectPid() {
+               $domainObjectName = uniqid('DomainObject_');
+               eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {}');
+               $domainObject = new $domainObjectName();
+               $domainObject->setPid(42);
+               $this->assertEquals($domainObject->getPid(), 42);
+       }
+
+       /**
+        * @test
+        */
+       public function theObjectReturnsItsCorrectPidIfThePidIsNull() {
+               $domainObjectName = uniqid('DomainObject_');
+               eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {}');
+               $domainObject = new $domainObjectName();
+               $this->assertNull($domainObject->getPid());
+       }
+
+
+       /**
+        * @test
+        */
        public function objectIsNotDirtyAfterCallingMemorizeCleanStateWithSimpleProperties() {
                $domainObjectName = uniqid('DomainObject_');
                eval('class ' . $domainObjectName . ' extends Tx_Extbase_DomainObject_AbstractEntity {
index 50de815..c65ce5a 100644 (file)
@@ -543,7 +543,7 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
                $mockUriBuilder = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_MVC_Web_Routing_UriBuilder'), array('dummy'));
                $actualResult = $mockUriBuilder->_call('convertTransientObjectToArray', $mockValueObject);
 
-               $expectedResult = array('name' => 'foo', 'uid' => NULL);
+               $expectedResult = array('name' => 'foo', 'uid' => NULL, 'pid' => NULL);
                $this->assertEquals($expectedResult, $actualResult);
        }
 
@@ -573,8 +573,12 @@ class Tx_Extbase_Tests_Unit_MVC_Web_Routing_UriBuilderTest extends Tx_Extbase_Te
                $expectedResult = array(
                        'object' => array(
                                'object' => 99,
-                               'uid' => NULL),
-                       'uid' => NULL);
+                               'uid' => NULL,
+                               'pid' => NULL
+                               ),
+                       'uid' => NULL,
+                       'pid' => NULL
+                       );
                $this->assertEquals($expectedResult, $actualResult);
        }