Esempio n. 1
0
 /**
  * breaks all relations, optionally only of given role
  * 
  * @param  string $_model    own model to break all relations for
  * @param  string $_backend  own backend to break all relations for
  * @param  string $_id       own id to break all relations for
  * @param  string $_degree   only breaks relations of given degree
  * @param  array  $_type     only breaks relations of given type
  * @return void
  */
 public function breakAllRelations($_model, $_backend, $_id, $_degree = NULL, array $_type = array())
 {
     $relationIds = $this->getAllRelations($_model, $_backend, $_id, $_degree, $_type)->getArrayOfIds();
     if (!empty($relationIds)) {
         $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('rel_id') . ' IN (?)', $relationIds));
         $this->_dbTable->update(array('is_deleted' => 1, 'deleted_by' => Tinebase_Core::getUser()->getId(), 'deleted_time' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG)), $where);
     }
 }
Esempio n. 2
0
 /**
  * unregisters all observables of a given observer 
  * 
  * @param Tinebase_Record_Interface $_observer 
  * @return void
  */
 public function removeAllObservables($_observer)
 {
     if ($_observer->getApplication() && $_observer->getId()) {
         $where = array($this->_db->quoteIdentifier('observer_application') . ' =' . $_observer->getApplication(), $this->_db->quoteIdentifier('observer_identifier') . '  =' . $_observer->getId());
         $this->_db->update(array('is_deleted' => true, 'deleted_by' => Tinebase_Core::getUser()->getId(), 'deleted_time' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG)), $where);
     } else {
         throw new Tinebase_Exception_Record_DefinitionFailure();
     }
 }
Esempio n. 3
0
 /**
  * updates a single role
  * 
  * @param  Tinebase_Model_Role $_role
  * @return Tinebase_Model_Role
  */
 public function updateRole(Tinebase_Model_Role $_role)
 {
     $data = $_role->toArray();
     $data['last_modified_by'] = Tinebase_Core::getUser()->getId();
     $data['last_modified_time'] = Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG);
     $where = $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $_role->getId());
     $this->_rolesTable->update($data, $where);
     $role = $this->getRoleById($_role->getId());
     return $role;
 }
Esempio n. 4
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. 5
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');
 }
