/** * do duplicate check (before create) * * @param Tinebase_Record_Interface $_record * @return void * @throws Tinebase_Exception_Duplicate */ protected function _duplicateCheck(Tinebase_Record_Interface $_record) { $duplicateFilter = $this->_getDuplicateFilter($_record); if ($duplicateFilter === NULL) { return; } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Doing duplicate check.'); } $duplicates = $this->search($duplicateFilter, new Tinebase_Model_Pagination(array('limit' => 5)), true); if (count($duplicates) > 0) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Found ' . count($duplicates) . ' duplicate(s).'); } $ted = new Tinebase_Exception_Duplicate('Duplicate record(s) found'); $ted->setModelName($this->_modelName); $ted->setData($duplicates); $ted->setClientRecord($_record); throw $ted; } else { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' No duplicates found.'); } } }
/** * Checks if number is unique if manual generated * * @param Tinebase_Record_Interface $record * @param Boolean $update true if called un update * @throws Tinebase_Exception_Duplicate * @return boolean */ protected function _checkNumberUniquity($record, $update = FALSE) { $filterArray = array(array('field' => 'number', 'operator' => 'equals', 'value' => $record->{$this->_numberProperty})); if ($update) { $filterArray[] = array('field' => 'id', 'operator' => 'notin', 'value' => $record->getId()); } $filterName = $this->_modelName . 'Filter'; $filter = new $filterName($filterArray); $existing = $this->search($filter); if (count($existing->toArray()) > 0) { $e = new Tinebase_Exception_Duplicate(_('The number you have tried to set is already in use!')); $e->setData($existing); $e->setClientRecord($record); throw $e; } return true; }