/** * Deletes a set of records. * * If one of the records could not be deleted, no record is deleted * * @param array array of record identifiers * @return Tinebase_Record_RecordSet * @throws Tinebase_Exception_NotFound|Tinebase_Exception */ public function delete($_ids) { if ($_ids instanceof $this->_modelName) { $_ids = (array) $_ids->getId(); } $ids = $this->_inspectDelete((array) $_ids); $records = $this->_backend->getMultiple((array) $ids); if (count((array) $ids) != count($records)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Only ' . count($records) . ' of ' . count((array) $ids) . ' records exist.'); } try { $db = $this->_backend->getAdapter(); $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction($db); $this->_checkRight('delete'); foreach ($records as $record) { $this->_checkGrant($record, 'delete'); $this->_deleteRecord($record); } Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId); // send notifications if ($this->sendNotifications()) { foreach ($records as $record) { $this->doSendNotifications($record, $this->_currentAccount, 'deleted'); } } } catch (Exception $e) { Tinebase_TransactionManager::getInstance()->rollBack(); Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . print_r($e->getMessage(), true)); Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . print_r($e->getTraceAsString(), true)); throw $e; } // returns deleted records return $records; }
/** * Deletes a set of records. * * If one of the records could not be deleted, no record is deleted * * @param array|Tinebase_Record_Interface|Tinebase_Record_RecordSet $_ids array of record identifiers * @return Tinebase_Record_RecordSet * @throws Exception */ public function delete($_ids) { if ($_ids instanceof $this->_modelName || $_ids instanceof Tinebase_Record_RecordSet) { /** @var Tinebase_Record_Interface $_ids */ $_ids = (array) $_ids->getId(); } /** @var array $_ids */ $ids = $this->_inspectDelete((array) $_ids); $records = $this->_backend->getMultiple((array) $ids); if (count((array) $ids) != count($records)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Only ' . count($records) . ' of ' . count((array) $ids) . ' records exist.'); } if (empty($records)) { return $records; } if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Deleting ' . count($records) . ' of ' . $this->_modelName . ' records ...'); } try { $db = $this->_backend->getAdapter(); $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction($db); $this->_checkRight('delete'); foreach ($records as $record) { if ($this->sendNotifications()) { $this->_getRelatedData($record); } $this->_deleteRecord($record); } Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId); // send notifications if ($this->sendNotifications()) { foreach ($records as $record) { $this->doSendNotifications($record, Tinebase_Core::getUser(), 'deleted'); } } } catch (Exception $e) { Tinebase_TransactionManager::getInstance()->rollBack(); Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . print_r($e->getMessage(), true)); throw $e; } if ($this->_clearCustomFieldsCache) { Tinebase_Core::getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('customfields')); } // returns deleted records return $records; }
/** * returns quoted column name for sql backend * * @param Tinebase_Backend_Sql_Interface $_backend * @return string * * @todo to be removed once we split filter model / backend */ protected function _getQuotedFieldName($_backend) { $tablename = isset($this->_options['tablename']) ? $this->_options['tablename'] : $_backend->getTableName(); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . 'Using tablename: ' . $tablename); } return $_backend->getAdapter()->quoteIdentifier($tablename . '.' . $this->_field); }
/** * returns quoted column name for sql backend * * @param Tinebase_Backend_Sql_Interface $_backend * @return string * * @todo to be removed once we split filter model / backend */ protected function _getQuotedFieldName($_backend) { return $_backend->getAdapter()->quoteIdentifier('attendee.status'); }