Example #1
0
 /**
  * gc
  *
  * @param string $past
  *
  * @return  bool
  */
 public function gc($past)
 {
     $query = $this->db->getQuery(true);
     $query->delete($this->db->quoteName($this->options['table']))->where($this->db->quoteName($this->options['time_col']) . ' < ' . $this->db->quote((int) $past));
     // Remove expired sessions from the database.
     $this->db->setQuery($query);
     return (bool) $this->db->execute();
 }
Example #2
0
 /**
  * Garbage collect stale sessions from the SessionHandler backend.
  *
  * @param   integer  $lifetime  The maximum age of a session.
  *
  * @return  boolean  True on success, false otherwise.
  *
  * @since   1.0
  */
 public function gc($lifetime = 1440)
 {
     // Determine the timestamp threshold with which to purge old sessions.
     $past = time() - $lifetime;
     try {
         $query = $this->db->getQuery(true);
         $query->delete($this->db->quoteName('#__session'))->where($this->db->quoteName('time') . ' < ' . $this->db->quote((int) $past));
         // Remove expired sessions from the database.
         $this->db->setQuery($query);
         return (bool) $this->db->execute();
     } catch (\Exception $e) {
         return false;
     }
 }
Example #3
0
 /**
  * Merges the incoming structure definition with the existing structure.
  *
  * @return  void
  *
  * @note    Currently only supports XML format.
  * @since   1.0
  * @throws  \RuntimeException on error.
  */
 public function mergeStructure()
 {
     $tables = $this->db->getTableList();
     if ($this->from instanceof \SimpleXMLElement) {
         $xml = $this->from;
     } else {
         $xml = new \SimpleXMLElement($this->from);
     }
     // Get all the table definitions.
     $xmlTables = $xml->xpath('database/table_structure');
     foreach ($xmlTables as $table) {
         // Convert the magic prefix into the real table name.
         $tableName = $this->getRealTableName((string) $table['name']);
         if (in_array($tableName, $tables)) {
             // The table already exists. Now check if there is any difference.
             if ($queries = $this->getAlterTableql($xml->database->table_structure)) {
                 // Run the queries to upgrade the data structure.
                 foreach ($queries as $query) {
                     $this->db->setQuery((string) $query);
                     try {
                         $this->db->execute();
                     } catch (\RuntimeException $e) {
                         $this->db->log(LogLevel::DEBUG, 'Fail: ' . $this->db->getQuery());
                         throw $e;
                     }
                     $this->db->log(LogLevel::DEBUG, 'Pass: '******'Fail: ' . $this->db->getQuery());
                 throw $e;
             }
             $this->db->log(LogLevel::DEBUG, 'Pass: ' . $this->db->getQuery());
         }
     }
 }