From 740bcbedc0cffe640a1e33f47c0b8dbfca0766a9 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 6 Sep 2009 04:28:29 +0000 Subject: [PATCH] Integrated sandbox functionality directly into the application so that there is no need for two independent applications for both the normal and sandbox version. git-svn-id: file:///svn-source/pmgr/branches/single_site_sandbox_20090905@838 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/app_controller.php | 35 ++++++++++++++++++---------- site/app_helper.php | 8 +++++++ site/build_devbox.cmd | 5 ++++ site/config/bootstrap.php | 8 ++++++- site/config/database.php | 2 ++ site/config/routes.php | 16 +++++++++++++ site/controllers/util_controller.php | 9 ++++--- site/views/layouts/default.ctp | 4 ++++ 8 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 site/build_devbox.cmd diff --git a/site/app_controller.php b/site/app_controller.php index 8618348..393f771 100644 --- a/site/app_controller.php +++ b/site/app_controller.php @@ -251,24 +251,32 @@ class AppController extends Controller { array('controller' => 'tenders', 'action' => 'deposit'), null, 'SITE', $this->op_area); - if (sandbox()) { + $url_components = array('plugin', 'controller', 'action', 'named'); + if (devbox()) { +/* $sources = ConnectionManager::sourceList(); */ +/* $db = ConnectionManager::getDataSource($sources[0])->config['database']; */ +/* $this->sideMenuAreaName($db, 'SANDBOX', $this->std_area); */ + $this->sideMenuAreaName('DevBox', 'SANDBOX', $this->std_area); + $this->addSideMenuLink('Rebuild DevBox', + array('controller' => 'util', 'action' => 'rebuild_devbox'), null, + 'SANDBOX'); + } + elseif (sandbox()) { $this->addSideMenuLink('Rebuild Sandbox', array('controller' => 'util', 'action' => 'rebuild_sandbox'), null, 'SANDBOX'); $this->addSideMenuLink('Leave Sandbox', - ((empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . - $_SERVER['SERVER_NAME'] . - preg_replace("%^/([^/]+)\.sand%", "/$1", $_SERVER['REQUEST_URI'])), - null, - 'SANDBOX'); + array('sand_route' => false) + + array_intersect_key($this->params, array_flip($url_components)) + + $this->params['pass'], + null, 'SANDBOX'); } else { $this->addSideMenuLink('Enter Sandbox', - ((empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . - $_SERVER['SERVER_NAME'] . - preg_replace("%^/([^/]+)%", "/$1.sand", $_SERVER['REQUEST_URI'])), - null, - 'SANDBOX'); + array('sand_route' => true) + + array_intersect_key($this->params, array_flip($url_components)) + + $this->params['pass'], + null, 'SANDBOX'); } // REVISIT : 20090824 @@ -297,8 +305,11 @@ class AppController extends Controller { function beforeFilter() { $this->params['user'] = $this->Permission->User->currentUser(); - $this->params['dev'] = $this->Option->enabled('dev'); $this->params['admin'] = $this->Option->enabled('admin'); + $this->params['dev'] = devbox(); + + if ($this->params['dev'] && !$this->Option->enabled('dev')) + $this->redirect("/"); if (!$this->params['dev']) Configure::write('debug', '0'); diff --git a/site/app_helper.php b/site/app_helper.php index 1c797e3..04153e6 100644 --- a/site/app_helper.php +++ b/site/app_helper.php @@ -38,5 +38,13 @@ App::import('Core', 'Helper'); */ class AppHelper extends Helper { + function url($url = null, $full = false) { + foreach(array('sand_route', 'dev_route') AS $mod) { + if (isset($this->params[$mod]) && is_array($url) && !isset($url[$mod])) + $url[$mod] = $this->params[$mod]; + } + return parent::url($url, $full); + } + } ?> \ No newline at end of file diff --git a/site/build_devbox.cmd b/site/build_devbox.cmd new file mode 100644 index 0000000..79b99d5 --- /dev/null +++ b/site/build_devbox.cmd @@ -0,0 +1,5 @@ +@echo off +mysqldump --user=pmgr --password=pmgruser --opt property_manager > H:\pmgr_dev.sql +mysql --user=pmgr --password=pmgruser --database=pmgr_dev < H:\pmgr_dev.sql +del H:\pmgr_dev.sql +echo Build Complete! diff --git a/site/config/bootstrap.php b/site/config/bootstrap.php index 2ad4251..d03f0e3 100644 --- a/site/config/bootstrap.php +++ b/site/config/bootstrap.php @@ -33,7 +33,13 @@ */ function sandbox() { - return preg_match("%^/[^/]*sand/%", $_SERVER['REQUEST_URI']); + $r = Router::requestRoute(); + return !empty($r[3]['sand_route']); +} + +function devbox() { + $r = Router::requestRoute(); + return !empty($r[3]['dev_route']); } function server_request_var($var) { diff --git a/site/config/database.php b/site/config/database.php index c7fa35e..6cdddfa 100644 --- a/site/config/database.php +++ b/site/config/database.php @@ -12,6 +12,8 @@ class DATABASE_CONFIG { ); function __construct() { + if (devbox()) + $this->default['database'] = 'pmgr_dev'; if (sandbox()) $this->default['database'] = 'pmgr_sand'; } diff --git a/site/config/routes.php b/site/config/routes.php index 7a9ad16..6135fdd 100644 --- a/site/config/routes.php +++ b/site/config/routes.php @@ -36,4 +36,20 @@ $default_path = array('controller' => 'maps', 'action' => 'view', '1'); */ Router::connect('/', $default_path); +/* + * Route for sandbox functionality + */ +Router::connect('/sand', + array('sand_route' => true) + $default_path); +Router::connect('/sand/:controller/:action/*', + array('sand_route' => true, 'action' => null)); + +/* + * Route for developement functionality + */ +Router::connect('/dev', + array('dev_route' => true) + $default_path); +Router::connect('/dev/:controller/:action/*', + array('dev_route' => true, 'action' => null)); + ?> \ No newline at end of file diff --git a/site/controllers/util_controller.php b/site/controllers/util_controller.php index a1d975f..03aa2a4 100644 --- a/site/controllers/util_controller.php +++ b/site/controllers/util_controller.php @@ -32,16 +32,16 @@ class UtilController extends AppController { /************************************************************************** ************************************************************************** ************************************************************************** - * function: rebuild_sandbox + * function: rebuild_box */ - function rebuild_sandbox() { + function rebuild_box($type) { $this->layout = null; $this->autoLayout = false; $this->autoRender = false; Configure::write('debug', '0'); $script = preg_replace('%/webroot/index.php$%', - '/build_sandbox.cmd', + '/build_'.$type.'box.cmd', $_SERVER['SCRIPT_FILENAME']); // REVISIT : 20090828 @@ -59,4 +59,7 @@ class UtilController extends AppController { $this->redirect($url); } + function rebuild_sandbox() { $this->rebuild_box('sand'); } + function rebuild_devbox() { $this->rebuild_box('dev'); } + } diff --git a/site/views/layouts/default.ctp b/site/views/layouts/default.ctp index 94de8f0..f849b13 100644 --- a/site/views/layouts/default.ctp +++ b/site/views/layouts/default.ctp @@ -34,9 +34,11 @@ charset(); ?> + <?php if (devbox()) echo "*DEVBOX* "; ?> <?php if (sandbox()) echo "*SANDBOX* "; ?> Property Manager: <?php echo $title_for_layout; ?> <?php if (sandbox()) echo " *SANDBOX*"; ?> + <?php if (devbox()) echo " *DEVBOX*"; ?>