/** * Support method for fetching rows. * * @param string $type Whether to fetch 'all' or 'row'. * @param string|array $where An SQL WHERE clause. * @param string|array $order An SQL ORDER clause. * @param int $count An SQL LIMIT count. * @param int $offset An SQL LIMIT offset. * @return mixed The row results per the Zend_Db_Adapter fetch mode. */ protected function _fetch($type, $where = null, $order = null, $count = null, $offset = null) { // selection tool $select = $this->_db->select(); // the FROM clause $select->from($this->_name, array_keys($this->_cols)); // the WHERE clause $where = (array) $where; foreach ($where as $key => $val) { // is $key an int? if (is_int($key)) { // $val is the full condition $select->where($val); } else { // $key is the condition with placeholder, // and $val is quoted into the condition $select->where($key, $val); } } // the ORDER clause $order = (array) $order; foreach ($order as $val) { $select->order($val); } // the LIMIT clause $select->limit($count, $offset); // return the results $method = "fetch{$type}"; return $this->_db->{$method}($select); }
/** * get the basic select object to fetch records from the database * * @param array|string|Zend_Db_Expr $_cols columns to get, * per default * @param boolean $_getDeleted get deleted records (if modlog is active) * @return Zend_Db_Select */ protected function _getSelect($_cols = '*', $_getDeleted = FALSE) { $select = $this->_db->select()->from($this->_userTable); if ($this->_hasTine20Userid === true) { $select->where($this->_db->quoteIdentifier($this->_propertyMapping['emailGID']) . ' = ?', $this->_config['emailGID'])->limit(1); } else { $select->where($this->_db->quoteIdentifier($this->_propertyMapping['emailGID']) . ' = ?', $this->_convertToInt($this->_config['emailGID']))->limit(1); } return $select; }
/** * Write a message to the log. * * @param array $event event data * @return void * @throws Zend_Log_Exception */ protected function _write($event) { $config = Zend_Registry::get('config'); $isLogMsg = (bool) $config['logging']['log']['enable']; $isLogStat = (bool) $config['logging']['statistics']['enable']; $isLogEx = (bool) $config['logging']['exeption']['enable']; // Проверим возможность логирования if ($this->_table == 'log_msg' && !$isLogMsg) { return; } elseif ($this->_table == 'log_stat' && !$isLogStat) { return; } elseif ($this->_table == 'log_error' && !$isLogEx) { return; } // Удалим лишние записи if ($this->_max_rows && $this->_max_rows !== -1) { $select = $this->_db->select(); $select->from($this->_table, 'count(*)'); $count_rows = (int) $this->_db->fetchOne($select); if ($count_rows >= $this->_max_rows) { // Получим массив ids для удаления строк в таблице $limit = $count_rows - $this->_max_rows; $limit++; $select = $this->_db->select(); $select->from($this->_table, 'id'); $select->limit($limit, 0); $row_ids = $this->_db->fetchCol($select); // Удалим строки из таблицы foreach ($row_ids as $id) { $this->_db->delete($this->_table, 'id=' . $id); } } } // Запишем событие в лог parent::_write($event); }
/** * get the basic select object to fetch records from the database * * @param array|string|Zend_Db_Expr $_cols columns to get, * per default * @param boolean $_getDeleted get deleted records (if modlog is active) * @return Zend_Db_Select * * SELECT dovecot_users.*, dovecot_quotas.mail_quota, dovecot_quotas.mail_size, dovecot_quotas.sieve_quota, dovecot_quotas.sieve_size * FROM dovecot_users * LEFT JOIN dovecot_quotas * ON (dovecot_users.username=dovecot_quotas.username) * WHERE dovecot_users.userid = $_userId * LIMIT 1 */ protected function _getSelect($_cols = '*', $_getDeleted = FALSE) { $select = $this->_db->select()->from(array($this->_userTable))->joinLeft(array($this->_quotasTable), '(' . $this->_db->quoteIdentifier($this->_userTable . '.' . $this->_propertyMapping['emailUsername']) . ' = ' . $this->_db->quoteIdentifier($this->_quotasTable . '.' . $this->_propertyMapping['emailUsername']) . ')', array($this->_propertyMapping['emailMailSize'] => $this->_quotasTable . '.' . $this->_propertyMapping['emailMailSize'], $this->_propertyMapping['emailSieveSize'] => $this->_quotasTable . '.' . $this->_propertyMapping['emailSieveSize']))->limit(1); // append domain if set or domain IS NULL if (array_key_exists('domain', $this->_config) && !empty($this->_config['domain'])) { $select->where($this->_db->quoteIdentifier($this->_userTable . '.' . 'domain') . ' = ?', $this->_config['domain']); } else { $select->where($this->_db->quoteIdentifier($this->_userTable . '.' . 'domain') . " = ''"); } return $select; }
/** * get the basic select object to fetch records from the database * * @param array|string|Zend_Db_Expr $_cols columns to get, * per default * @param boolean $_getDeleted get deleted records (if modlog is active) * @return Zend_Db_Select */ protected function _getSelect($_cols = '*', $_getDeleted = FALSE) { // _userTable.emailUserId=_destinationTable.emailUserId $userIDMap = $this->_db->quoteIdentifier($this->_userTable . '.' . $this->_propertyMapping['emailUserId']); $userEmailMap = $this->_db->quoteIdentifier($this->_userTable . '.' . $this->_propertyMapping['emailAddress']); $select = $this->_db->select()->from($this->_userTable)->group($this->_userTable . '.userid')->limit(1); // select source from alias table $select->joinLeft(array('aliases' => $this->_destinationTable), '(' . $userIDMap . ' = ' . $this->_db->quoteIdentifier('aliases.' . $this->_propertyMapping['emailUserId']) . ' AND ' . $userEmailMap . ' = ' . $this->_db->quoteIdentifier('aliases.' . $this->_propertyMapping['emailForwards']) . ')', array($this->_propertyMapping['emailAliases'] => Tinebase_Backend_Sql_Command::getAggregateFunction($this->_db, $this->_db->quoteIdentifier('aliases.' . $this->_propertyMapping['emailAliases'])))); // Select // select destination from alias table $select->joinLeft(array('forwards' => $this->_destinationTable), '(' . $userIDMap . ' = ' . $this->_db->quoteIdentifier('forwards.' . $this->_propertyMapping['emailUserId']) . ' AND ' . $userEmailMap . ' = ' . $this->_db->quoteIdentifier('forwards.' . $this->_propertyMapping['emailAliases']) . ')', array($this->_propertyMapping['emailForwards'] => Tinebase_Backend_Sql_Command::getAggregateFunction($this->_db, $this->_db->quoteIdentifier('forwards.' . $this->_propertyMapping['emailForwards'])))); // Select // append domain if set or domain IS NULL if (!empty($this->_clientId)) { $select->where($this->_db->quoteIdentifier($this->_userTable . '.client_idnr') . ' = ?', $this->_clientId); } else { $select->where($this->_db->quoteIdentifier($this->_userTable . '.client_idnr') . ' IS NULL'); } return $select; }