Skip to content

Instantly share code, notes, and snippets.

@datawithdev
Forked from dberry37388/session
Created March 30, 2012 23:34

Revisions

  1. dberry37388 revised this gist Jan 23, 2012. 1 changed file with 45 additions and 16 deletions.
    61 changes: 45 additions & 16 deletions session
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,46 @@
    <?php
    <?
    /**
    * Simple task to create the session db table.
    * Date: 1/23/12
    * Time: 11:22 AM
    * Sessions DB Table Task
    *
    * Run this task to set add/remove/clear the db sessions table
    * for your app. This could be expanded in app/tasks for application specific stuff.
    *
    * @version 1.0
    * @author Daniel Berry
    * @license MIT License
    */

    namespace Fuel\Tasks;

    class Session {

    public function run()
    {
    // Will only accept the options in the array
    $option = \Cli::prompt('What would you like to do?', array('create','remove', 'clear', 'help'));

    switch($option)
    {
    case "create":
    return self::create();
    break;
    case "remove":
    return self::remove();
    break;
    case "clear":
    return self::clear();
    break;
    default:
    return self::help();
    break;
    }
    }

    /*
    * create the sessions table
    * php oil r session
    * php oil r session:create
    */
    public function run()
    public function create()
    {
    \Config::load('session', true);

    @@ -39,11 +66,13 @@ class Session {
    }
    }



    /*
    * remove the sessions table
    * php oil r session:down
    * php oil r session:remove
    */
    public function down()
    public function remove()
    {
    \Config::load('session', true);

    @@ -61,22 +90,22 @@ class Session {

    /*
    * truncate the sessions table
    * php oil r session:truncate
    * php oil r session:clear
    */
    public function truncate()
    public function clear()
    {
    \Config::load('session', true);

    // Will only accept the options in the array
    $iamsure = \Cli::prompt('Are you sure you want to truncate the sessions table?', array('y','n'));
    $iamsure = \Cli::prompt('Are you sure you want to clear the sessions table?', array('y','n'));

    if ($iamsure === 'y')
    {
    \DBUtil::truncate_table(\Config::get('session.db.table'));
    return \Cli::color("Session database table successfully truncated.", 'green');
    }

    return \Cli::color("Session database table was not truncated.", 'red');
    return \Cli::color("Session database table was not cleared.", 'red');
    }

    /**
    @@ -92,11 +121,11 @@ class Session {
    The session task will create the nessecary db tables.

    Examples:
    php oil r session
    php oil r session:down
    php oil r migrate:truncate
    php oil r session:create
    php oil r session:remove
    php oil r migrate:clear
    php oil r migrate:help

    HELP;
    }
    }
  2. dberry37388 revised this gist Jan 23, 2012. 1 changed file with 36 additions and 17 deletions.
    53 changes: 36 additions & 17 deletions session
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,10 @@ namespace Fuel\Tasks;

    class Session {

    /*
    * create the sessions table
    * php oil r session
    */
    public function run()
    {
    \Config::load('session', true);
    @@ -35,6 +39,10 @@ class Session {
    }
    }

    /*
    * remove the sessions table
    * php oil r session:down
    */
    public function down()
    {
    \Config::load('session', true);
    @@ -51,22 +59,10 @@ class Session {
    return \Cli::color("Session database table was not deleted.", 'red');
    }

    public function down()
    {
    \Config::load('session', true);

    // Will only accept the options in the array
    $iamsure = \Cli::prompt('Are you sure you want to delete the sessions table?', array('y','n'));

    if ($iamsure === 'y')
    {
    \DBUtil::drop_table(\Config::get('session.db.table'));
    return \Cli::color("Session database table deleted.", 'green');
    }

    return \Cli::color("Session database table was not deleted.", 'red');
    }

    /*
    * truncate the sessions table
    * php oil r session:truncate
    */
    public function truncate()
    {
    \Config::load('session', true);
    @@ -82,4 +78,27 @@ class Session {

    return \Cli::color("Session database table was not truncated.", 'red');
    }
    }

    /**
    * Shows basic help instructions for using migrate in oil
    */
    public static function help()
    {
    echo <<<HELP
    Usage:
    php oil refine session

    Description:
    The session task will create the nessecary db tables.

    Examples:
    php oil r session
    php oil r session:down
    php oil r migrate:truncate
    php oil r migrate:help

    HELP;
    }
    }

    /* End of file tasks/session.php */
  3. dberry37388 revised this gist Jan 23, 2012. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions session
    Original file line number Diff line number Diff line change
    @@ -66,4 +66,20 @@ class Session {

    return \Cli::color("Session database table was not deleted.", 'red');
    }

    public function truncate()
    {
    \Config::load('session', true);

    // Will only accept the options in the array
    $iamsure = \Cli::prompt('Are you sure you want to truncate the sessions table?', array('y','n'));

    if ($iamsure === 'y')
    {
    \DBUtil::truncate_table(\Config::get('session.db.table'));
    return \Cli::color("Session database table successfully truncated.", 'green');
    }

    return \Cli::color("Session database table was not truncated.", 'red');
    }
    }
  4. dberry37388 created this gist Jan 23, 2012.
    69 changes: 69 additions & 0 deletions session
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    <?php
    /**
    * Simple task to create the session db table.
    * Date: 1/23/12
    * Time: 11:22 AM
    */

    namespace Fuel\Tasks;

    class Session {

    public function run()
    {
    \Config::load('session', true);

    if (\Config::get('session.driver') === 'db')
    {
    \DBUtil::create_table(\Config::get('session.db.table'), array(
    'session_id' => array('constraint' => 40, 'type' => 'varchar'),
    'previous_id' => array('constraint' => 40, 'type' => 'varchar'),
    'user_agent' => array('type' => 'text', 'null' => false),
    'ip_hash' => array('constraint' => 32, 'type' => 'char'),
    'created' => array('constraint' => 10, 'type' => 'int', 'unsigned' => true),
    'updated' => array('constraint' => 10, 'type' => 'int', 'unsigned' => true),
    'payload' => array('type' => 'longtext'),
    ), array('session_id'), false, 'InnoDB', 'utf8');

    \DBUtil::create_index(\Config::get('session.db.table'), 'previous_id', 'previous_id', 'unique');

    return \Cli::color("Success! Your session table has been created!", 'green');
    }
    else
    {
    return \Cli::color("Oops, your driver is currently set to ".\Config::get('session.driver').'. Please set your driver type to db before continuing.', 'red');
    }
    }

    public function down()
    {
    \Config::load('session', true);

    // Will only accept the options in the array
    $iamsure = \Cli::prompt('Are you sure you want to delete the sessions table?', array('y','n'));

    if ($iamsure === 'y')
    {
    \DBUtil::drop_table(\Config::get('session.db.table'));
    return \Cli::color("Session database table deleted.", 'green');
    }

    return \Cli::color("Session database table was not deleted.", 'red');
    }

    public function down()
    {
    \Config::load('session', true);

    // Will only accept the options in the array
    $iamsure = \Cli::prompt('Are you sure you want to delete the sessions table?', array('y','n'));

    if ($iamsure === 'y')
    {
    \DBUtil::drop_table(\Config::get('session.db.table'));
    return \Cli::color("Session database table deleted.", 'green');
    }

    return \Cli::color("Session database table was not deleted.", 'red');
    }
    }