コード例 #1
0
 /**
  * Remove anything that is older than 15 minutes, we only want to keep 15 
  * minutes worth of history
  */
 public function cleanup()
 {
     $config = Config::get('cron');
     $minutes = isset($config['save_time']) ? $config['save_time'] : 15;
     $startDate = new \DateTime();
     $startDate->modify("-{$minutes} minutes");
     $sql = "DELETE FROM `virge_cron_job` WHERE `finished_on` <= ?";
     Database::query($sql, $startDate);
 }
コード例 #2
0
ファイル: Model.php プロジェクト: siosphere/virge-orm
 /**
  * Get the table definition as an associative array
  * @return array|null
  */
 public function _getDef()
 {
     if (isset(self::$_globalTableData[$this->_table])) {
         return $this->_tableData = self::$_globalTableData[$this->_table];
     }
     if (!isset($this->_table) || $this->_table === '') {
         return;
     }
     //load from cache
     /*if(Cache::data('mysql:def:' . get_class($this))){
           return Cache::data('mysql:def:' . get_class($this));
       }*/
     $sql = "SHOW COLUMNS FROM `{$this->_table}`";
     $result = Database::connection($this->_connection)->query($sql);
     if ($result) {
         foreach ($result as $row) {
             $field_name = $row['Field'];
             $primary = false;
             if ($row['Key'] == 'PRI') {
                 $primary = true;
             }
             $type = $row['Type'];
             $this->_tableData[] = array('field_name' => $field_name, 'type' => $type, 'primary' => $primary);
         }
         return self::$_globalTableData[$this->_table] = $this->_tableData;
         //Cache::data('mysql:def:' . get_class($this), $this->_tableData);
     }
     return NULL;
 }
コード例 #3
0
 /**
  * Ping the database connection
  * @return bool
  */
 public function ping()
 {
     return Database::connection('default')->ping();
 }
コード例 #4
0
ファイル: SchemaService.php プロジェクト: siosphere/virge-db
 /**
  * Log that the migration happened
  * TODO: use the virge ORM
  * @param string $file
  */
 public function logMigration($file)
 {
     $user = get_current_user();
     $sql = "INSERT INTO `virge_migration` (`filename`, `executed_by`, `executed_on`, `summary`) VALUES (?, ?, ?, ?)";
     Database::query($sql, array($file, $user, new \DateTime(), Schema::$last_response));
 }
コード例 #5
0
ファイル: Schema.php プロジェクト: siosphere/virge-db
 /**
  * Finish out our schema change by adding any indexes, and foreign keys
  */
 public static function finish()
 {
     foreach (self::$references as $reference) {
         Database::connection(self::$connection)->query($reference->getQuery());
     }
 }
コード例 #6
0
ファイル: Collection.php プロジェクト: siosphere/virge-orm
 /**
  * Prepare a statement
  * @param string $query
  * @return mixed
  * @throws InvalidQueryException
  */
 protected function _prepare($query)
 {
     $i = 0;
     foreach ($this->getParameters() as $parameter) {
         $field = 'field' . $i;
         ${$field} = $parameter['value'];
         $paramValues[] = ${$field};
         $i++;
     }
     $stmt = Database::connection($this->connection)->prepare($query, $paramValues);
     if (!$stmt) {
         throw new InvalidQueryException('Failed to prepare statement: ' . $query);
     }
     return $stmt;
 }