0010074: IDs of new created dependent records failure
authorAlexander Stintzing <a.stintzing@metaways.de>
Mon, 21 Jul 2014 12:47:03 +0000 (14:47 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 22 Jul 2014 12:00:11 +0000 (14:00 +0200)
When creating dependent records (add some free days to a vacation),
and the parent record is new, the ids of he dependent records will
have the js-timestamp, not a regular id.

https://forge.tine20.org/mantisbt/view.php?id=10074

Change-Id: Ia23cf5240d46cd01bac2f323f8317fdccd3b75b3
Reviewed-on: http://gerrit.tine20.com/customers/885
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/HumanResources/JsonTests.php
tine20/Tinebase/Controller/Record/Abstract.php

index f040ed9..ac1482f 100644 (file)
@@ -292,7 +292,8 @@ class HumanResources_JsonTests extends HumanResources_TestCase
             'end_date'   => clone $edate,
             'vacation_days' => 23,
             'feast_calendar_id' => $fcId,
-            'creation_time' => $now
+            'creation_time' => $now,
+            'id' => 1234567891
         ));
         
         $sdate->addMonth(1);
@@ -303,7 +304,8 @@ class HumanResources_JsonTests extends HumanResources_TestCase
             'end_date'   => clone $edate,
             'vacation_days' => 27,
             'feast_calendar_id' => $fcId,
-            'creation_time' => $now
+            'creation_time' => $now,
+            'id' => 1234567890
         );
         
         $employee = $this->_getEmployee('unittest')->toArray();
@@ -312,6 +314,10 @@ class HumanResources_JsonTests extends HumanResources_TestCase
         $employee = $this->_json->saveEmployee($employee);
         $this->assertEquals(2, count($employee['contracts']));
         
+        // get sure the ids are generated properly
+        $this->assertEquals(40, strlen($employee['contracts'][1]['id']));
+        $this->assertEquals(40, strlen($employee['contracts'][0]['id']));
+        
         $this->_removeAllEmployees();
         
         // remove ids
index 42c747a..d634df0 100644 (file)
@@ -1767,9 +1767,20 @@ abstract class Tinebase_Controller_Record_Abstract
                 foreach ($_record->{$_property} as $recordArray) {
                     $rec = new $recordClassName(array(),true);
                     $rec->setFromJsonInUsersTimezone($recordArray);
+                    
+                    if (strlen($rec->getId()) < 40) {
+                        $rec->{$rec->getIdProperty()} = Tinebase_Record_Abstract::generateUID();
+                    }
+                    
                     $rs->addRecord($rec);
                 }
                 $_record->{$_property} = $rs;
+            } else {
+                foreach ($_record->{$_property} as $rec) {
+                    if (strlen($rec->getId()) < 40) {
+                        $rec->{$rec->getIdProperty()} = Tinebase_Record_Abstract::generateUID();
+                    }
+                }
             }
             // legacy end
 
@@ -1848,7 +1859,7 @@ abstract class Tinebase_Controller_Record_Abstract
                         }
                         // create if ID does not exist or has not a length of 40
                     } else {
-                        $record->id = NULL;
+                        $record->{$record->getIdProperty()} = NULL;
                         $crc = $controller->create($record);
                         $existing->addRecord($crc);
                         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {