public function update(ActiveSync_Model_SyncState $_syncState) { $where = array($this->_db->quoteInto('device_id = ?', $_syncState->device_id), $this->_db->quoteInto('type = ?', $_syncState->type), $this->_db->quoteInto('counter = ?', $_syncState->counter)); $newData = array('lastsync' => $_syncState->lastsync); $result = $this->_db->update(SQL_TABLE_PREFIX . 'acsync_synckey', $newData, $where); return $result; }
/** * Should handle execution of the task, taking as much (optional) parameters as needed * * The parameters should be optional and failing to provide them should be handled by * the task */ public function execute($sourceId = null, $userId = null) { $now = new \MUtil_Db_Expr_CurrentTimestamp(); $values = array('gso_last_synch' => $now, 'gso_changed' => $now, 'gso_changed_by' => $userId); $where = $this->db->quoteInto('gso_id_source = ?', $sourceId); $this->db->update('gems__sources', $values, $where); }
/** * Should handle execution of the task, taking as much (optional) parameters as needed * * The parameters should be optional and failing to provide them should be handled by * the task */ public function execute($lineNr = null, $forRoundOrder = null, $usesRoundRound = null, $roundField = null) { $batch = $this->getBatch(); $import = $batch->getVariable('import'); if (!(isset($import['trackId']) && $import['trackId'])) { // Do nothing return; } if (isset($import['roundOrders'][$usesRoundRound]) && $import['roundOrders'][$usesRoundRound]) { $this->db->update('gems__rounds', array($roundField => $import['roundOrders'][$usesRoundRound]), $this->db->quoteInto("gro_id_order = ? AND ", $forRoundOrder) . $this->db->quoteInto("gro_id_track = ?", $import['trackId'])); } }
/** * Should handle execution of the task, taking as much (optional) parameters as needed * * The parameters should be optional and failing to provide them should be handled by * the task */ public function execute() { $role = \Gems_Roles::getInstance(); $parents = $this->db->fetchPairs("SELECT grl_id_role, grl_parents FROM gems__roles"); // \MUtil_Echo::track($parents); if ($parents) { foreach ($parents as $id => $priv) { $values['grl_parents'] = implode(',', $role->translateToRoleIds($priv)); $this->db->update('gems__roles', $values, $this->db->quoteInto('grl_id_role = ?', $id)); } } }
/** * Should handle execution of the task, taking as much (optional) parameters as needed * * The parameters should be optional and failing to provide them should be handled by * the task */ public function execute($tableName = '', $idField = '', $passwordField = '', $methodField = '') { $passwords = $this->db->fetchPairs("SELECT {$idField}, {$passwordField} FROM {$tableName} WHERE {$passwordField} IS NOT NULL AND {$methodField} IS NULL"); if ($passwords) { $values[$methodField] = 'default'; foreach ($passwords as $key => $password) { $values[$passwordField] = $this->project->encrypt($password, $values[$methodField]); $this->db->update($tableName, $values, "{$idField} = '{$key}'"); } $this->getBatch()->addMessage(sprintf($this->_('%d passwords encrypted for table %s.'), count($passwords), $tableName)); } else { $this->getBatch()->addMessage(sprintf($this->_('No passwords found in table %s.'), $tableName)); } }
/** * get array of ids which got send to the client for a given class * * @param Syncope_Model_IDevice|string $_deviceId * @param Syncope_Model_IFolder|string $_folderId * @return Syncope_Model_SyncState */ public function validate($_deviceId, $_folderId, $_syncKey) { $deviceId = $_deviceId instanceof Syncope_Model_IDevice ? $_deviceId->id : $_deviceId; $folderId = $_folderId instanceof Syncope_Model_IFolder ? $_folderId->id : $_folderId; $select = $this->_db->select()->from($this->_tablePrefix . 'synckey')->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)->where($this->_db->quoteIdentifier('counter') . ' = ?', $_syncKey)->where($this->_db->quoteIdentifier('type') . ' = ?', $folderId); $stmt = $this->_db->query($select); $state = $stmt->fetchObject('Syncope_Model_SyncState'); $stmt = null; # see https://bugs.php.net/bug.php?id=44081 if (!$state instanceof Syncope_Model_ISyncState) { return false; } $this->_convertFields($state); // check if this was the latest syncKey $select = $this->_db->select()->from($this->_tablePrefix . 'synckey')->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)->where($this->_db->quoteIdentifier('counter') . ' = ?', $_syncKey + 1)->where($this->_db->quoteIdentifier('type') . ' = ?', $folderId); $stmt = $this->_db->query($select); $moreRecentState = $stmt->fetchObject('Syncope_Model_SyncState'); $stmt = null; # see https://bugs.php.net/bug.php?id=44081 // found more recent synckey => the last sync repsone got not received by the client if ($moreRecentState instanceof Syncope_Model_ISyncState) { // undelete entries marked as deleted in syncope_content table $this->_db->update($this->_tablePrefix . 'content', array('is_deleted' => 0), array('device_id = ?' => $deviceId, 'folder_id = ?' => $folderId, 'creation_synckey = ?' => $state->counter, 'is_deleted = ?' => 1)); // remove entries added during latest sync in syncope_content table $this->_db->delete($this->_tablePrefix . 'content', array('device_id = ?' => $deviceId, 'folder_id = ?' => $folderId, 'creation_synckey > ?' => $state->counter)); } else { // finaly delete all entries marked for removal in syncope_content table $this->_db->delete($this->_tablePrefix . 'content', array('device_id = ?' => $deviceId, 'folder_id = ?' => $folderId, 'is_deleted = ?' => 1)); } // remove all other synckeys $this->_deleteOtherStates($state); return $state; }
public function aggregate($object) { if (!$object->getEntityPkValue() && $object->getId()) { $object->load($object->getReviewId()); } $ratingModel = Mage::getModel('rating/rating'); $ratingSummaries = $ratingModel->getEntitySummary($object->getEntityPkValue(), false); $nonDelete = array(); foreach ($ratingSummaries as $ratingSummaryObject) { if ($ratingSummaryObject->getCount()) { $ratingSummary = round($ratingSummaryObject->getSum() / $ratingSummaryObject->getCount()); } else { $ratingSummary = $ratingSummaryObject->getSum(); } $reviewsCount = $this->getTotalReviews($object->getEntityPkValue(), true, $ratingSummaryObject->getStoreId()); $select = $this->_read->select(); $select->from($this->_aggregateTable)->where("{$this->_aggregateTable}.entity_pk_value = ?", $object->getEntityPkValue())->where("{$this->_aggregateTable}.entity_type = ?", $object->getEntityId())->where("{$this->_aggregateTable}.store_id = ?", $ratingSummaryObject->getStoreId()); $oldData = $this->_read->fetchRow($select); $data = new Varien_Object(); $data->setReviewsCount($reviewsCount)->setEntityPkValue($object->getEntityPkValue())->setEntityType($object->getEntityId())->setRatingSummary($ratingSummary > 0 ? $ratingSummary : 0)->setStoreId($ratingSummaryObject->getStoreId()); $this->_write->beginTransaction(); try { if ($oldData['primary_id'] > 0) { $condition = $this->_write->quoteInto("{$this->_aggregateTable}.primary_id = ?", $oldData['primary_id']); $this->_write->update($this->_aggregateTable, $data->getData(), $condition); } else { $this->_write->insert($this->_aggregateTable, $data->getData()); } $this->_write->commit(); } catch (Exception $e) { $this->_write->rollBack(); } } }
/** * save data * @param string $key * @param int $language_id * @param string $val * @return boolean */ public function save($key, $language_id, $val, $section = "", $import = false, $newKey = "") { $data = array('key' => $newKey == "" ? $key : $newKey, 'language_id' => $language_id, 'value' => $val, 'section' => $section); $selectTranslate = $this->_dbTable->select()->where('`language_id` = ?', $language_id)->where('`key` = ?', $data['key']); if ($section != "" && !$import) { $data['section'] = $section; } if ($section != "" && $import) { $selectTranslate->where('`section` = ?', $section); } $rowTranslate = $selectTranslate->query()->fetchObject(); // ->toArray() if (is_object($rowTranslate)) { $res = $this->_dbTable->update($data, array('id = ?' => $rowTranslate->id)); if (!$import) { $this->cacheCleanTranslation(); } return $res == 1; } else { $res = $this->_dbTable->insert($data); if (!$import) { $this->cacheCleanTranslation(); } return $res > 0; } }
/** * * @param array $contentTypes */ protected function _insertContentTypes(array $contentTypes) { $contentTypeModel = $this->getModelFromCache('XenForo_Model_ContentType'); $existingContentTypes = $contentTypeModel->getContentTypesForCache(); foreach ($contentTypes as $contentType => $contentTypeParams) { $existingFields = array(); if (isset($existingContentTypes[$contentType])) { $existingFields = $existingContentTypes[$contentType]; } if (isset($contentTypeParams['addon_id'])) { if (isset($contentTypeParams['fields'])) { $contentTypeFields = array($contentType => $contentTypeParams['fields']); $this->_insertContentTypeFields($contentTypeFields); $existingFields = array_merge($contentTypeFields, $existingFields); } $fields = serialize($existingFields); $addOnId = $contentTypeParams['addon_id']; $sql = "INSERT INTO xf_content_type (\n content_type,\n addon_id,\n fields\n ) VALUES (\n '" . $contentType . "',\n '" . $addOnId . "',\n '" . $fields . "'\n ) ON DUPLICATE KEY UPDATE\n addon_id = '" . $addOnId . "',\n fields = '" . $fields . "'"; $this->_db->query($sql); $existingContentTypes[$contentType] = $existingFields; } else { $this->_db->update('xf_content_type', array('fields' => serialize($existingFields)), 'content_type = ' . $this->_db->quote($contentType)); } } $dataRegistryModel = $this->getModelFromCache('XenForo_Model_DataRegistry'); $dataRegistryModel->set('contentTypes', $existingContentTypes); }
/** * Test the Adapter's update() method. * Update a single row and verify that the change was made. * Attempt to update a row that does not exist, and verify * that no change was made. * * @todo: test that requires delimited identifiers. */ public function testUpdate() { $idKey = $this->getResultSetKey('id'); $titleKey = $this->getResultSetKey('title'); $subtitleKey = $this->getResultSetKey('subtitle'); $table = $this->getIdentifier(self::TABLE_NAME); $title = $this->getIdentifier('title'); $subtitle = $this->getIdentifier('subtitle'); $newTitle = 'New News Item 2'; $newSubTitle = 'New Sub title 2'; // Test that we can change the values in // an existing row. $result = $this->_db->update($table, array($title => $newTitle, $subtitle => $newSubTitle), 'id = 2'); $this->assertEquals(1, $result); // Query the row to see if we have the new values. $select = $this->_db->select(); $select->from($table); $select->where('id = 2'); $stmt = $this->_db->query($select); $result = $stmt->fetchAll(); $this->assertEquals(2, $result[0][$idKey]); $this->assertEquals($newTitle, $result[0][$titleKey]); $this->assertEquals($newSubTitle, $result[0][$subtitleKey]); // Test that update affects no rows if the WHERE // clause matches none. $result = $this->_db->update($table, array('title' => $newTitle, 'subtitle' => $newSubTitle), 'id = 327'); $this->assertEquals(0, $result); }
/** * Move tree node * * @todo Use adapter for generate conditions * @param Varien_Data_Tree_Node $node * @param Varien_Data_Tree_Node $newParent * @param Varien_Data_Tree_Node $prevNode */ public function move($node, $newParent, $prevNode = null) { $position = 1; $oldPath = $node->getData($this->_pathField); $newPath = $newParent->getData($this->_pathField); $newPath = $newPath . '/' . $node->getId(); $oldPathLength = strlen($oldPath); $newLevel = $newParent->getLevel() + 1; $levelDisposition = $newLevel - $node->getLevel(); $data = array($this->_levelField => new Zend_Db_Expr("{$this->_levelField} + '{$levelDisposition}'"), $this->_pathField => new Zend_Db_Expr("CONCAT('{$newPath}', RIGHT({$this->_pathField}, LENGTH({$this->_pathField}) - {$oldPathLength}))")); $condition = $this->_conn->quoteInto("{$this->_pathField} REGEXP ?", "^{$oldPath}(/|\$)"); $this->_conn->beginTransaction(); $reorderData = array($this->_orderField => new Zend_Db_Expr("{$this->_orderField} + 1")); try { if ($prevNode && $prevNode->getId()) { $reorderCondition = "{$this->_orderField} > {$prevNode->getData($this->_orderField)}"; $position = $prevNode->getData($this->_orderField) + 1; } else { $reorderCondition = $this->_conn->quoteInto("{$this->_pathField} REGEXP ?", "^{$newParent->getData($this->_pathField)}/[0-9]+\$"); $select = $this->_conn->select()->from($this->_table, new Zend_Db_Expr("MIN({$this->_orderField})"))->where($reorderCondition); $position = (int) $this->_conn->fetchOne($select); } $this->_conn->update($this->_table, $reorderData, $reorderCondition); $this->_conn->update($this->_table, $data, $condition); $this->_conn->update($this->_table, array($this->_orderField => $position, $this->_levelField => $newLevel), $this->_conn->quoteInto("{$this->_idField} = ?", $node->getId())); $this->_conn->commit(); } catch (Exception $e) { $this->_conn->rollBack(); throw new Exception("Can't move tree node due to error: " . $e->getMessage()); } }
public function save(Mage_Admin_Model_Permissions_Roles $role) { if ($role->getPid() > 0) { $row = $this->load($role->getPid()); } else { $row = array('tree_level' => 0); } if ($role->getId()) { $this->_write->update($this->_roleTable, array('parent_id' => $role->getPid(), 'tree_level' => $row['tree_level'] + 1, 'role_name' => $role->getName()), "role_id = {$role->getId()}"); } else { $this->_write->insert($this->_roleTable, array('parent_id' => $role->getPid(), 'tree_level' => $row['tree_level'] + 1, 'role_name' => $role->getName(), 'role_type' => $role->getRoleType())); $role->setId($this->_write->lastInsertId()); } $this->_updateRoleUsersAcl($role); return $role->getId(); }
public function updateAll(My_Model_Mapper_IdentityObject $identity, array $data) { if (empty($data)) { throw new Exception("Data can not be empty"); } return $this->_connection->update($this->_tablename, $data, $this->_getSelection()->where($identity)); }
/** * Checks if the user is allowed to login or is blocked * * An adapter authorizes and if the end resultis boolean, string or array * it is converted into a \Zend_Auth_Result. * * @return mixed \Zend_Auth_Adapter_Interface|\Zend_Auth_Result|boolean|string|array */ protected function authorizeBlock() { try { $select = $this->db->select(); $select->from('gems__user_login_attempts', array('UNIX_TIMESTAMP(gula_block_until) - UNIX_TIMESTAMP() AS wait'))->where('gula_block_until is not null')->where('gula_login = ?', $this->getLoginName())->where('gula_id_organization = ?', $this->getCurrentOrganizationId())->limit(1); // Not the first login if ($block = $this->db->fetchOne($select)) { if ($block > 0) { $minutes = intval($block / 60) + 1; // Report all is not well return sprintf($this->plural('Your account is temporarily blocked, please wait a minute.', 'Your account is temporarily blocked, please wait %d minutes.', $minutes), $minutes); } else { // Clean the block once it's past $values['gula_failed_logins'] = 0; $values['gula_last_failed'] = null; $values['gula_block_until'] = null; $where = $this->db->quoteInto('gula_login = ? AND ', $this->getLoginName()); $where .= $this->db->quoteInto('gula_id_organization = ?', $this->getCurrentOrganizationId()); $this->db->update('gems__user_login_attempts', $values, $where); } } } catch (\Zend_Db_Exception $e) { // Fall through as this does not work if the database upgrade did not run // \MUtil_Echo::r($e); } return true; }
/** * sets etags, expects ids as keys and etags as value * * @param array $etags * * @todo maybe we should find a better place for the etag functions as this is currently only used in Calendar + Tasks */ public function setETags(array $etags) { foreach ($etags as $id => $etag) { $where = array($this->_db->quoteInto($this->_db->quoteIdentifier($this->_identifier) . ' = ?', $id)); $this->_db->update($this->_tablePrefix . $this->_tableName, array('etag' => $etag), $where); } }
/** * Move tree node * * @param Varien_Data_Tree_Node $node * @param Varien_Data_Tree_Node $parentNode * @param Varien_Data_Tree_Node $prevNode */ public function move($category, $newParent, $prevNode = null) { $position = 1; $oldPath = $category->getData($this->_pathField); $newPath = $newParent->getData($this->_pathField); $newPath = $newPath . '/' . $category->getId(); $oldPathLength = strlen($oldPath); $data = array($this->_pathField => new Zend_Db_Expr("CONCAT('{$newPath}', RIGHT({$this->_pathField}, LENGTH({$this->_pathField}) - {$oldPathLength}))")); $condition = $this->_conn->quoteInto("{$this->_pathField} REGEXP ?", "^{$oldPath}(/|\$)"); $this->_conn->beginTransaction(); try { if ($prevNode && $prevNode->getId()) { $reorderData = array($this->_orderField => new Zend_Db_Expr("{$this->_orderField} + 1")); $reorderCondition = "{$this->_orderField} > {$prevNode->getData($this->_orderField)}"; $this->_conn->update($this->_table, $reorderData, $reorderCondition); $position = $prevNode->getData($this->_orderField) + 1; } $this->_conn->update($this->_table, $data, $condition); $this->_conn->update($this->_table, array($this->_orderField => $position), $this->_conn->quoteInto("{$this->_idField} = ?", $category->getId())); $this->_conn->commit(); } catch (Exception $e) { $this->_conn->rollBack(); throw new Exception("Can't move tree node due to error: " . $e->getMessage()); } }
protected function updateQueryTableOnDelete($oo_id, $ids, $fieldname) { if (!empty($ids)) { $value = null; $this->db->update($this->querytable, [$fieldname => $value], $this->idField . " IN (" . implode(",", $ids) . ")"); } }
/** * Queries the minecraft server specified and returns an array with information on the server * @param Zend_Db_Adapter_Abstract $db * @param $minecraftServer */ public function queryMinecraftServer($db, $minecraftServer) { $status = array(); switch ($minecraftServer['query_type']) { case 'full_status': $query = new HeroDev_MinecraftStatus_Helper_GS4QueryHelper(); try { $query->connect($minecraftServer['address'], $minecraftServer['query_port']); $status = $query->getLongStatus(); if (isset($status['playerList'])) { //Try to generate a profile link for every player from their minecraft username. We do this now to minimize queries later on. foreach ($status['playerList'] as $key => $player) { $status['playerList'][$key] = array('username' => $player, 'profileLink' => self::getUserHref($player)); } } $status = array_merge($status, array("online" => 1)); } catch (GS4QueryException $e) { $status = array("online" => 0, "error" => $e->getMessage()); } break; case 'short_status': $query = new HeroDev_MinecraftStatus_Helper_GS4QueryHelper(); try { $query->connect($minecraftServer['address'], $minecraftServer['query_port']); $status = $query->getShortStatus(); $status = array_merge($status, array("online" => 1)); } catch (GS4QueryException $e) { $status = array("online" => 0, "error" => $e->getMessage()); } break; case 'serverlistping': $query = new HeroDev_MinecraftStatus_Helper_ServerListPingHelper(); try { $status = $query->pingServer($minecraftServer['address'], $minecraftServer['query_port']); $status = array_merge($status, array("online" => 1)); } catch (ServerListPingException $e) { $status = array("online" => 0, "error" => $e->getMessage()); } break; } //Update the status data $db->update('xf_herodev_minecraft_server', array('query_data' => serialize($status)), 'minecraft_server_id = ' . $db->quote($minecraftServer['minecraft_server_id'])); //Update the last query time $db->update('xf_herodev_minecraft_server', array('last_query_date' => XenForo_Application::$time), 'minecraft_server_id = ' . $db->quote($minecraftServer['minecraft_server_id'])); return $status; }
/** * Seta/Atualiza um valor do registro * * @param string $key chave do valor * @param mixed $value novo valor */ public function __set($key, $value) { if (isset($this->{$key})) { $this->db->update("registry", array("value" => $value), "context='{$this->getContext()}' AND `key`='{$key}'"); } else { $this->db->insert("registry", array("context" => $this->getContext(), "key" => $key, "value" => $value)); } $this->update(); }
/** * Update the token data when a Mail has been sent. * @param integer $tokenId TokenId to update. If none is supplied, use the current token */ public function updateToken($tokenId = false) { if (!$tokenId) { $tokenId = $this->token->getTokenId(); } $tokenData['gto_mail_sent_num'] = new \Zend_Db_Expr('gto_mail_sent_num + 1'); $tokenData['gto_mail_sent_date'] = \MUtil_Date::format(new \Zend_Date(), 'yyyy-MM-dd'); $this->db->update('gems__tokens', $tokenData, $this->db->quoteInto('gto_id_token = ?', $tokenId)); }
/** * Set the reception code for a respondent and cascade non-success codes to the * tracks / surveys. * * @param string $patientId Can be empty if $respondentId is passed * @param int $organizationId * @param string $newCode String or \Gems_Util_ReceptionCode * @param int $respondentId Pass when at hand, is looked up otherwise * @param string $oldCode Pass when at hand as tring or \Gems_Util_ReceptionCode, is looked up otherwise * @return \Gems_Util_ReceptionCode The new code reception code object for further processing */ public function setReceptionCode($patientId, $organizationId, $newCode, $respondentId = null, $oldCode = null) { if ($newCode instanceof \Gems_Util_ReceptionCode) { $code = $newCode; $newCode = $code->getCode(); } else { $code = $this->util->getReceptionCode($newCode); } $userId = $this->currentUser->getUserId(); // Perform actual save, but not for simple stop codes. if ($code->isForRespondents()) { if (null === $oldCode) { $oldCode = $this->getReceptionCode($patientId, $organizationId, $respondentId); } if ($oldCode instanceof \Gems_Util_ReceptionCode) { $oldCode = $oldCode->getCode(); } // If the code wasn't set already if ($oldCode !== $newCode) { $values['gr2o_reception_code'] = $newCode; $values['gr2o_changed'] = new \MUtil_Db_Expr_CurrentTimestamp(); $values['gr2o_changed_by'] = $userId; if ($patientId) { // Update though primamry key is prefered $where = 'gr2o_patient_nr = ? AND gr2o_id_organization = ?'; $where = $this->db->quoteInto($where, $patientId, null, 1); } else { $where = 'gr2o_id_user = ? AND gr2o_id_organization = ?'; $where = $this->db->quoteInto($where, $respondentId, null, 1); } $where = $this->db->quoteInto($where, $organizationId, null, 1); $this->db->update('gems__respondent2org', $values, $where); } } // Is the respondent really removed if (!$code->isSuccess()) { // Only check for $respondentId when it is really needed if (null === $respondentId) { $respondentId = $this->util->getDbLookup()->getRespondentId($patientId, $organizationId); } // Cascade to tracks // the responsiblilty to handle it correctly is on the sub objects now. $tracks = $this->loader->getTracker()->getRespondentTracks($respondentId, $organizationId); foreach ($tracks as $track) { if ($track->setReceptionCode($code, null, $userId)) { $this->addChanged(); } } } if ($code->isForRespondents()) { $this->handleRespondentChanged($patientId, $organizationId, $respondentId); } return $code; }
/** * Update session * * @param string $sessId * @param string $sessData * @return boolean */ public function write($sessId, $sessData) { $data = array('session_id' => $this->_prepareValueForSave($sessId), 'session_expires' => time() + $this->getLifeTime(), 'session_data' => $this->_prepareValueForSave($sessData)); $exists = $this->_write->fetchOne("SELECT session_id FROM `" . $this->_sessionTable . "` WHERE session_id = '" . $sessId . "'"); if ($exists) { $this->_write->update($this->_sessionTable, $data, 'session_id'); } else { $this->_write->insert($this->_sessionTable, $data); } return true; }
/** * set last login failure in accounts table * * @param string $_loginName * @return Tinebase_Model_FullUser|null user if found * @see Tinebase/User/Tinebase_User_Interface::setLastLoginFailure() */ public function setLastLoginFailure($_loginName) { try { $user = $this->getUserByPropertyFromSqlBackend('accountLoginName', $_loginName, 'Tinebase_Model_FullUser'); } catch (Tinebase_Exception_NotFound $tenf) { // nothing todo => is no existing user return null; } $values = array('last_login_failure_at' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'login_failures' => new Zend_Db_Expr($this->_db->quoteIdentifier('login_failures') . ' + 1')); $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $user->getId())); $this->_db->update(SQL_TABLE_PREFIX . 'accounts', $values, $where); return $user; }
/** * Tell the organization there is at least one respondent attached to it. * * Does nothing if this is already known. * * @param int $userId The current user * @return \Gems_User_Organization (continutation pattern) */ public function setHasRespondents($userId) { if (!$this->_get('gor_has_respondents')) { $values['gor_has_respondents'] = 1; $values['gor_changed'] = new \MUtil_Db_Expr_CurrentTimestamp(); $values['gor_changed_by'] = $userId; $where = $this->db->quoteInto('gor_id_organization = ?', $this->_id); $this->db->update('gems__organizations', $values, $where); // Invalidate cache / change value $this->_set('gor_has_respondents', 1); } return $this; }
public function received(Mage_Newsletter_Model_Subscriber $subscriber, Mage_Newsletter_Model_Queue $queue) { $this->_write->beginTransaction(); try { $data['letter_sent_at'] = now(); $this->_write->update($this->_subscriberLinkTable, $data, array($this->_write->quoteInto('subscriber_id=?', $subscriber->getId()), $this->_write->quoteInto('queue_id=?', $queue->getId()))); $this->_write->commit(); } catch (Exception $e) { $this->_write->rollBack(); Mage::throwException(Mage::helper('newsletter')->__('Cannot mark as received subscriber')); } return $this; }
/** * Update session * * @param string $sessId * @param string $sessData * @return boolean */ public function write($sessId, $sessData) { $bind = array('session_expires' => time() + $this->_lifeTime, 'session_data' => $sessData); $exists = $this->_write->fetchOne("SELECT session_id FROM {$this->_sessionTable} \n WHERE session_id = ?", array($sessId)); if ($exists) { $where = $this->_write->quoteInto('session_id=?', $sessId); $this->_write->update($this->_sessionTable, $bind, $where); } else { $bind['session_id'] = $sessId; $this->_write->insert($this->_sessionTable, $bind); } return true; }
/** * set last login failure in accounts table * * @param string $_loginName * @see Tinebase/User/Tinebase_User_Interface::setLastLoginFailure() */ public function setLastLoginFailure($_loginName) { Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Login of user ' . $_loginName . ' failed.'); try { $user = $this->getUserByLoginName($_loginName); } catch (Tinebase_Exception_NotFound $tenf) { // nothing todo => is no existing user return; } $values = array('last_login_failure_at' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'login_failures' => new Zend_Db_Expr($this->_db->quoteIdentifier('login_failures') . ' + 1')); $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $user->getId())); $this->_db->update(SQL_TABLE_PREFIX . 'accounts', $values, $where); }
/** * Updates data when subscriber received * * @param \Magento\Newsletter\Model\Subscriber $subscriber * @param \Magento\Newsletter\Model\Queue $queue * @return $this * @throws \Magento\Framework\Model\Exception */ public function received(\Magento\Newsletter\Model\Subscriber $subscriber, \Magento\Newsletter\Model\Queue $queue) { $this->_write->beginTransaction(); try { $data['letter_sent_at'] = $this->_date->gmtDate(); $this->_write->update($this->_subscriberLinkTable, $data, array('subscriber_id = ?' => $subscriber->getId(), 'queue_id = ?' => $queue->getId())); $this->_write->commit(); } catch (\Exception $e) { $this->_write->rollBack(); throw new \Magento\Framework\Model\Exception(__('We cannot mark as received subscriber.')); } return $this; }
/** * Updates data when subscriber received * * @param Mage_Newsletter_Model_Subscriber $subscriber * @param Mage_Newsletter_Model_Queue $queue * @return Mage_Newsletter_Model_Resource_Subscriber */ public function received(Mage_Newsletter_Model_Subscriber $subscriber, Mage_Newsletter_Model_Queue $queue) { $this->_write->beginTransaction(); try { $data['letter_sent_at'] = Mage::getSingleton('Mage_Core_Model_Date')->gmtDate(); $this->_write->update($this->_subscriberLinkTable, $data, array('subscriber_id = ?' => $subscriber->getId(), 'queue_id = ?' => $queue->getId())); $this->_write->commit(); } catch (Exception $e) { $this->_write->rollBack(); Mage::throwException(Mage::helper('Mage_Newsletter_Helper_Data')->__('Cannot mark as received subscriber.')); } return $this; }
/** * Updates existing rows. * Don't use $model->where()->update($data); * * @param array $data Column-value pairs. * @param array|string $where An SQL WHERE clause, or an array of SQL WHERE clauses. * @return int The number of rows updated. * @throws new Exception( 'condition is null' ); */ public function update($data, $where) { if (!isset($where)) { throw new Exception('condition is null'); } //no data need update if (count($data) == 0) { return; } $where = $this->_translateToZendWhere($where); $rtn = $this->_adapter->update($this->_tableName, $data, $where); return $rtn; }