Esempio n. 6
0
 /**
  * create a new group in sync backend
  * 
  * NOTE: sets visibility to HIDDEN if list_id is empty
  *
  * @param  Tinebase_Model_Group  $_group
  * @return Tinebase_Model_Group
  */
 public function updateGroupInSqlBackend(Tinebase_Model_Group $_group)
 {
     $groupId = Tinebase_Model_Group::convertGroupIdToInt($_group);
     if (empty($_group->list_id)) {
         $_group->visibility = Tinebase_Model_Group::VISIBILITY_HIDDEN;
         $_group->list_id = null;
     }
     $data = array('name' => $_group->name, 'description' => $_group->description, 'visibility' => $_group->visibility, 'email' => $_group->email, 'list_id' => $_group->list_id);
     $where = $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $groupId);
     $this->groupsTable->update($data, $where);
     return $this->getGroupById($groupId);
 }
 /**
  * transfers relations
  * 
  * @param string $sourceId
  * @param string $destinationId
  * @param string $model
  * 
  * @return array
  */
 public function transferRelations($sourceId, $destinationId, $model)
 {
     $controller = Tinebase_Controller_Record_Abstract::getController($model);
     // just for validation, the records aren't needed
     $controller->get($sourceId);
     $controller->get($destinationId);
     $tableName = SQL_TABLE_PREFIX . 'relations';
     // own side
     $select = $this->_db->select()->where($this->_db->quoteIdentifier('own_id') . ' = ?', $sourceId);
     $select->from($tableName);
     $stmt = $this->_db->query($select);
     $entries = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
     $stmt->closeCursor();
     // rel side
     $select = $this->_db->select()->where($this->_db->quoteIdentifier('related_id') . ' = ?', $sourceId);
     $select->from($tableName);
     $stmt = $this->_db->query($select);
     $relentries = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
     $stmt->closeCursor();
     $skipped = array();
     foreach ($entries as $entry) {
         $select = $this->_db->select()->where($this->_db->quoteInto($this->_db->quoteIdentifier('own_id') . ' = ?', $destinationId) . ' AND ' . $this->_db->quoteInto($this->_db->quoteIdentifier('related_id') . ' = ?', $entry['related_id']));
         $select->from($tableName);
         $stmt = $this->_db->query($select);
         $existing = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
         $stmt->closeCursor();
         if (count($existing) > 0) {
             $skipped[$entry['rel_id']] = $entry;
         } else {
             $this->_dbTable->update(array('own_id' => $destinationId), $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $entry['id']));
         }
     }
     foreach ($relentries as $entry) {
         $select = $this->_db->select()->where($this->_db->quoteInto($this->_db->quoteIdentifier('related_id') . ' = ?', $destinationId) . ' AND ' . $this->_db->quoteInto($this->_db->quoteIdentifier('own_id') . ' = ?', $entry['own_id']));
         $select->from($tableName);
         $stmt = $this->_db->query($select);
         $existing = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
         $stmt->closeCursor();
         if (count($existing) > 0) {
         } else {
             $this->_dbTable->update(array('related_id' => $destinationId), $this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $entry['id']));
         }
     }
     return $skipped;
 }
 /**
  * @param $_oldTableName
  * @param $_newTableName
  * @return int
  */
 public function renameTableInAppTables($_oldTableName, $_newTableName)
 {
     $applicationsTables = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'application_tables'));
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('name') . ' = ?', $_oldTableName));
     $result = $applicationsTables->update(array('name' => $_newTableName), $where);
     return $result;
 }
 /**
  * updates an user
  * 
  * this function updates an user 
  *
  * @param Tinebase_Model_FullUser $_user
  * @return Tinebase_Model_FullUser
  * @throws 
  */
 public function updateUserInSqlBackend(Tinebase_Model_FullUser $_user)
 {
     if (!$_user->isValid()) {
         throw new Tinebase_Exception_Record_Validation('Invalid user object. ' . print_r($_user->getValidationErrors(), TRUE));
     }
     $accountId = Tinebase_Model_User::convertUserIdToInt($_user);
     $oldUser = $this->getFullUserById($accountId);
     if (empty($_user->contact_id)) {
         $_user->visibility = 'hidden';
         $_user->contact_id = null;
     }
     $accountData = $this->_recordToRawData($_user);
     // don't update id
     unset($accountData['id']);
     // ignore all other states (expired and blocked)
     if ($_user->accountStatus == Tinebase_User::STATUS_ENABLED) {
         $accountData[$this->rowNameMapping['accountStatus']] = $_user->accountStatus;
         if ($oldUser->accountStatus === Tinebase_User::STATUS_BLOCKED) {
             $accountData[$this->rowNameMapping['loginFailures']] = 0;
         } elseif ($oldUser->accountStatus === Tinebase_User::STATUS_EXPIRED) {
             $accountData[$this->rowNameMapping['accountExpires']] = null;
         }
     } elseif ($_user->accountStatus == Tinebase_User::STATUS_DISABLED) {
         $accountData[$this->rowNameMapping['accountStatus']] = $_user->accountStatus;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($accountData, true));
     }
     try {
         $accountsTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts'));
         $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $accountId));
         $accountsTable->update($accountData, $where);
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw $e;
     }
     return $this->getUserById($accountId, 'Tinebase_Model_FullUser');
 }
 /**
  * update to 0.13
  * - rename Dialer app to 'Phone'
  */
 public function update_12()
 {
     // rename app in application table
     $appTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'applications'));
     $appTable->update(array('name' => 'Phone'), "name = 'Dialer'");
     $this->setApplicationVersion('Tinebase', '0.13');
 }
 /**
  * testConcurrencyLinebreakMismatch
  * 
  * @see 0007140: normalize linebreaks in concurrency check
  */
 public function testConcurrencyLinebreakMismatch()
 {
     $utask = $this->_persistantTestTask1;
     $utask->description = 'description' . "\n";
     $utask = $this->_controller->update($utask);
     // change linebreak in db to \r\n
     $loggedMods = Tinebase_Timemachine_ModificationLog::getInstance()->getModifications('Tasks', $utask->getId(), 'Tasks_Model_Task', 'Sql', Tinebase_DateTime::now()->subMinute(5), $utask->last_modified_time);
     $this->assertEquals(1, count($loggedMods));
     $mod = $loggedMods[0]->toArray();
     $this->assertEquals('description', $mod['modified_attribute']);
     $mod['new_value'] = 'description' . "\r\n";
     $modlog = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'timemachine_modlog'));
     $modlog->update($mod, Tinebase_Core::getDb()->quoteInto('id = ?', $mod['id']));
     // this should still work as we normalize linebreaks in concurrency check
     $resolvableConcurrencyTask = clone $utask;
     $resolvableConcurrencyTask->last_modified_time = Tinebase_DateTime::now()->addHour(-1);
     $resolvableConcurrencyTask->description = 'description' . "\n";
     $task = $this->_controller->update($resolvableConcurrencyTask);
     $this->assertEquals('description' . "\n", $task->description);
 }
