Skip to content

Instantly share code, notes, and snippets.

@jonathandavis
Created March 22, 2013 20:22
Show Gist options
  • Save jonathandavis/5224447 to your computer and use it in GitHub Desktop.
Save jonathandavis/5224447 to your computer and use it in GitHub Desktop.
/**
* Garbage collection routine for cleaning up old and expired
* sessions.
*
* 1.3 Added support for shopping session cold storage
*
* @author Jonathan Davis
* @since 1.1
* @version 1.3
*
* @return boolean
**/
function purge () {
if (empty($this->session)) return false;
$timeout = SHOPP_SESSION_TIMEOUT;
$now = current_time('mysql');
$meta_table = DatabaseObject::tablename('meta');
DB::query("INSERT INTO $meta_table (parent,context,type,name,value,created,modified)
SELECT session,'shopping','session','coldstorage',data,created,modified FROM $this->_table WHERE $timeout < UNIX_TIMESTAMP('$now') - UNIX_TIMESTAMP(modified) AND shopping=1");
if (!DB::query("DELETE LOW_PRIORITY FROM $this->_table WHERE $timeout < UNIX_TIMESTAMP('$now') - UNIX_TIMESTAMP(modified)"))
trigger_error("Could not delete cached session data.");
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment