/**
  * @see: https://forge.tine20.org/mantisbt/view.php?id=10176
  */
 public function testSavingRelatedRecordWithCorruptId()
 {
     $date = new Tinebase_DateTime();
     $e = $this->_getEmployee();
     $c = $this->_getContract($date);
     $c->id = '1234567890';
     $employeeJson = $e->toArray();
     $employeeJson = $this->_json->saveEmployee($employeeJson);
     $c->employee_id = $employeeJson['id'];
     $c = HumanResources_Controller_Contract::getInstance()->create($c);
     $this->assertEquals('1234567890', $c->getId());
     $employeeJson['contracts'] = array($c->toArray());
     $employeeJson = $this->_json->saveEmployee($employeeJson);
     // if it has been corrupted before this change was committed, the corrupted id should stay
     $this->assertEquals('1234567890', $employeeJson['contracts'][0]['id']);
 }
 /**
  * update employee
  * 
  * @param Zend_Console_Getopt $opts
  * @param HumanResources_Model_Employee $employee
  * @param HumanResources_Model_Employee $currentEmployee
  * @return HumanResources_Model_Employee
  */
 protected function _updateImportedEmployee($opts, $employee, $currentEmployee)
 {
     if ($opts->v) {
         echo "Updating employee " . $employee->n_fn . ".\n";
     }
     // update only some fields
     $fieldsToUpdate = array('postalcode', 'locality', 'street', 'bday', 'employment_begin', 'employment_end', 'bank_account_number', 'bank_name', 'bank_code_number', 'health_insurance', 'number', 'contracts');
     $changed = FALSE;
     foreach ($fieldsToUpdate as $field) {
         if (!empty($employee->{$field}) && $currentEmployee->{$field} !== $employee->{$field}) {
             if ($field === 'contracts' && !empty($currentEmployee->{$field})) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($currentEmployee->toArray(), TRUE));
                 }
             } else {
                 $currentEmployee->{$field} = $employee->{$field};
             }
             $changed = TRUE;
         }
     }
     if ($opts->d || !$changed) {
         $result = $currentEmployee;
     } else {
         $json = new HumanResources_Frontend_Json();
         $result = $json->saveEmployee($currentEmployee->toArray());
         if ($currentEmployee->contracts) {
             $rs = new Tinebase_Record_RecordSet('HumanResources_Model_Contract');
             foreach ($currentEmployee->contracts as $contract) {
                 $rs->addRecord(new HumanResources_Model_Contract($contract));
             }
             $currentEmployee->contracts = $rs;
         }
         if ($currentEmployee->costcenters) {
             $ccrs = new Tinebase_Record_RecordSet('HumanResources_Model_CostCenter');
             foreach ($currentEmployee->costcenters as $costcenter) {
                 $ccrs->addRecord(new HumanResources_Model_CostCenter($costcenter));
             }
             $currentEmployee->costcenters = $ccrs;
         }
         $result = HumanResources_Controller_Employee::getInstance()->update($currentEmployee);
     }
     return $result;
 }