/**
  * 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($db->getAdapter()->quoteIdentifier('rel_id') . ' = ?', $relation->getId())));
     }
 }
 /**
  * remove stuff from db
  *
  */
 public function tearDown()
 {
     // NOTE: cascading delete of dependend stuff due to sql schema
     $db = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'tasks'));
     $db->delete($db->getAdapter()->quoteInto($db->getAdapter()->quoteIdentifier('id') . ' = ?', $this->_persistantTestTask1->getId()));
     Tinebase_Timemachine_ModificationLogTest::purgeLogs($this->_persistantTestTask1->getId());
 }
Esempio n. 3
0
 /**
  * returns all observers of a given observable and event
  * 
  * @param Tinebase_Record_Interface $_observable 
  * @param string _event 
  * @return Tinebase_Record_RecordSet
  */
 protected function getObserversByEvent($_observable, $_event)
 {
     if (!$_observer->getApplication() || !$_observer->getId()) {
         throw new Tinebase_Exception_Record_DefinitionFailure();
     }
     $where = array($this->_db->quoteIdentifier('observable_application') . ' =' . $_observable->getApplication(), $this->_db->quoteIdentifier('observable_identifier') . '  =' . $_observable->getId(), $this->_db->quoteIdentifier('observed_event') . '         =' . $this->_db->getAdapter()->quote($_event));
     return new Tinebase_Record_RecordSet('Tinebase_Model_PersistentObserver', $this->_db->fetchAll($where), true);
 }
Esempio n. 4
0
 /**
  * return all groups an account is member of
  *
  * @param mixed $_accountId the account as integer or Tinebase_Model_User
  * @return array
  */
 public function getGroupMemberships($_accountId)
 {
     $accountId = Tinebase_Model_User::convertUserIdToInt($_accountId);
     $cacheId = convertCacheId('groupMemberships' . $accountId);
     $memberships = Tinebase_Core::getCache()->load($cacheId);
     if (!$memberships) {
         $memberships = array();
         $colName = $this->groupsTable->getAdapter()->quoteIdentifier('account_id');
         $select = $this->groupMembersTable->select();
         $select->where($colName . ' = ?', $accountId);
         $rows = $this->groupMembersTable->fetchAll($select);
         foreach ($rows as $membership) {
             $memberships[] = $membership->group_id;
         }
         Tinebase_Core::getCache()->save($memberships, $cacheId);
     }
     return $memberships;
 }
Esempio n. 5
0
 /**
  * Returns a single logbook entry identified by an logbook identifier
  * 
  * @param   string _id
  * @return  Tinebase_Model_ModificationLog
  * @throws  Tinebase_Exception_NotFound
  */
 public function getModification($_id)
 {
     $db = $this->_table->getAdapter();
     $stmt = $db->query($db->select()->from($this->_tablename)->where($this->_table->getAdapter()->quoteInto($db->quoteIdentifier('id') . ' = ?', $_id)));
     $RawLogEntry = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
     if (empty($RawLogEntry)) {
         throw new Tinebase_Exception_NotFound("Modification Log with id: {$_id} not found!");
     }
     return new Tinebase_Model_ModificationLog($RawLogEntry[0], true);
 }
Esempio n. 6
0
 /**
  * update registration
  *
  * @param   Tinebase_Model_Registration $_registration
  * @return  Tinebase_Model_Registration the updated registration object
  * 
  */
 public function updateRegistration(Tinebase_Model_Registration $_registration)
 {
     if (!$_registration->isValid()) {
         throw new Exception('invalid registration object');
     }
     $registrationData = array("login_name" => $_registration->login_name, "login_hash" => $_registration->login_hash, "email" => $_registration->email, "date" => $_registration->date instanceof DateTime ? $_registration->date->get(Tinebase_Record_Abstract::ISO8601LONG) : NULL, "status" => $_registration->status, "email_sent" => $_registration->email_sent);
     //--
     $where = array($this->_registrationsTable->getAdapter()->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $_registration->id));
     $result = $this->_registrationsTable->update($registrationData, $where);
     return $this->getRegistrationByHash($_registration->login_hash);
 }