Esempio n. 12
0
 /**
  * updates an user
  * 
  * this function updates an user 
  *
  * @param Tinebase_Model_FullUser $_user
  * @return Tinebase_Model_FullUser
  * @throws 
  */
 public function updateUserInSqlBackend(Tinebase_Model_FullUser $_user)
 {
     if (!$_user->isValid()) {
         throw new Tinebase_Exception_Record_Validation('Invalid user object. ' . print_r($_user->getValidationErrors(), TRUE));
     }
     $accountId = Tinebase_Model_User::convertUserIdToInt($_user);
     $oldUser = $this->getFullUserById($accountId);
     $accountsTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts'));
     if (empty($_user->contact_id)) {
         $_user->visibility = 'hidden';
         $_user->contact_id = null;
     }
     $accountData = array('login_name' => $_user->accountLoginName, 'expires_at' => $_user->accountExpires instanceof DateTime ? $_user->accountExpires->get(Tinebase_Record_Abstract::ISO8601LONG) : NULL, 'primary_group_id' => $_user->accountPrimaryGroup, 'home_dir' => $_user->accountHomeDirectory, 'login_shell' => $_user->accountLoginShell, 'openid' => $_user->openid, 'visibility' => $_user->visibility, 'contact_id' => $_user->contact_id, $this->rowNameMapping['accountDisplayName'] => $_user->accountDisplayName, $this->rowNameMapping['accountFullName'] => $_user->accountFullName, $this->rowNameMapping['accountFirstName'] => $_user->accountFirstName, $this->rowNameMapping['accountLastName'] => $_user->accountLastName, $this->rowNameMapping['accountEmailAddress'] => $_user->accountEmailAddress);
     // ignore all other states (expired and blocked)
     if ($_user->accountStatus == Tinebase_User::STATUS_ENABLED) {
         $accountData[$this->rowNameMapping['accountStatus']] = $_user->accountStatus;
         if ($oldUser->accountStatus === Tinebase_User::STATUS_BLOCKED) {
             $accountData[$this->rowNameMapping['loginFailures']] = 0;
         } elseif ($oldUser->accountStatus === Tinebase_User::STATUS_EXPIRED) {
             $accountData[$this->rowNameMapping['accountExpires']] = null;
         }
     } elseif ($_user->accountStatus == Tinebase_User::STATUS_DISABLED) {
         $accountData[$this->rowNameMapping['accountStatus']] = $_user->accountStatus;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($accountData, true));
     }
     try {
         $accountsTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts'));
         $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $accountId));
         $accountsTable->update($accountData, $where);
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw $e;
     }
     return $this->getUserById($accountId, 'Tinebase_Model_FullUser');
 }
 /**
  * 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);
 }