/** * Move down/up setting into the table */ public function reorder($setting, $table, $sens) { global $logger; $cur_id = $setting->id; $other_id = $sens == 'up' ? $cur_id - 1 : $cur_id + 1; $oTable = new Zend_Db_Table($table); $where_cur = $oTable->getAdapter()->quoteInto('id = ?', $cur_id); $where_other = $oTable->getAdapter()->quoteInto('id = ?', $other_id); $where_tmp = $oTable->getAdapter()->quoteInto('id = ?', 999); $oTable->update(array('id' => 999), $where_cur); $oTable->update(array('id' => $cur_id), $where_other); $result = $oTable->update(array('id' => $other_id), $where_tmp); $logger->log("Reorder setting {$table}={$setting->id} {$sens}", Zend_Log::INFO); return $result; }
/** * Saves the properties to the database. * * This performs an intelligent insert/update, and reloads the * properties with fresh data from the table on success. * * @return int 0 on failure, 1 on success. */ public function save() { // convenience var for the primary key name $primary = $this->_info['primary']; // check the primary key value for insert/update if (empty($this->_data[$primary])) { // no primary key value, must be an insert. // make sure it's null. $this->_data[$primary] = null; // attempt the insert. $result = $this->_table->insert($this->_data); if (is_numeric($result)) { // insert worked, refresh with data from the table $this->_data[$primary] = $result; $this->_refresh(); } // regardless of success return the result return $result; } else { // has a primary key value, update only that key. $where = $this->_db->quoteInto("{$primary} = ?", $this->_data[$primary]); // return the result of the update attempt, // no need to update the row object. $result = $this->_table->update($this->_data, $where); if (is_int($result)) { // update worked, refresh with data from the table $this->_refresh(); } } }
public function update(array $data, $where) { if (empty($data['updated_at'])) { $data['updated_at'] = date('Y-m-d h:i:s'); } return parent::update($data, $where); }
public function updateAd(array $data, $id) { $table = new Zend_Db_Table('ads'); $fields = $table->info(Zend_Db_Table_Abstract::COLS); foreach ($data as $field => $value) { if (!in_array($field, $fields)) { unset($data[$field]); } } return $table->update($data, 'id = ' . (int) $id); }
public function update($id, array $data, $log = true) { $data['updated_at'] = get_time(); if (is_session('user_id')) { $data['updated_by'] = get_session('user_id'); } $where = $this->getAdapter()->quoteInto('id = ?', $id); parent::update($data, $where); if ($log) { log_sql($this->_name, $id, 'updated', $data); set_session('notice', 'current record saved'); } }
/** * Save object in DB * * @return HumanHelp_Model_Comment */ public function save() { $table = new Zend_Db_Table('comments'); if (isset($this->_id)) { // Update $table->update($this->_data, $table->getAdapter()->quoteInto('id = ?', $this->_id)); } else { // Insert $table->insert($this->_data); $this->_id = $table->getAdapter()->lastInsertId('comments', 'id'); } return $this; }
/** * Overwrites the update method to allow the second param ($where clause) * to be null, which would then generate the where clause with the values * of the primary keys * * @param array $data * @param mixed $where * @return result from update */ public function update(array $data, $where) { if (is_null($where)) { $primary = is_array($this->_primary) ? $this->_primary : array($this->_primary); foreach ($primary as $key) { if (!is_null($where)) { $where .= ' AND '; } if (!isset($data[$key])) { throw new Ot_Exception_Input("Primary key {$key} not set"); } $where .= $this->getAdapter()->quoteInto($key . ' = ?', $data[$key]); } } return parent::update($data, $where); }
/** * Save a metadata value, will update the row if it exists, otherwise insert. * * @param MetadataDao $metadataDao * @return bool * @throws Zend_Exception */ public function saveMetadataValue($metadataDao) { if (!$metadataDao instanceof MetadataDao) { throw new Zend_Exception('Should be a metadata.'); } $cols = array('metadata_id' => $metadataDao->getKey(), 'itemrevision_id' => $metadataDao->getItemrevisionId()); $data['value'] = $metadataDao->getValue(); $tablename = $this->getTableValueName($metadataDao->getMetadatatype()); $table = new Zend_Db_Table(array('name' => $tablename, 'primary' => 'metadata_id')); if ($this->getMetadataValueExists($metadataDao)) { $wheres = array(); foreach ($cols as $col => $val) { $wheres[$col . '=?'] = $val; } $table->update($data, $wheres); } else { foreach ($cols as $col => $val) { $data[$col] = $val; } $table->insert($data); } return true; }
public function update(array $data) { $table = new Zend_Db_Table('users'); $where = $table->getAdapter()->quoteInto('id= ?', (int) $data['id']); $table->update($data, $where); }
/** * 按ID更改新闻信息 * * @param array $arrayUpdate * @param int $id */ public function update($arrayUpdate, $id, $isCleanCache = true) { try { //开启事务 $this->getAdapter()->beginTransaction(); //如果需要删除缓存 if ($isCleanCache) { //清除指定标识的缓存 $this->_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array(strtolower($this->_name))); $this->_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array(strtolower($this->_name . '_findById_' . $id))); } //指定查询条件 $where = $this->getAdapter()->quoteInto('id = ?', $id); //调用父类方法更改数据 parent::update($arrayUpdate, $where); //提交查询 $this->getAdapter()->commit(); } catch (Zend_Exception $e) { echo $e->getMessage(); //如果出错则事务回滚 $this->getAdapter()->rollBack(); } }
public function update(array $data, $where) { $metadata = $this->info(); $columns = $metadata['cols']; $timestamp = date("Y-m-d H:i:s"); if (in_array('updated_on', $columns)) { if (!in_array('updated_on', $data)) { $data['updated_on'] = $timestamp; } } $params = array("data" => $data, "where" => $where, "errors" => $this->_errors, "table" => $this->_name, "module" => $this->_module_id, "primary" => $this->_primary); if (isset($this->_use_adapter)) { $params['use_adapter'] = $this->_use_adapter; } else { $params['use_adapter'] = null; } // rethrowing exceptions here because of a weird php issue where the trace isn't getting passed try { $params = Bolts_Plugin::getInstance()->doFilter('db_table_update', $params); } catch (Exception $e) { throw $e; } if (count($params['errors']) == 0) { return parent::update($params['data'], $params['where']); } else { $this->_errors = $params['errors']; return false; } }
/** * mark a thread as read by setting the unread counter to zero * * @param thread_id */ public function markAsRead($id, $user_id) { if (!$id) { return null; } $threads_table = new Zend_Db_Table('threads'); $data = array('unread' => '0'); $where = array('id = ?' => $id, 'last_speaker != ?' => $user_id); $threads_table->update($data, $where); }
/** * Switching trigger statuses according to plugin status * @param $pluginName Name of plugin * @param $status Plugin status * @return Application_Model_Mappers_EmailTriggersMapper */ public function toggleTriggersStatuses($pluginName, $status) { $triggers = $this->_getTriggers($pluginName); if (!empty($triggers)) { $triggersTable = new Zend_Db_Table('email_triggers'); $triggersTable->getAdapter()->beginTransaction(); foreach ($triggers as $trigger) { $triggersTable->update(array('enabled' => $status == Application_Model_Models_Plugin::DISABLED ? self::TRIGGER_STATUS_DISABLED : self::TRIGGER_STATUS_ENABLED), array('trigger_name = ?' => $trigger['trigger_name'], 'observer = ?' => $trigger['observer'])); } $triggersTable->getAdapter()->commit(); } return $this; }
public function _update() { parent::update($this->attributes, $this->siteDbAdapter->quoteInto($this->pkname . ' = ?', $this->pk)); return $this->pk; }
public function update(array $data, $where) { // add a timestamp /* if (empty($data['update_date'])) { $data['update_date'] = time(); } */ //$id = $this->getMasterAdapter(); $this->_db = CrFramework_Db_Control::getAdapter('write'); $this->setDefaultAdapter($this->_db); return parent::update($data, $where); }
public function update(array $data, $where) { /* password hash */ if (!empty($data['pwd'])) { $data['pwd'] = $this->_hasher->HashPassword($data['pwd']); if (strlen($data['pwd']) < 20) { throw new Exception(__METHOD__ . ' : "Internal error. Failed to hash new password"'); } } parent::update($data, $where); }
/** * 根据数组,更新id所在行数据 * param array $set 更新数组,下标为字段名,值为字段值 * param int or array $id 条件值 * param string $whereField 条件字段名 * @see Zend_Db_Table_Abstract::update() * @return boolean 更新成功返回true,否则false */ public function update(array $set, $id, $whereField = 'id') { if (is_array($id)) { //过滤id值 $db = $this->getDefaultAdapter(); $quoteId = $db->quoteInto(' in (?)', $id); //构造where条件 $where = $whereField . $quoteId; //$where = $whereField . ' in (' . implode(',', $id) . ')'; //用db引用之前写法 } else { $where = $whereField . ' = ' . intval($id); } $affectedRows = parent::update($set, $where); return $affectedRows ? true : false; }
/** * Обновляем раздел * @param array $data * @param array|string $data SQL WHERE запрос * @return ID обновлённой записи */ public function updateSection(array $data, $where) { return $this->_modelItems->update($data, $where); }
public function update(array $data, $where) { $row = $this->fetchRow($where); if (empty($data['inherit_id'])) { $data['inherit_id'] = null; } // Не должно быть : role id != inherit_id в одной и той же записи if (isset($row->id) && isset($data['inherit_id'])) { if ($row->id == $data['inherit_id']) { $translate = Zend_Registry::get('translate'); throw new Zend_Exception($translate->_('Role Id and Inherited Role Id must not be identical')); return 0; } } return parent::update($data, $where); }
/** * Updates existing rows. * * @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. */ public function update(array $data, $where) { return parent::update($data, $where); }
/** * update data overloaded to log the action */ public function update(array $data, $where) { $toreturn = parent::update($data, $where); if ($toreturn > 0) { $this->log('UPDATE:' . $toreturn . ' row(s) updated'); } else { $this->log('UPDATE:no row(s) updated', Zend_Log::ERR); } return $toreturn; }
public function update(array $data, $where) { $data = $this->_cleanData($data); $response = parent::update($data, $where); return $response; }
protected function setSystemAccessLog(&$data) { if ($this->_logAccess === 0 || !$data->use_id || isset($data->access_id)) { return $this; } require_once realpath(APPLICATION_PATH . '/../vendor/phpsniff-2.1.3/phpSniff.class.php'); $_sniff = new phpSniff(); $clientInfo = $_sniff->property(); /** * @see Ht/Utils/Generater.php */ try { Zend_Loader::loadClass("Ht_Utils_Generater"); Zend_Loader::loadClass("Ht_Utils_Generater_Id"); $generator = new Ht_Utils_Generater_Id(array(Ht_Utils_Generater::GENERATED_DIGIT32, Ht_Utils_Generater::GENERATED_INCLUDE_NUMBER, Ht_Utils_Generater::GENERATED_USE_LOWERLETTER, Ht_Utils_Generater::GENERATED_USE_UPPERLETTER)); $access_id = $generator->getGeneratedId(); } catch (Exception $exc) { echo $exc->getMessage(), "<hr />"; echo $exc->getTraceAsString(); } $row = array("access_id" => $access_id, "acc_id" => $data->u_id, "login_time" => new Zend_Db_Expr("NOW()"), "acc_ip" => $clientInfo["ip"], "acc_agent" => $clientInfo["ua"], "acc_browser" => $clientInfo["long_name"], "acc_os" => $clientInfo["os"]); unset($_sniff, $clientInfo); try { $sysaccess = new Default_Model_DbTable_SysAccess(); $sysaccess->insert($row); $user = new Zend_Db_Table('ht_user'); $where = $user->getAdapter()->quoteInto("use_id =?", $data->use_id); $user->update(array("use_lastlogin" => new Zend_Db_Expr("NOW()")), $where); } catch (Exception $exc) { $data->access_id = $access_id; return $this; } $data->access_id = $access_id; return $this; }
public function logoutAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $auth = Zend_Auth::getInstance(); $identity = $auth->getIdentity(); try { $sysaccess = new Zend_Db_Table(array('name' => 'sys_access')); $sysaccess->update(array("logout_time" => new Zend_Db_Expr("NOW()")), $sysaccess->getAdapter()->quoteInto("access_id=?", $identity->access_id)); $this->_dispatcher->notify(new sfEvent($this, 'authentication.log', array('message' => array(sprintf('`%s` logout success.', trim($identity->use_name . ' ' . $identity->use_lastname))), 'priority' => Zend_Log::INFO))); $auth->clearIdentity(); } catch (Exception $e) { $this->_dispatcher->notify(new sfEvent($this, 'authentication.log', array('message' => array(sprintf('`%s` logout error.', trim($identity->use_name . ' ' . $identity->use_lastname)), $e->getMessage()), 'priority' => Zend_Log::ERR))); } $this->_redirect($this->_baseUrl); }