/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @access protected */ protected function tearDown() { $db = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'relations')); foreach ($this->relations as $relation) { $db->delete(array($db->getAdapter()->quoteInto('rel_id = ?', $relation->getId()))); } }
/** * delete groups * * @param mixed $_groupId * @throws Tinebase_Exception_Backend */ public function deleteGroups($_groupId) { $groupIds = array(); if (is_array($_groupId) or $_groupId instanceof Tinebase_Record_RecordSet) { foreach ($_groupId as $groupId) { $groupIds[] = Tinebase_Model_Group::convertGroupIdToInt($groupId); } } else { $groupIds[] = Tinebase_Model_Group::convertGroupIdToInt($_groupId); } try { $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb()); $where = $this->_db->quoteInto($this->_db->quoteIdentifier('group_id') . ' IN (?)', $groupIds); $this->groupMembersTable->delete($where); $where = $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' IN (?)', $groupIds); $this->groupsTable->delete($where); if ($this instanceof Tinebase_Group_Interface_SyncAble) { $this->deleteGroupsInSyncBackend($groupIds); } Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId); } catch (Exception $e) { Tinebase_TransactionManager::getInstance()->rollBack(); throw new Tinebase_Exception_Backend($e->getMessage()); } }
/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @access protected */ protected function tearDown() { $db = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'record_persistentobserver')); foreach ($this->persistentObserver as $persistentObserver) { $db->delete(array('identifier' => $persistentObserver->getId())); } }
/** * delete groups in sql backend * * @param array $groupIds */ public function deleteGroupsInSqlBackend($groupIds) { $where = $this->_db->quoteInto($this->_db->quoteIdentifier('group_id') . ' IN (?)', (array) $groupIds); $this->groupMembersTable->delete($where); $where = $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' IN (?)', (array) $groupIds); $this->groupsTable->delete($where); }
/** * purges(removes from table) all relations * * @param string $_ownModel * @param string $_ownBackend * @param string $_ownId * @return void * * @todo should this function only purge deleted/broken relations? */ public function purgeAllRelations($_ownModel, $_ownBackend, $_ownId) { $relationIds = $this->getAllRelations($_ownModel, $_ownBackend, $_ownId, NULL, array(), true)->getArrayOfIds(); if (!empty($relationIds)) { $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('rel_id') . ' IN (?)', $relationIds)); $this->_dbTable->delete($where); } }
public function testCreateMinimalTask() { $summary = 'minimal task by phpunit'; $task = new Tasks_Model_Task(array('summary' => $summary, 'container_id' => $this->container_id)); $persitantTask = $this->_backend->create($task); $pagination = new Tasks_Model_Pagination(); $filter = new Tasks_Model_TaskFilter(array(array('field' => 'summary', 'operator' => 'contains', 'value' => $summary), array('field' => 'container_id', 'operator' => 'equals', 'value' => $task->container_id))); $tasks = $this->_backend->search($filter, $pagination); $this->assertEquals(1, count($tasks)); $db = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'tasks')); $db->delete("summary LIKE '{$summary}'"); Tinebase_Timemachine_ModificationLogTest::purgeLogs($persitantTask->getId()); }
/** * set role rights * * @param int $_roleId * @param array $_roleRights with role rights ("application_id" => app id, "right" => the right to set) * @throws Tinebase_Exception_InvalidArgument */ public function setRoleRights($_roleId, array $_roleRights) { $roleId = (int) $_roleId; if ($roleId != $_roleId && $roleId > 0) { throw new Tinebase_Exception_InvalidArgument('$_roleId must be integer and greater than 0'); } // remove old rights $where = $this->_db->quoteInto($this->_db->quoteIdentifier('role_id') . ' = ?', $roleId); $this->_roleRightsTable->delete($where); foreach ($_roleRights as $right) { $data = array('role_id' => $roleId, 'application_id' => $right['application_id'], 'right' => $right['right']); $this->_roleRightsTable->insert($data); } // invalidate cache Tinebase_Core::get(Tinebase_Core::CACHE)->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('rights')); }
/** * purges mod log entries of given recordIds * * @param mixed [string|array|Tinebase_Record_RecordSet] $_recordIds * * @todo should be removed when other tests do not need this anymore */ public static function purgeLogs($_recordIds) { $table = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'timemachine_modlog')); foreach ((array) $_recordIds as $recordId) { $table->delete($table->getAdapter()->quoteInto('record_id = ?', $recordId)); } }
/** * delete registration by username * * @param string $_username * @return int number of rows affected */ public function deleteRegistrationByLoginName($_username) { $where = $this->_db->quoteInto($this->_db->quoteIdentifier('login_name') . ' = ?', $_username); $result = $this->_registrationsTable->delete($where); return $result; }
/** * delete a user * * @param mixed $_userId * @return Tinebase_Model_FullUser the delete user */ public function deleteUserInSqlBackend($_userId) { if ($_userId instanceof Tinebase_Model_FullUser) { $user = $_userId; } else { $user = $this->getFullUserById($_userId); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Deleting user' . $user->accountLoginName); } $event = new Tinebase_Event_User_DeleteAccount(Tinebase_Config::getInstance()->get(Tinebase_Config::ACCOUNT_DELETION_EVENTCONFIGURATION, new Tinebase_Config_Struct())->toArray()); $event->account = $user; Tinebase_Event::fireEvent($event); $accountsTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts')); $groupMembersTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'group_members')); $roleMembersTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'role_accounts')); try { $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction($this->_db); $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('account_id') . ' = ?', $user->getId())); $groupMembersTable->delete($where); $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('account_id') . ' = ?', $user->getId()), $this->_db->quoteInto($this->_db->quoteIdentifier('account_type') . ' = ?', Tinebase_Acl_Rights::ACCOUNT_TYPE_USER)); $roleMembersTable->delete($where); $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $user->getId())); $accountsTable->delete($where); Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId); } catch (Exception $e) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' error while deleting account ' . $e->__toString()); } Tinebase_TransactionManager::getInstance()->rollBack(); throw $e; } return $user; }
/** * delete note type * * @param integer $_noteTypeId */ public function deleteNoteType($_noteTypeId) { $this->_noteTypesTable->delete($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $_noteTypeId)); }