0012202: saving timesheet results in segfault
authorPaul Mehrer <p.mehrer@metaways.de>
Mon, 12 Sep 2016 08:33:48 +0000 (10:33 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 12 Sep 2016 12:04:57 +0000 (14:04 +0200)
Tinebase_Convert_Json - fix record field resolving

fields of type record only need to be resolved to
a record if they are not yet resolved obviously

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

Change-Id: I4449b7b9e81866b00c13659b79a4e5fdf20f6b9d
Reviewed-on: http://gerrit.tine20.com/customers/3560
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Convert/Json.php

index a3caece..488e4f9 100644 (file)
@@ -82,22 +82,27 @@ class Tinebase_Convert_Json implements Tinebase_Convert_Interface
             
             foreach ($resolveRecords as $foreignRecordClassName => $fields) {
                 $foreignIds = array();
             
             foreach ($resolveRecords as $foreignRecordClassName => $fields) {
                 $foreignIds = array();
+                $foreignRecordsArray = array();
                 $fields = (array) $fields;
                 foreach ($fields as $field) {
                     $idsForField = $_records->{$field};
                     foreach ($idsForField as $key => $value) {
                 $fields = (array) $fields;
                 foreach ($fields as $field) {
                     $idsForField = $_records->{$field};
                     foreach ($idsForField as $key => $value) {
-                        if ($value && ! in_array($value, $foreignIds)) {
-                            $foreignIds[] = $value;
+                        if ($value instanceof Tinebase_Record_Abstract) {
+                            $foreignRecordsArray[$value->getId()] = $value;
+                        } else {
+                            if ($value && !isset($foreignRecordsArray[$value])) {
+                                $foreignIds[$value] = $value;
+                            }
                         }
                     }
                 }
                 
                         }
                     }
                 }
                 
-                if (empty($foreignIds)) {
+                if (empty($foreignIds) && empty($foreignRecordsArray)) {
                     continue;
                 }
                 
                 $cfg = $resolveFields[$fields[0]];
                     continue;
                 }
                 
                 $cfg = $resolveFields[$fields[0]];
-                
+
                 if ($cfg['type'] == 'user') {
                     $foreignRecords = Tinebase_User::getInstance()->getMultiple($foreignIds);
                 } else if ($cfg['type'] == 'container') {
                 if ($cfg['type'] == 'user') {
                     $foreignRecords = Tinebase_User::getInstance()->getMultiple($foreignIds);
                 } else if ($cfg['type'] == 'container') {
@@ -106,8 +111,9 @@ class Tinebase_Convert_Json implements Tinebase_Convert_Interface
                     if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__
                         . ' No handling for container foreign records implemented');
 
                     if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__
                         . ' No handling for container foreign records implemented');
 
-                    $foreignRecords = new Tinebase_Record_RecordSet('Tinebase_Model_Container');
+                    //$foreignRecords = new Tinebase_Record_RecordSet('Tinebase_Model_Container');
                     // $foreignRecords->addRecord(Tinebase_Container::getInstance()->get(XXX));
                     // $foreignRecords->addRecord(Tinebase_Container::getInstance()->get(XXX));
+                    continue;
                 } else {
                     try {
                         $controller = Tinebase_Core::getApplicationInstance($foreignRecordClassName);
                 } else {
                     try {
                         $controller = Tinebase_Core::getApplicationInstance($foreignRecordClassName);
@@ -118,6 +124,12 @@ class Tinebase_Convert_Json implements Tinebase_Convert_Interface
                         continue;
                     }
                 }
                         continue;
                     }
                 }
+
+                foreach($foreignRecordsArray as $id => $rec) {
+                    if ($foreignRecords->getById($id) === false) {
+                        $foreignRecords->addRecord($rec);
+                    }
+                }
                 
                 if ($foreignRecords->count() === 0) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
                 
                 if ($foreignRecords->count() === 0) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__