Permalink
Browse files

Made Caffeine CLI aware, refactoring db module to be more reliable, a…

…dding CLI support to db module.
  • Loading branch information...
1 parent e0747ad commit 4133fe3bc8d2aeb4348624bfced557dcd59a7b03 @geekforbrains committed Mar 15, 2012
View
@@ -3,17 +3,32 @@
class Db_DbController extends Controller {
/**
- * Used for running database updates and installs through the browser by accessing
- * the route "db/install". Installing must be enabled in the config in order for this
- * to run, otherwise 404 is returned.
+ * TODO
*/
- public static function install()
+ public static function runner($cmd, $force = false)
{
- if(Config::get('db.install'))
+ $force = ($force == 'force') ? true : false;
+
+ if(Config::get('db.enable_url_runner'))
{
- Db::install();
- echo '<h1>Installing/Updating Database</h1>';
- Dev::outputDebug();
+ switch($cmd)
+ {
+ case 'install':
+ Db_Runner::install($force);
+ break;
+
+ case 'update':
+ Db_Runner::update();
+ break;
+
+ case 'seed':
+ Db_Runner::seed();
+ break;
+
+ default:
+ die('Invalid command, must be install, update or seed.');
+ }
+
exit();
}
else
View
@@ -34,10 +34,13 @@ public static function query($sql, $bindings = array(), $getInsertId = true, $cl
}
else
{
- if(stripos($sql, 'SELECT') === 0 || stripos($sql, 'DESCRIBE') === 0)
+ if(stripos($sql, 'SHOW TABLES') === 0)
+ return $query->fetchAll(); // Always return show tables as an array
+
+ elseif(stripos($sql, 'SELECT') === 0 || stripos($sql, 'DESCRIBE') === 0)
return $query->fetchAll(PDO::FETCH_CLASS, $class);
- elseif(stripos($sql, 'UPDATE') === 0 || stripos($sql, 'DELETE') === 0 || stripos($sql, 'SHOW TABLES') === 0)
+ elseif(stripos($sql, 'UPDATE') === 0 || stripos($sql, 'DELETE') === 0)
return $query->rowCount();
elseif($result && $getInsertId)
@@ -60,14 +63,6 @@ public static function query($sql, $bindings = array(), $getInsertId = true, $cl
public static function table($table) {
return new Db_Query($table);
}
-
- public static function install()
- {
- if(!Config::get('db.install'))
- return;
-
- Db_Installer::init();
- }
/**
* Creates a PDO connection based on configs.
View
@@ -0,0 +1,12 @@
+<?php
+
+/**
+ * Loads a driver from the drivers/ dir based on configs.
+ * That class is then extended by the installer, updater and seeder
+ *
+ * TODO Add more driver support (postgre, sqlite etc.)
+ */
+if(Config::get('db.driver'))
+ require_once(ROOT . 'core/db/drivers/mysql' . EXT);
+else
+ die('Invalid database driver "' . Config::get('db.driver') . '" in your setup.php file.');
Oops, something went wrong.

0 comments on commit 4133fe3

Please sign in to comment.