Adding fix for Ticket #2339

Adding fix for Ticket #2335
Adding fix for Ticket #2344

Merged changes in dbo from 1.2 to 1.1
Merged changes to session handling in 1.2 to 1.1
Merged changes to Model::_ _saveMulti() in 1.2 to 1.1
Added Set::pushDiff() to append differences in array 2 to array 1
Added SessionComponent::activate() and SessionHelper::activate() to turn sessions usage on if AUTO_SESSION is set to false
Added test for Ticket #2343
Added change to AclNode to use correct table naming
Added garbage clean up to CakeSession::_ _close(); some installs, like Debian, have removed garbage clean
up and use a cron job instead. Currently this change is only supported for database session.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4752 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-04-04 07:25:48 +00:00
parent f4df563a84
commit dcac88825a
10 changed files with 118 additions and 44 deletions

View file

@ -140,16 +140,15 @@ class Dispatcher extends Object {
}
}
if (empty($params['action'])) {
$params['action'] = 'index';
}
if(defined('CAKE_ADMIN')) {
if(isset($params[CAKE_ADMIN])) {
$this->admin = '/'.CAKE_ADMIN ;
$url = preg_replace('/'.CAKE_ADMIN.'\//', '', $url);
if (empty($params['action'])) {
$params['action'] = CAKE_ADMIN.'_'.'index';
} else {
$params['action'] = CAKE_ADMIN.'_'.$params['action'];
}
$params['action'] = CAKE_ADMIN.'_'.$params['action'];
} elseif (strpos($params['action'], CAKE_ADMIN) === 0) {
$privateAction = true;
}
@ -178,10 +177,6 @@ class Dispatcher extends Object {
$classMethods = get_class_methods($controller);
$classVars = get_object_vars($controller);
if (empty($params['action'])) {
$params['action'] = 'index';
}
if((in_array($params['action'], $classMethods) || in_array(strtolower($params['action']), $classMethods)) && strpos($params['action'], '_', 0) === 0) {
$privateAction = true;
}

View file

@ -61,9 +61,14 @@ class AclNode extends AppModel {
function node($ref = null) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$type = $this->name;
$table = low($type) . 's';
$prefix = $this->tablePrefix;
if (!empty($this->useTable)) {
$table = $this->useTable;
} else {
$table = Inflector::pluralize(Inflector::underscore($type));
}
if (empty($ref)) {
return null;
} elseif (is_string($ref)) {

View file

@ -41,6 +41,7 @@ class SessionComponent extends CakeSession {
* Used to determine if methods implementation is used, or bypassed
*
* @var boolean
* @access private
*/
var $__active = true;
/**
@ -55,9 +56,23 @@ class SessionComponent extends CakeSession {
$this->__active = false;
}
}
/**
* Turn sessions on if AUTO_SESSION is set to false in core.php
*
* @param string $base
*/
function activate($base = null) {
if ($this->__active === true) {
return;
}
parent::__construct($base);
$this->__active = true;
}
/**
* Startup method. Copies controller data locally for rendering flash messages.
*
* @param object $controller
* @access public
*/
function startup(&$controller) {
$this->base = $controller->base;
@ -76,6 +91,7 @@ class SessionComponent extends CakeSession {
* @param string $name The name of the key your are setting in the session.
* This should be in a Controller.key format for better organizing
* @param string $value The value you want to store in a session.
* @access public
*/
function write($name, $value = null) {
if ($this->__active === true) {
@ -103,6 +119,7 @@ class SessionComponent extends CakeSession {
* @param string $name the name of the session key you want to read
*
* @return values from the session vars
* @access public
*/
function read($name = null) {
if ($this->__active === true) {
@ -131,6 +148,7 @@ class SessionComponent extends CakeSession {
*
* @param string $name
* @return boolean, true is session variable is set and can be deleted, false is variable was not set.
* @access public
*/
function delete($name) {
if ($this->__active === true) {
@ -145,6 +163,7 @@ class SessionComponent extends CakeSession {
*
* @param string $name
* @return boolean true is session variable is set, false if not
* @access public
*/
function check($name) {
if ($this->__active === true) {
@ -158,6 +177,7 @@ class SessionComponent extends CakeSession {
* In your controller: $this->Session->error();
*
* @return string Last session error
* @access public
*/
function error() {
if ($this->__active === true) {
@ -176,6 +196,7 @@ class SessionComponent extends CakeSession {
* @param string $layout Layout to wrap flash message in
* @param array $params Parameters to be sent to layout as view variables
* @param string $key Message key, default is 'flash'
* @access public
*/
function setFlash($message, $layout = 'default', $params = array(), $key = 'flash') {
if ($this->__active === true) {
@ -204,6 +225,7 @@ class SessionComponent extends CakeSession {
* Used to renew a session id
*
* In your controller: $this->Session->renew();
* @access public
*/
function renew() {
if ($this->__active === true) {
@ -216,6 +238,7 @@ class SessionComponent extends CakeSession {
* In your controller: $this->Session->valid();
*
* @return boolean true is session is valid, false is session is invalid
* @access public
*/
function valid() {
if ($this->__active === true) {
@ -227,6 +250,7 @@ class SessionComponent extends CakeSession {
* Used to destroy sessions
*
* In your controller:. $this->Session->destroy();
* @access public
*/
function destroy() {
if ($this->__active === true) {

View file

@ -33,6 +33,7 @@
if (!class_exists('Object')) {
uses('object');
}
uses('Set');
/**
* Pluralize and singularize English words.
*
@ -60,7 +61,7 @@ class Inflector extends Object {
static $instance = array();
if (!isset($instance[0]) || !$instance[0]) {
$instance[0] = &new Inflector();
$instance[0] =& new Inflector();
}
return $instance[0];
@ -92,7 +93,8 @@ class Inflector extends Object {
'/(alias)/i' => '\1es', # alias
'/(octop|vir)us$/i' => '\1i', # octopus, virus - virus has no defined plural (according to Latin/dictionary.com), but viri is better than viruses/viruss
'/(ax|cri|test)is$/i' => '\1es', # axis, crisis
'/s$/' => 's',); # no change (compatibility)
'/s$/' => 's', # no change (compatibility)
'/$/' => 's',);
$coreUninflectedPlural = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'Amoyese',
'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', 'carp', 'chassis', 'clippers',
@ -137,9 +139,9 @@ class Inflector extends Object {
'turf' => 'turfs',);
include(CONFIGS.'inflections.php');
$pluralRules = array_merge($corePluralRules, $pluralRules, array('/$/' => 's'));
$uninflected = array_merge($coreUninflectedPlural, $uninflectedPlural);
$irregular = array_merge($coreIrregularPlural, $irregularPlural);
$pluralRules = Set::pushDiff($corePluralRules, $pluralRules);
$uninflected = Set::pushDiff($coreUninflectedPlural, $uninflectedPlural);
$irregular = Set::pushDiff($coreIrregularPlural, $irregularPlural);
$_this->pluralRules = array('pluralRules' => $pluralRules, 'uninflected' => $uninflected, 'irregular' => $irregular);
$_this->pluralized = array();
@ -270,9 +272,9 @@ class Inflector extends Object {
'turfs' => 'turf',);
include(CONFIGS.'inflections.php');
$singularRules = array_merge($coreSingularRules, $singularRules);
$uninflected = array_merge($coreUninflectedSingular, $uninflectedSingular);
$irregular = array_merge($coreIrregularSingular, $irregularSingular);
$singularRules = Set::pushDiff($coreSingularRules, $singularRules);
$uninflected = Set::pushDiff($coreUninflectedSingular, $uninflectedSingular);
$irregular = Set::pushDiff($coreIrregularSingular, $irregularSingular);
$_this->singularRules = array('singularRules' => $singularRules, 'uninflected' => $uninflected, 'irregular' => $irregular);
$_this->singularized = array();

View file

@ -187,8 +187,6 @@ class DboPostgres extends DboSource {
}
}
$this->__cacheDescription($model->tablePrefix . $model->table, $fields);
//pr($cols);
//pr($fields);
return $fields;
}
/**

View file

@ -360,6 +360,10 @@ class CakeSession extends Object {
* @access private
*/
function __close() {
$probability = mt_rand(1, 150);
if($probability <= 3) {
$this->__gc();
}
return true;
}
/**
@ -407,7 +411,7 @@ class CakeSession extends Object {
* @return boolean
* @access private
*/
function __gc($expires) {
function __gc($expires = null) {
$db =& ConnectionManager::getDataSource('default');
$table = $db->fullTableName(CAKE_SESSION_TABLE);
$db->execute("DELETE FROM " . $db->name($table) . " WHERE " . $db->name($table.'.expires') . " < ". $db->value(time()));

View file

@ -68,19 +68,42 @@ class Set extends Object {
* @access public
*/
function merge($array = null, $array2 = null) {
if ($array2 != null && is_array($array2)) {
if ($array2 !== null && is_array($array2)) {
return array_merge_recursive($array, $array2);
}
if ($array == null) {
$array = $this->value;
} elseif (is_object($array) && (is_a($array, 'set') || is_a($array, 'Set'))) {
$array = $array->get();
} elseif (is_object($array)) {
// Throw an error
} elseif (!is_array($array)) {
$array = array($array);
if(!isset($this->value)) {
$this->value = array();
}
$this->value = array_merge_recursive($this->value, $array);
$this->value = array_merge_recursive($this->value, Set::__array($array));
return $this->value;
}
/**
* Pushes the differences in $array2 onto the end of $array
*
* @param mixed $array
* @param mixed $arrary2
* @return array
* @access public
*/
function pushDiff($array = null, $array2 = null) {
if ($array2 !== null && is_array($array2)) {
foreach($array2 as $key => $value) {
if (!array_key_exists($key, $array)) {
$array[$key] = $value;
} else {
if (is_array($value)) {
$array[$key] = Set::pushDiff($array[$key], $array2[$key]);
}
}
}
return $array;
}
if(!isset($this->value)) {
$this->value = array();
}
$this->value = Set::pushDiff($this->value, Set::__array($array));
return $this->value;
}
/**
@ -103,7 +126,18 @@ class Set extends Object {
}
return Set::__map($val, $class);
}
function __array($array) {
if ($array == null) {
$array = $this->value;
} elseif (is_object($array) && (is_a($array, 'set') || is_a($array, 'Set'))) {
$array = $array->get();
} elseif (is_object($array)) {
// Throw an error
} elseif (!is_array($array)) {
$array = array($array);
}
return $array;
}
function __map($value, $class, $identity = null) {
if (is_object($value)) {
@ -485,5 +519,4 @@ class Set extends Object {
return $list;
}
}
?>
?>

View file

@ -776,7 +776,7 @@ class AjaxHelper extends AppHelper {
$callback = $this->remoteFunction($options);
$javascript = "new $klass('$name', ";
$javascript .= (isset($options['frequency']) ? $options['frequency'] . ', ' : '') . "function(element, value) {";
$javascript .= (!isset($options['frequency']) || intval($options['frequency']) == 0 ? '' : $options['frequency'] . ', ' ) . "function(element, value) {";
$javascript .= "$callback})";
return $javascript;
}

View file

@ -60,6 +60,14 @@ class SessionHelper extends CakeSession {
$this->__active = false;
}
}
/**
* Turn sessions on if AUTO_SESSION is set to false in core.php
*
* @param string $base
*/
function activate($base = null) {
$this->__active = true;
}
/**
* Used to read a session values set in a controller for a key or return values for all keys.
*
@ -69,6 +77,7 @@ class SessionHelper extends CakeSession {
* @param string $name the name of the session key you want to read
*
* @return values from the session vars
* @access public
*/
function read($name = null) {
if ($this->__active === true) {
@ -83,6 +92,7 @@ class SessionHelper extends CakeSession {
*
* @param string $name
* @return boolean
* @access public
*/
function check($name) {
if ($this->__active === true) {
@ -96,6 +106,7 @@ class SessionHelper extends CakeSession {
* In your view: $session->error();
*
* @return string last error
* @access public
*/
function error() {
if ($this->__active === true) {
@ -111,6 +122,7 @@ class SessionHelper extends CakeSession {
*
* @param string $key The [Message.]key you are rendering in the view.
* @return string Will echo the value if $key is set, or false if not set.
* @access public
*/
function flash($key = 'flash') {
if ($this->__active === true) {
@ -139,6 +151,7 @@ class SessionHelper extends CakeSession {
* Used to check is a session is valid in a view
*
* @return boolean
* @access public
*/
function valid() {
if ($this->__active === true) {

View file

@ -45,6 +45,10 @@ class InflectorTest extends UnitTestCase {
$expected = 'menu';
$this->assertEqual($result, $expected);
$result = $this->inflector->singularize('houses');
$expected = 'house';
$this->assertEqual($result, $expected);
$result = $this->inflector->singularize('quizzes');
$expected = 'quiz';
$this->assertEqual($result, $expected);
@ -72,13 +76,13 @@ class InflectorTest extends UnitTestCase {
$result = $this->inflector->singularize('indices');
$expected = 'index';
$this->assertEqual($result, $expected);
$result = $this->inflector->singularize('houses');
$expected = 'house';
$this->assertEqual($result, $expected);
}
function testInflectingPlurals() {
$result = $this->inflector->singularize('house');
$expected = 'houses';
$this->assertEqual($result, $expected);
$result = $this->inflector->pluralize('Bus');
$expected = 'Buses';
$this->assertEqual($result, $expected);
@ -110,10 +114,6 @@ class InflectorTest extends UnitTestCase {
$result = $this->inflector->pluralize('index');
$expected = 'indices';
$this->assertEqual($result, $expected);
$result = $this->inflector->pluralize('house');
$expected = 'houses';
$this->assertEqual($result, $expected);
}
function tearDown() {