From 27fdb1e3f54e354ca13b357922601be9e0d5ee7c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 24 Jan 2012 15:02:51 -0600 Subject: [PATCH] added key and session tasks. --- laravel/cli/dependencies.php | 11 ++++ laravel/cli/tasks/session.php | 69 ++++++++++++++++++++++ laravel/core.php | 1 + laravel/database/schema.php | 1 - laravel/database/schema/grammars/mysql.php | 2 +- laravel/database/schema/table.php | 4 +- laravel/session.php | 2 +- 7 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 laravel/cli/tasks/session.php diff --git a/laravel/cli/dependencies.php b/laravel/cli/dependencies.php index a4e112ec..f7e5969f 100644 --- a/laravel/cli/dependencies.php +++ b/laravel/cli/dependencies.php @@ -35,6 +35,17 @@ return new Tasks\Key; }); +/** + * The session task is responsible for performing tasks related + * to the session store of the application. It can do things + * such as generating the session table or clearing expired + * sessions from storage. + */ +IoC::singleton('task: session', function() +{ + return new Tasks\Session; +}); + /** * The bundle repository is responsible for communicating with * the Laravel bundle sources to get information regarding any diff --git a/laravel/cli/tasks/session.php b/laravel/cli/tasks/session.php new file mode 100644 index 00000000..73b6dfd5 --- /dev/null +++ b/laravel/cli/tasks/session.php @@ -0,0 +1,69 @@ +create(); + + // The session table consists simply of a ID, a UNIX timestamp to + // indicate the expiration time, and a blob field which will hold + // the serialized form of the session payload. + $table->string('id')->length(40)->primary('session_primary'); + + $table->integer('last_activity'); + + $table->text('data'); + }); + + // By default no session driver is specified in the configuration. + // Since the developer is requesting that the session table be + // created on the database, we'll set the driver to database + // to save an extra step for the developer. + $config = File::get(APP_PATH.'config/session'.EXT); + + $config = str_replace("'driver' => '',", "'driver' => 'database',", $config); + + File::put(APP_PATH.'config/session'.EXT, $config); + + echo "The table has been created! Database set as session driver."; + } + + /** + * Sweep the expired sessions from storage. + * + * @param array $arguments + * @return void + */ + public function sweep($arguments = array()) + { + $driver = \Laravel\Session::factory(Config::get('session.driver')); + + // If the driver implements the "Sweeper" interface, we know that + // it can sweep expired sessions from storage. Not all drivers + // need be sweepers, as stores like Memcached and APC will + // perform their own garbage collection. + if ($driver instanceof Sweeper) + { + $lifetime = Config::get('session.lifetime'); + + $driver->sweep(time() - ($lifetime * 60)); + } + + echo "The session table has been swept!"; + } + +} \ No newline at end of file diff --git a/laravel/core.php b/laravel/core.php index 84e58f51..fab9b058 100644 --- a/laravel/core.php +++ b/laravel/core.php @@ -92,6 +92,7 @@ 'Laravel\\CLI\\Tasks\\Migrate\\Resolver' => SYS_PATH.'cli/tasks/migrate/resolver'.EXT, 'Laravel\\CLI\\Tasks\\Migrate\\Database' => SYS_PATH.'cli/tasks/migrate/database'.EXT, 'Laravel\\CLI\\Tasks\\Key' => SYS_PATH.'cli/tasks/key'.EXT, + 'Laravel\\CLI\\Tasks\\Session' => SYS_PATH.'cli/tasks/session'.EXT, 'Laravel\\Database\\Connection' => SYS_PATH.'database/connection'.EXT, 'Laravel\\Database\\Expression' => SYS_PATH.'database/expression'.EXT, diff --git a/laravel/database/schema.php b/laravel/database/schema.php index d36df3ef..15767f28 100644 --- a/laravel/database/schema.php +++ b/laravel/database/schema.php @@ -29,7 +29,6 @@ public static function table($table, $callback) */ public static function execute($table) { - die('here'); foreach ($table->commands as $command) { $connection = DB::connection($table->connection); diff --git a/laravel/database/schema/grammars/mysql.php b/laravel/database/schema/grammars/mysql.php index 89bd1b95..2927237e 100644 --- a/laravel/database/schema/grammars/mysql.php +++ b/laravel/database/schema/grammars/mysql.php @@ -144,7 +144,7 @@ protected function incrementer(Table $table, Fluent $column) */ public function primary(Table $table, Fluent $command) { - return $this->key($table, $command, 'PRIMARY KEY'); + return $this->key($table, $command->name(null), 'PRIMARY KEY'); } /** diff --git a/laravel/database/schema/table.php b/laravel/database/schema/table.php index cbaf505e..81516797 100644 --- a/laravel/database/schema/table.php +++ b/laravel/database/schema/table.php @@ -67,7 +67,7 @@ public function create() * @param string $name * @return Fluent */ - public function primary($columns, $name) + public function primary($columns, $name = null) { return $this->key(__FUNCTION__, $columns, $name); } @@ -148,7 +148,7 @@ public function drop_column($columns) * @param string $name * @return void */ - public function drop_primary($name) + public function drop_primary($name = null) { return $this->drop_key(__FUNCTION__, $name); } diff --git a/laravel/session.php b/laravel/session.php index cc83ee5c..d2253834 100644 --- a/laravel/session.php +++ b/laravel/session.php @@ -38,7 +38,7 @@ public static function start($driver) * @param string $driver * @return Driver */ - protected static function factory($driver) + public static function factory($driver) { switch ($driver) {