Example #1
0
 /**
  * Write a message to the log.
  *
  * @param  array  $event  event data
  * @return void
  */
 protected function _write($event)
 {
     if ($this->_columnMap === null) {
         $dataToInsert = $event;
     } else {
         $dataToInsert = array();
         foreach ($this->_columnMap as $columnName => $fieldKey) {
             $dataToInsert[$columnName] = $event[$fieldKey];
         }
     }
     $this->_db->insert($this->_table, $dataToInsert);
 }
 /**
  * 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);
 }
Example #3
0
 /**
  * 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();
         }
     }
 }
 /**
  * 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;
 }
 /**
  * Constructor
  *
  * @return void
  */
 public function __construct()
 {
     $this->db = Centreon_Db_Manager::factory('centreon');
     $res = $this->db->query("SELECT `value` FROM informations WHERE `key` = 'version'");
     $row = $res->fetch();
     $this->version = $row['value'];
     $this->params = array();
     $this->insertParams = array();
     $this->exportExcludedParams = array();
     $this->action = "";
     $this->delim = ";";
 }
Example #6
0
 /**
  * Write a message to the log.
  *
  * @param  array  $event  event data
  * @return void
  */
 protected function _write($event)
 {
     if ($this->_db === null) {
         throw new Zend_Log_Exception('Database adapter instance has been removed by shutdown');
     }
     if ($this->_columnMap === null) {
         $dataToInsert = $event;
     } else {
         $dataToInsert = array();
         foreach ($this->_columnMap as $columnName => $fieldKey) {
             $dataToInsert[$columnName] = $event[$fieldKey];
         }
     }
     $this->_db->insert($this->_table, $dataToInsert);
 }
Example #7
0
 /**
  * Write a message to the log.
  *
  * @param  array  $event  event data
  * @return void
  */
 protected function _write($event)
 {
     if ($this->_db === null) {
         throw new Log\Exception('Database adapter is null');
     }
     if ($this->_columnMap === null) {
         $dataToInsert = $event;
     } else {
         $dataToInsert = array();
         foreach ($this->_columnMap as $columnName => $fieldKey) {
             $dataToInsert[$columnName] = $event[$fieldKey];
         }
     }
     $this->_db->insert($this->_table, $dataToInsert);
 }
Example #8
0
 /**
  * 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);
 }
Example #9
0
File: Db.php Project: netixx/Stock
 /**
  * Write a message to the log.
  *
  * @param  array  $event  event data
  * @return void
  * @throws Zend_Log_Exception
  */
 protected function _write($event)
 {
     if ($this->_db === null) {
         require_once PHP_LIBRARY_PATH . 'Zend/Log/Exception.php';
         throw new Zend_Log_Exception('Database adapter is null');
     }
     if ($this->_columnMap === null) {
         $dataToInsert = $event;
     } else {
         $dataToInsert = array();
         foreach ($this->_columnMap as $columnName => $fieldKey) {
             $dataToInsert[$columnName] = $event[$fieldKey];
         }
     }
     $this->_db->insert($this->_table, $dataToInsert);
 }
Example #10
0
 /**
  * Writes an array of key/value pairs to the database, where the keys are the
  * database field names and values are what to put in those fields.
  *
  * @param array $fields
  * @return bool
  */
 public function write($fields)
 {
     /**
      * If the field defaults for 'message' and 'level' have been changed
      * in the options, replace the keys in the $field array.
      */
     if ($this->_options['fieldMessage'] != 'message') {
         $fields[$this->_options['fieldMessage']] = $fields['message'];
         unset($fields['message']);
     }
     if ($this->_options['fieldLevel'] != 'level') {
         $fields[$this->_options['fieldLevel']] = $fields['level'];
         unset($fields['level']);
     }
     /**
      * Build an array of field names and values for the SQL statement.
      */
     $fieldNames = array();
     foreach ($fields as $key => &$value) {
         /**
          * @todo needs to be updated for new database adapters
          */
         $fieldNames[] = "`" . $this->_dbAdapter->escapeString($key) . "`";
         $value = "'" . $this->_dbAdapter->escapeString($value) . "'";
         if ($value == "''") {
             $value = "NULL";
         }
     }
     /**
      * INSERT the log line into the database.  XXX Replace with Prepared Statement
      */
     /**
      * @todo needs to be updated for new database adapters
      */
     $sql = "INSERT INTO `" . $this->_dbAdapter->escapeString($this->_tableName) . "` (" . implode(', ', $fieldNames) . ') VALUES (' . implode(', ', $fields) . ')';
     // The database adapter will raise an exception if any problems occur.
     /**
      * @todo needs to be updated for new database adapters
      */
     $this->_dbAdapter->insert($sql);
     return true;
 }
