Beispiel #1
0
 public function drop($target)
 {
     try {
         Oops_Sql_Common::delete($this->_table, array('target' => $target));
     } catch (Oops_Sql_Exception $e) {
         self::__install($this->_table);
     }
 }
Beispiel #2
0
 /**
  * Reads config values from DB and constructs Config object
  * 
  * @param string $table
  * @param string|array $keyFields Field name(s) to use as config key. If not given table's primary key will be used
  * @param string|array $valueFields Field name(s) to use as config value. If not given all fields excluding keys will be used
  * @param string $keyDelimiter Explode keys by this delimiter and group values for each exploded part  
  */
 public function __construct($table, $keyFields = null, $valueFields = null, $keyDelimiter = '.', $allowModifications = false)
 {
     $table = Oops_Sql_Common::escapeIdentifiers($table);
     if (is_null($keyFields)) {
         $keyFields = array();
         $r = Oops_Sql::Query("SHOW COLUMNS FROM {$table}", OOPS_SQL_EXCEPTION);
         while (($row = mysql_fetch_row($r)) !== false) {
             if (strtoupper($row[3]) == 'PRI') {
                 $keyFields[] = $row[0];
             }
         }
     } else {
         Oops_Utils::ToArray($keyFields);
     }
     if (!count($keyFields)) {
         throw new Exception("No key fields for config");
     }
     if (is_null($valueFields)) {
         $sql = "SELECT * FROM {$table}";
     } else {
         Oops_Utils::ToArray($valueFields);
         $select = array_merge($keyFields, $valueFields);
         foreach ($select as $k => $v) {
             $select[$k] = Oops_Sql_Common::escapeIdentifiers($v);
         }
         $sql = 'SELECT ' . join(',', $select) . " FROM {$table}";
     }
     $r = Oops_Sql::Query($sql);
     $data = array();
     while (($row = mysql_fetch_assoc($r)) !== false) {
         $keyParts = array();
         foreach ($keyFields as $keyField) {
             $keyParts[] = $row[$keyField];
             unset($row[$keyField]);
         }
         if (count($row) == 1) {
             $row = array_pop($row);
         }
         $data[join($keyDelimiter, $keyParts)] = $row;
     }
     parent::__construct($data, $keyDelimiter, $allowModifications);
 }
Beispiel #3
0
 /**
  * 
  * @param Oops_Process_Abstract $process
  * @return bool True on success
  * @throws Oops_Process_Exception
  */
 public function set($pid, $data)
 {
     if (!strlen($pid)) {
         throw new Oops_Process_Exception("Can not store process without id", OOPS_PROCESS_EXCEPTION_NO_PID);
     }
     if (!isset($data['class'])) {
         throw new Oops_Process_Exception("Proceess class not defined", OOPS_PROCESS_EXCEPTION_NO_CLASS);
     }
     $this->_cached[$pid] = $data;
     /**
      * First store process class and state
      */
     Oops_Sql_Common::replace($this->_tableProcesses, array('pid' => $pid, 'class' => $data['class'], 'currentState' => $data['currentState']));
     /**
      * Now let's store ticket
      */
     Oops_Sql_Common::insert($this->_tableProcessTickets, array('pid' => $pid, 'serialized' => $data['ticket']));
     /**
      * Finally store process variables
      */
     foreach ($data['variables'] as $name => $value) {
         list($class, $id, $serialized) = $this->_composeData($value);
         $variable = array('pid' => $pid, 'class' => $class, 'id' => $id, 'serialized' => $serialized);
         Oops_Sql_Common::replace($this->_tableProcessData, $variable);
     }
 }
Beispiel #4
0
 public function _destroy($ses_id)
 {
     $ses_id = preg_replace('/\\W+/', '', $ses_id);
     Oops_Sql_Common::delete($this->_tableSessions, array('ses_id' => $ses_id));
     return true;
 }
Beispiel #5
0
 protected function _sqlOrderBy()
 {
     // @todo use Oops_Sql_Expressions as well, check if field exists
     $orderBy = '';
     foreach ($this->_orderBy as $f => $direction) {
         if (strpos($f, '.') !== false) {
             list($table, $field) = explode('.', $f);
             if (!isset($this->_joinedAliases[$table])) {
                 trigger_error("Invalid order field '{$f}', unknown alias '{$table}'", E_USER_WARNING);
                 continue;
             }
             if (!in_array($field, $this->{$table}->_fields)) {
                 trigger_error("Invalid order field '{$f}', unknown field '{$field}' in '{$table}'", E_USER_WARNING);
                 continue;
             }
         } elseif ($this->_useAlias) {
             $f = $this->_alias . '.' . $f;
         }
         $orderBy .= Oops_Sql_Common::escapeIdentifiers($f);
         if ($direction == self::ORDER_DESC) {
             $orderBy .= ' DESC';
         }
         $orderBy .= ', ';
     }
     if (strlen($orderBy)) {
         $orderBy = ' ORDER BY ' . substr($orderBy, 0, -2);
     }
     return $orderBy;
 }