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
This commit is contained in:
abijah
2009-09-06 04:28:29 +00:00
parent 7a2034aea0
commit 740bcbedc0
8 changed files with 71 additions and 16 deletions

View File

@@ -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 <AP>: 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');

View File

@@ -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);
}
}
?>

5
site/build_devbox.cmd Normal file
View File

@@ -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!

View File

@@ -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) {

View File

@@ -12,6 +12,8 @@ class DATABASE_CONFIG {
);
function __construct() {
if (devbox())
$this->default['database'] = 'pmgr_dev';
if (sandbox())
$this->default['database'] = 'pmgr_sand';
}

View File

@@ -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));
?>

View File

@@ -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 <AP>: 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'); }
}

View File

@@ -34,9 +34,11 @@
<head>
<?php echo $html->charset(); ?>
<title>
<?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*"; ?>
</title>
<?php
// Reset the __scripts variable, which has already been dumped to
@@ -66,6 +68,8 @@
$theme = 'dotluv';
$theme = 'dark-hive';
$theme = 'start';
if (devbox())
$theme = 'dotluv';
if (sandbox())
$theme = 'darkness';