Esempio n. 7
0
 /**
  * add salutation image path
  */
 public function update_3()
 {
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>image_path</name>
             <type>text</type>
             <length>255</length>
         </field>');
     $this->_backend->addCol('addressbook_salutations', $declaration);
     $this->setTableVersion('addressbook_salutations', '2', TRUE);
     // update image paths
     $salutationTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'addressbook_salutations'));
     $where = $salutationTable->getAdapter()->quoteInto('gender = ?', 'male');
     $salutationTable->update(array('image_path' => 'images/empty_photo_male.png'), $where);
     $where = $salutationTable->getAdapter()->quoteInto('gender = ?', 'female');
     $salutationTable->update(array('image_path' => 'images/empty_photo_female.png'), $where);
     $where = $salutationTable->getAdapter()->quoteInto('gender = ?', 'other');
     $salutationTable->update(array('image_path' => 'images/empty_photo_company.png'), $where);
     $this->setApplicationVersion('Addressbook', '3.4');
 }
 /**
  * counts related records, gropued by Model, Type and Id but excludes relations which will be updated by $excludeCount
  *
  * @param string $ownModel
  * @param Tinebase_Record_RecordSet $relations
  * @return array
  */
 public function countRelatedConstraints($ownModel, $relations, $excludeCount)
 {
     if ($relations->count() == 0) {
         return array();
     }
     $adapter = $this->_dbTable->getAdapter();
     $tableName = SQL_TABLE_PREFIX . 'relations';
     $sql = 'SELECT ' . $this->_dbCommand->getConcat(array($this->_db->quoteIdentifier('related_model'), "'--'", $this->_db->quoteIdentifier('type'), "'--'", $this->_db->quoteIdentifier('own_id'))) . ' 
                 AS ' . $this->_db->quoteIdentifier('id') . ',
                 ' . $this->_db->quoteIdentifier('related_model') . ', ' . $this->_db->quoteIdentifier('type') . ',
                 ' . $this->_db->quoteIdentifier('own_model') . ', COUNT(*)
                 AS ' . $this->_db->quoteIdentifier('count') . '
             FROM ' . $this->_db->quoteIdentifier($tableName) . '
             WHERE ' . $this->_db->quoteInto($this->_db->quoteIdentifier('own_id') . ' IN (?) ', $relations->related_id) . '
                 AND ' . $this->_db->quoteInto($this->_db->quoteIdentifier('related_model') . ' = ? ', $ownModel) . '
                 AND ' . $this->_db->quoteIdentifier('is_deleted') . ' = 0 ';
     if (!empty($excludeCount)) {
         $sql .= ' AND ' . $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' NOT IN (?) ', $excludeCount);
     }
     $sql .= 'GROUP BY ' . $this->_db->quoteIdentifier('own_id') . ',' . $this->_db->quoteIdentifier('related_model') . ', ' . $this->_db->quoteIdentifier('own_model') . ', ' . $this->_db->quoteIdentifier('type') . ', ' . $this->_db->quoteIdentifier('related_id');
     $result = $adapter->fetchAssoc($sql);
     return $result;
 }
 /**
  * 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));
     }
 }
 /**
  * set the password for given account
  *
  * @param   string  $_userId
  * @param   string  $_password
  * @param   bool    $_encrypt encrypt password
  * @param   bool    $_mustChange
  * @return  void
  * @throws  Tinebase_Exception_InvalidArgument
  */
 public function setPassword($_userId, $_password, $_encrypt = TRUE, $_mustChange = null)
 {
     $userId = $_userId instanceof Tinebase_Model_User ? $_userId->getId() : $_userId;
     $user = $_userId instanceof Tinebase_Model_FullUser ? $_userId : $this->getFullUserById($userId);
     $this->checkPasswordPolicy($_password, $user);
     $accountsTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts'));
     $accountData['password'] = $_encrypt ? Hash_Password::generate('SSHA256', $_password) : $_password;
     $accountData['last_password_change'] = Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG);
     $where = array($accountsTable->getAdapter()->quoteInto($accountsTable->getAdapter()->quoteIdentifier('id') . ' = ?', $userId));
     $result = $accountsTable->update($accountData, $where);
     if ($result != 1) {
         throw new Tinebase_Exception_NotFound('Unable to update password! account not found in authentication backend.');
     }
     $this->_setPluginsPassword($userId, $_password, $_encrypt);
 }
 /**
  * update function 1
  * adds application rights
  *
  */
 public function update_1()
 {
     $this->validateTableVersion('application_rights', '1');
     $declaration = new Setup_Backend_Schema_Field();
     $declaration->name = 'account_type';
     $declaration->type = 'enum';
     $declaration->notnull = 'true';
     $declaration->value = array(Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE, 'account', Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP);
     $this->_backend->addCol('application_rights', $declaration);
     $declaration = new Setup_Backend_Schema_Field();
     $declaration->name = 'right';
     $declaration->type = 'text';
     $declaration->length = 64;
     $declaration->notnull = 'true';
     $this->_backend->alterCol('application_rights', $declaration);
     $rightsTable = new Tinebase_Db_Table(array('name' => 'application_rights'));
     $data = array('account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE);
     $where = array($this->_db->quoteIdentifier('account_id') . ' IS NULL', $this->_db->quoteIdentifier('group_id') . ' IS NULL');
     $rightsTable->update($data, $where);
     $data = array('account_type' => 'account');
     $where = array($this->_db->quoteIdentifier('account_id') . ' IS NOT NULL', $this->_db->quoteIdentifier('group_id') . ' IS NULL');
     $rightsTable->update($data, $where);
     $data = array('account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP);
     $where = array($this->_db->quoteIdentifier('account_id') . ' IS NULL', $this->_db->quoteIdentifier('group_id') . ' IS NOT NULL');
     $rightsTable->update($data, $where);
     $data = array('account_id' => new Zend_Db_Expr('group_id'));
     $where = array($rightsTable->getAdapter()->quoteInto($this->_db->quoteIdentifier('account_type') . ' = ?', Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP));
     $rightsTable->update($data, $where);
     $this->_backend->dropIndex('application_rights', 'account_id-group_id-application_id-right');
     $index = new StdClass();
     $index->name = 'account_id-account_type-application_id-right';
     $index->unique = 'true';
     $index->field = array();
     $field = new StdClass();
     $field->name = 'account_id';
     $index->field[] = $field;
     $field = new StdClass();
     $field->name = 'account_type';
     $index->field[] = $field;
     $field = new StdClass();
     $field->name = 'application_id';
     $index->field[] = $field;
     $field = new StdClass();
     $field->name = 'right';
     $index->field[] = $field;
     $this->_backend->addIndex('application_rights', $index);
     $this->_backend->dropCol('application_rights', 'group_id');
     $this->setTableVersion('application_rights', '2');
     $this->setApplicationVersion('Tinebase', '0.2');
 }
 /**
  * Returns Status identifier
  *
  * @param string $_egw14Status
  * @return id identifier
  */
 protected static function getStatus($_egw14Status)
 {
     static $stati;
     $oldstatus = strtoupper($_egw14Status);
     if (!isset($stati[$oldstatus])) {
         $statusTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'tasks_status'));
         $status = $statusTable->fetchRow($statusTable->getAdapter()->quoteInto('status LIKE ?', $oldstatus));
         if (!$status) {
             $identifier = $statusTable->insert(array('created_by' => Tinebase_Core::getUser()->getId(), 'creation_time' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'status' => $oldstatus));
             $stati[$oldstatus] = $identifier;
         } else {
             $stati[$oldstatus] = $status->identifier;
         }
     }
     return $stati[$oldstatus];
 }
 /**
  * update note type
  *
  * @param Tinebase_Model_NoteType $_noteType
  */
 public function updateNoteType(Tinebase_Model_NoteType $_noteType)
 {
     $data = $_noteType->toArray();
     $where = array($this->_noteTypesTable->getAdapter()->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $_noteType->getId()));
     $this->_noteTypesTable->update($data, $where);
 }