Example #11
0
 /**
  * Writes an array of key/value pairs to the database, where the keys are the
  * database field names and values are what to put in those fields.
  *
  * @param array $fields
  * @return bool
  */
 public function write($fields)
 {
     /**
      * If the field defaults for 'message' and 'level' have been changed
      * in the options, replace the keys in the $field array.
      */
     if ($this->_options['fieldMessage'] != 'message') {
         $fields[$this->_options['fieldMessage']] = $fields['message'];
         unset($fields['message']);
     }
     if ($this->_options['fieldLevel'] != 'level') {
         $fields[$this->_options['fieldLevel']] = $fields['level'];
         unset($fields['level']);
     }
     /**
      * INSERT the log line into the database
      */
     $this->_dbAdapter->insert($this->_tableName, $fields);
     return true;
 }
Example #12
0
 /**
  * Remove any data associated with a tweet.
  * @param int $id
  */
 public function reset($id)
 {
     $this->adapter->delete('tweetist', array('dataset = ' . $this->dataset, 'tweet = ' . $id));
 }
 /**
  * Runs the sql query to insert record
  * 
  * @param string $tableName
  * @param array $data
  */
 public function insertRecord($tableName, array $data)
 {
     $this->dbAdapter->insert($tableName, $data);
 }
Example #14
0
 /**
  * check if user exists already in dovecot user table
  * 
  * @param  Tinebase_Model_FullUser  $_user
  */
 protected function _userExists(Tinebase_Model_FullUser $_user)
 {
     $select = $this->_getSelect();
     $select->where($this->_db->quoteIdentifier($this->_userTable . '.' . $this->_propertyMapping['emailUserId']) . ' = ?', $_user->getId());
     #if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $select->__toString());
     // Perferom query - retrieve user from database
     $stmt = $this->_db->query($select);
     $queryResult = $stmt->fetch();
     $stmt->closeCursor();
     if (!$queryResult) {
         return false;
     }
     return true;
 }
Example #15
0
 /**
  *
  * Public service for grouping treatment
  * @param Zend_Db_Adapter $adapter
  * @param string $tablePrefix
  * @param Zend_Db_Select $select
  */
 public static function traitGroup($adapter, $tablePrefix, Zend_Db_Select $select)
 {
     $group = $select->getPart(Zend_Db_Select::GROUP);
     //if (empty($group)) return;
     $order = $select->getPart(Zend_Db_Select::ORDER);
     $columns = $select->getPart(Zend_Db_Select::COLUMNS);
     try {
         //$column is an array where 0 is table, 1 is field and 2 is alias
         foreach ($columns as $column) {
             $field = implode('.', $column);
             if (!in_array($field, $group)) {
                 // replaces * by each name of column
                 if ($column[1] == '*') {
                     $tableFields = $adapter->describeTable($tablePrefix . $column[0]);
                     foreach ($tableFields as $columnName => $schema) {
                         // adds columns into group by clause (table.field)
                         // checks if field has a function (that must be an aggregation)
                         $element = "{$column[0]}.{$columnName}";
                         if (!in_array($element, $group) && !preg_match('/\\(.*\\)/', $element)) {
                             $group[] = $element;
                         }
                     }
                 } else {
                     // adds column into group by clause (table.field)
                     $element = "{$column[0]}.{$column[1]}";
                     if (!preg_match('/\\(.*\\)/', $element)) {
                         $group[] = $element;
                     } else {
                         if (substr($column[1], 0, 10) == "(CASE WHEN") {
                             $group[] = $column[1];
                         }
                     }
                 }
             }
         }
         foreach ($order as $column) {
             $field = $column[0];
             if (preg_match('/.*\\..*/', $field) && !in_array($field, $group)) {
                 // adds column into group by clause (table.field)
                 $group[] = $field;
             }
         }
         $select->reset(Zend_Db_Select::GROUP);
         $select->group($group);
     } catch (Exception $e) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Exception: ' . $e->getMessage() . ' Trace: ' . $e->getTraceAsString());
     }
     return $select;
 }
Example #16
0
 /**
  * Write a message to the log.
  *
  * @param  $message    Message to log
  * @param  $priority   Priority of message
  * @return bool        Always True
  */
 public function write($message, $priority)
 {
     $fields = array($this->_options['fieldMessage'] => $message, $this->_options['fieldPriority'] => $priority);
     $this->_db->insert($this->_table, $fields);
     return true;
 }