/** * import single record * * @param Tinebase_Record_Abstract $_record * @param string $_resolveStrategy * @param array $_recordData not needed here but in other import classes (i.a. Admin_Import_Csv) * @return Tinebase_Record_Abstract the imported record * @throws Tinebase_Exception_Record_Validation */ protected function _importRecord($_record, $_resolveStrategy = NULL, $_recordData = array()) { $_record->isValid(TRUE); if ($this->_options['dryrun']) { Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb()); } $this->_handleTags($_record, $_resolveStrategy); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Record to import: ' . print_r($_record->toArray(), true)); } $importedRecord = $this->_importAndResolveConflict($_record, $_resolveStrategy); $this->_importResult['results']->addRecord($importedRecord); if ($this->_options['dryrun']) { Tinebase_TransactionManager::getInstance()->rollBack(); } else { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Successfully imported record with id ' . $importedRecord->getId()); } } $this->_importResult['totalcount']++; return $importedRecord; }
/** * validate and filter the the internal data * * @param $_throwExceptionOnInvalidData * @return bool * @throws Tinebase_Exception_Record_Validation */ public function isValid($_throwExceptionOnInvalidData = false) { $isValid = parent::isValid($_throwExceptionOnInvalidData); if (isset($this->_properties['count']) && isset($this->_properties['until'])) { $isValid = $this->_isValidated = false; if ($_throwExceptionOnInvalidData) { $e = new Tinebase_Exception_Record_Validation('count and until can not be set both'); Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . $e); throw $e; } } return $isValid; }
/** * additional validation * * @param $_throwExceptionOnInvalidData * @return bool * @throws Tinebase_Exception_Record_Validation * @see Tinebase_Record_Abstract::isValid() */ function isValid($_throwExceptionOnInvalidData = false) { if (!$this->__get('org_name') && !$this->__get('n_family')) { array_push($this->_validationErrors, array('id' => 'org_name', 'msg' => 'either "org_name" or "n_family" must be given!')); array_push($this->_validationErrors, array('id' => 'n_family', 'msg' => 'either "org_name" or "n_family" must be given!')); $valid = false; } else { $valid = true; } $parentException = false; $parentValid = false; try { $parentValid = parent::isValid($_throwExceptionOnInvalidData); } catch (Tinebase_Exception_Record_Validation $e) { $parentException = $e; } if ($_throwExceptionOnInvalidData && (!$valid || !$parentValid)) { if (!$valid) { $message = 'either "org_name" or "n_family" must be given!'; } if ($parentException) { $message .= ', ' . $parentException->getMessage(); } $e = new Tinebase_Exception_Record_Validation($message); if (!$valid) { Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ":\n" . print_r($this->_validationErrors, true) . $e); } throw $e; } return $parentValid && $valid; }