Merging fixes to trunk

Revision: [1805]
Adding fix for Ticket #238

Revision: [1804]
Fixing associations queries.
Adding fix from Ticket #275

Revision: [1803]
Removing the auto generating of a new session id when CAKE_SECURITY set to high.
Adding renew() to the session component, this can be used to regenerate a new session id.

Revision: [1802]
Adding fix for Ticket #280.
Need to decide if we should set the 2 vars mentioned in the ticket automatically,
I changed the 2 method to call the dbo. 

Revision: [1801]
Fixing errors in AclCLI class

Revision: [1800]
Made change to fields name setting, * will no longer be used, query will be built using the tables meta data

Revision: [1799]

Revision: [1798]
Adding fix for Ticket #269

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1806 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-01-15 12:18:57 +00:00
parent fb96b06394
commit 44cd92d739
10 changed files with 89 additions and 76 deletions

View file

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ // // +---------------------------------------------------------------------------------------------------+ //
/////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
0.10.5.1797 RC 1 0.10.5.1806 RC 1

View file

@ -150,6 +150,20 @@ class SessionComponent extends Object
} }
/**
* Enter description here...
*
* Use like this. $this->Session->valid();
* This will return true if session is valid
* false if session is invalid
*
* @return boolean
*/
function renew()
{
$this->CakeSession->renew();
}
/** /**
* Enter description here... * Enter description here...
* *

View file

@ -112,7 +112,7 @@ class DboSource extends DataSource
function execute($sql) function execute($sql)
{ {
$t = getMicrotime(); $t = getMicrotime();
$this->_result = $this->__execute($sql); $this->_result = $this->_execute($sql);
$this->affected = $this->lastAffected(); $this->affected = $this->lastAffected();
$this->took = round((getMicrotime() - $t) * 1000, 0); $this->took = round((getMicrotime() - $t) * 1000, 0);
@ -407,7 +407,7 @@ class DboSource extends DataSource
if ($linkModel == null) if ($linkModel == null)
{ {
// Generates primary query // Generates primary query
$sql = 'SELECT ' . join(', ', $this->fields($queryData['fields'])) . ' FROM '; $sql = 'SELECT ' . join(', ', $this->fields($model, $model->name, $queryData['fields'])) . ' FROM ';
$sql .= $this->name($model->table).' AS '; $sql .= $this->name($model->table).' AS ';
$sql .= $this->name($model->name).' ' . join(' ', $queryData['joins']).' '; $sql .= $this->name($model->name).' ' . join(' ', $queryData['joins']).' ';
$sql .= $this->conditions($queryData['conditions']).' '.$this->order($queryData['order']); $sql .= $this->conditions($queryData['conditions']).' '.$this->order($queryData['order']);
@ -418,7 +418,7 @@ class DboSource extends DataSource
$alias = $association; $alias = $association;
if($model->name == $linkModel->name) if($model->name == $linkModel->name)
{ {
$alias = Inflector::pluralize($association); // $alias = Inflector::pluralize($association);
} }
switch ($type) switch ($type)
@ -430,7 +430,8 @@ class DboSource extends DataSource
{ {
return $assocData['finderQuery']; return $assocData['finderQuery'];
} }
$sql = 'SELECT * FROM '.$this->name($linkModel->table).' AS '.$alias; $sql = 'SELECT '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
$sql .= ' FROM '.$this->name($linkModel->table).' AS '.$alias;
$conditions = $queryData['conditions']; $conditions = $queryData['conditions'];
$condition = $model->escapeField($assocData['foreignKey']); $condition = $model->escapeField($assocData['foreignKey']);
$condition .= '={$__cake_foreignKey__$}'; $condition .= '={$__cake_foreignKey__$}';
@ -510,8 +511,8 @@ class DboSource extends DataSource
else else
{ {
$conditions = $assocData['conditions']; $conditions = $assocData['conditions'];
$sql = 'SELECT * FROM '.$this->name($linkModel->table).' AS '; $sql = 'SELECT '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
$sql .= $this->name($alias); $sql .= ' FROM '.$this->name($linkModel->table).' AS '. $this->name($alias);
$cond = $this->name($alias).'.'.$this->name($assocData['foreignKey']); $cond = $this->name($alias).'.'.$this->name($assocData['foreignKey']);
$cond .= '={$__cake_id__$}'; $cond .= '={$__cake_id__$}';
@ -541,14 +542,13 @@ class DboSource extends DataSource
else else
{ {
$joinTbl = $this->name($assocData['joinTable']); $joinTbl = $this->name($assocData['joinTable']);
$alias = $this->name($alias);
$sql = 'SELECT '.join(', ', $this->fields($assocData['fields'])); $sql = 'SELECT '.join(', ', $this->fields($linkModel, $alias, $assocData['fields']));
$sql .= ' FROM '.$this->name($linkModel->table).' AS '.$alias; $sql .= ' FROM '.$this->name($linkModel->table).' AS '.$this->name($alias);
$sql .= ' JOIN '.$joinTbl.' ON '.$joinTbl; $sql .= ' JOIN '.$joinTbl.' ON '.$joinTbl;
$sql .= '.'.$this->name($assocData['foreignKey']).'={$__cake_id__$}'; $sql .= '.'.$this->name($assocData['foreignKey']).'={$__cake_id__$}';
$sql .= ' AND '.$joinTbl.'.'.$this->name($assocData['associationForeignKey']); $sql .= ' AND '.$joinTbl.'.'.$this->name($assocData['associationForeignKey']);
$sql .= ' = '.$alias.'.'.$this->name($linkModel->primaryKey); $sql .= ' = '.$this->name($alias).'.'.$this->name($linkModel->primaryKey);
$sql .= $this->conditions($assocData['conditions']); $sql .= $this->conditions($assocData['conditions']);
$sql .= $this->order($assocData['order']); $sql .= $this->order($assocData['order']);
@ -621,10 +621,10 @@ class DboSource extends DataSource
{ {
$data['conditions'] = ' 1 '; $data['conditions'] = ' 1 ';
} }
if (!isset($data['fields'])) // if (!isset($data['fields']))
{ // {
$data['fields'] = '*'; // $data['fields'] = '*';
} // }
if (!isset($data['joins'])) if (!isset($data['joins']))
{ {
$data['joins'] = array(); $data['joins'] = array();
@ -639,11 +639,11 @@ class DboSource extends DataSource
} }
} }
function fields ($fields) function fields (&$model, $alias, $fields)
{ {
if (is_array($fields)) if (is_array($fields))
{ {
$f = $fields; $fields = $fields;
} }
else else
{ {
@ -661,7 +661,12 @@ class DboSource extends DataSource
} }
else else
{ {
$fields = array('*'); //$fields = array('*');
foreach ($model->_tableInfo->value as $field)
{
$fields[]= $field['name'];
}
} }
} }
@ -669,7 +674,7 @@ class DboSource extends DataSource
{ {
for ($i = 0; $i < count($fields); $i++) for ($i = 0; $i < count($fields); $i++)
{ {
$fields[$i] = $this->name($fields[$i]); $fields[$i] = $this->name($alias).'.'.$this->name($fields[$i]);
} }
} }
return $fields; return $fields;

View file

@ -125,8 +125,9 @@ class DboMysql extends DboSource
* *
* @param string $sql SQL statement * @param string $sql SQL statement
* @return resource Result resource identifier * @return resource Result resource identifier
* @access protected
*/ */
function __execute ($sql) function _execute ($sql)
{ {
return mysql_query($sql, $this->connection); return mysql_query($sql, $this->connection);
} }
@ -168,10 +169,16 @@ class DboMysql extends DboSource
*/ */
function fetchRow ($assoc = false) function fetchRow ($assoc = false)
{ {
//return mysql_fetch_array($this->_result, $assoc? MYSQL_ASSOC: MYSQL_BOTH); if(is_resource($this->_result))
$this->resultSet($this->_result); {
$resultRow = $this->fetchResult(); $this->resultSet($this->_result);
return $resultRow; $resultRow = $this->fetchResult();
return $resultRow;
}
else
{
return null;
}
} }
/** /**
@ -244,7 +251,7 @@ class DboMysql extends DboSource
{ {
return '*'; return '*';
} }
return '`'.$data.'`'; return '`'. ereg_replace('\.', '`.`', $data) .'`';
} }
/** /**

View file

@ -453,7 +453,7 @@ class Model extends Object
switch($key) switch($key)
{ {
case 'fields': case 'fields':
$data = '*'; $data = '';
break; break;
case 'foreignKey': case 'foreignKey':
$data = Inflector::singularize($this->table).'_id'; $data = Inflector::singularize($this->table).'_id';
@ -1346,7 +1346,8 @@ class Model extends Object
*/ */
function getNumRows () function getNumRows ()
{ {
return $this->__numRows; //return $this->__numRows;
return $this->db->lastNumRows();
} }
/** /**
@ -1356,7 +1357,8 @@ class Model extends Object
*/ */
function getAffectedRows () function getAffectedRows ()
{ {
return $this->__affectedRows; //return $this->__affectedRows;
return $this->db->lastAffected();
} }
/** /**

View file

@ -450,7 +450,7 @@ class Model extends Object
switch($key) switch($key)
{ {
case 'fields': case 'fields':
$data = '*'; $data = '';
break; break;
case 'foreignKey': case 'foreignKey':
$data = Inflector::singularize($this->table).'_id'; $data = Inflector::singularize($this->table).'_id';
@ -1343,7 +1343,8 @@ class Model extends Object
*/ */
function getNumRows () function getNumRows ()
{ {
return $this->__numRows; //return $this->__numRows;
return $this->db->lastNumRows();
} }
/** /**
@ -1353,7 +1354,8 @@ class Model extends Object
*/ */
function getAffectedRows () function getAffectedRows ()
{ {
return $this->__affectedRows; //return $this->__affectedRows;
return $this->db->lastAffected();
} }
/** /**

View file

@ -314,6 +314,7 @@ class CakeSession extends Object
setcookie(CAKE_SESSION_COOKIE, '', time()-42000, $this->path); setcookie(CAKE_SESSION_COOKIE, '', time()-42000, $this->path);
} }
$file = $sessionpath.DS."sess_".session_id(); $file = $sessionpath.DS."sess_".session_id();
session_destroy();
@unlink($file); @unlink($file);
$this->__construct($this->path); $this->__construct($this->path);
} }
@ -427,8 +428,8 @@ class CakeSession extends Object
{ {
if($this->readSessionVar("Config")) if($this->readSessionVar("Config"))
{ {
if($this->userAgent == $this->readSessionVar("Config.userAgent") && if($this->userAgent == $this->readSessionVar("Config.userAgent")
$this->time <= $this->readSessionVar("Config.time")) && $this->time <= $this->readSessionVar("Config.time"))
{ {
$this->writeSessionVar("Config.time", $this->sessionTime); $this->writeSessionVar("Config.time", $this->sessionTime);
$this->valid = true; $this->valid = true;
@ -449,11 +450,6 @@ class CakeSession extends Object
$this->valid = true; $this->valid = true;
$this->_setError(1, "Session is valid"); $this->_setError(1, "Session is valid");
} }
if($this->security == 'high')
{
$this->_regenerateId();
}
header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
} }
@ -519,7 +515,7 @@ class CakeSession extends Object
* @access private * @access private
* *
*/ */
function _renew() function renew()
{ {
$this->_regenerateId(); $this->_regenerateId();
} }

View file

@ -61,7 +61,7 @@ class AjaxHelper extends Helper
* *
* @var array * @var array
*/ */
var $ajaxOptions = array('method','position','form','parameters','evalScripts', 'asynchronous', 'onComplete', 'onUninitialized', 'onLoading', 'onLoaded', 'onInteractive'); var $ajaxOptions = array('type', 'confirm', 'condition', 'before', 'after', 'fallback', 'update', 'loading', 'loaded', 'interactive', 'complete', 'with', 'url', 'method', 'position', 'form', 'parameters', 'evalScripts', 'asynchronous', 'onComplete', 'onUninitialized', 'onLoading', 'onLoaded', 'onInteractive');
/** /**
* Options for draggable. * Options for draggable.
@ -84,8 +84,6 @@ class AjaxHelper extends Helper
*/ */
var $sortOptions = array('tag', 'only', 'overlap', 'constraint', 'containment', 'handle', 'hoverClass', 'ghosting', 'dropOnEmpty', 'onUpdate', 'onChange'); var $sortOptions = array('tag', 'only', 'overlap', 'constraint', 'containment', 'handle', 'hoverClass', 'ghosting', 'dropOnEmpty', 'onUpdate', 'onChange');
var $__ajaxKeys = array('url', 'with', 'update', 'loading', 'loaded', 'interactive', 'complete', 'type', 'confirm', 'condition', 'before', 'after', 'fallback');
/** /**
* Returns link to remote action * Returns link to remote action
* *
@ -377,22 +375,10 @@ class AjaxHelper extends Helper
$options['id'] = r("/", "_", $field); $options['id'] = r("/", "_", $field);
} }
$htmlOptions = $options; $htmlOptions = $this->__getHtmlOptions($options);
$ajaxOptions = array('with', 'asynchronous', 'synchronous', 'method', 'position', 'form');
$htmlOptions['autocomplete'] = "off"; $htmlOptions['autocomplete'] = "off";
foreach($ajaxOptions as $key)
{
if(isset($options[$key]))
{
$ajaxOptions[$key] = $options[$key];
}
else
{
unset($ajaxOptions[$key]);
}
}
if(!isset($options['class'])) if(!isset($options['class']))
{ {
$options['class'] = "auto_complete"; $options['class'] = "auto_complete";
@ -537,9 +523,13 @@ class AjaxHelper extends Helper
} }
function __getHtmlOptions($options) function __getHtmlOptions($options, $extra = array())
{ {
foreach($this->__ajaxKeys as $key) foreach($this->ajaxOptions as $key)
{
unset($options[$key]);
}
foreach($extra as $key)
{ {
unset($options[$key]); unset($options[$key]);
} }

View file

@ -1377,7 +1377,7 @@ class HtmlHelper extends Helper
{ {
$value = isset($value)? $value : $this->tagValue($tagName."_min"); $value = isset($value)? $value : $this->tagValue($tagName."_min");
$minValue = empty($selected) ? date('i') : $selected ; $minValue = empty($selected) ? date('i') : $selected ;
for( $minCount=0; $minCount<61; $minCount++) for( $minCount=0; $minCount<60; $minCount++)
{ {
$mins[$minCount] = sprintf('%02d', $minCount); $mins[$minCount] = sprintf('%02d', $minCount);
} }

View file

@ -51,19 +51,17 @@ define ('APP_DIR', 'app');
* *
*/ */
define ('DEBUG', 1); define ('DEBUG', 1);
require_once (ROOT.'cake'.DS.'basics.php');
require_once (ROOT.'cake'.DS.'config'.DS.'paths.php'); require_once (ROOT.'cake'.DS.'config'.DS.'paths.php');
require_once (CAKE.'basics.php');
require_once (CONFIGS.'core.php'); require_once (CONFIGS.'core.php');
require_once (CONFIGS.'database.php'); require_once (CONFIGS.'database.php');
uses ('neat_array'); uses ('neat_array');
uses ('object'); uses ('object');
uses ('session'); uses ('session');
uses ('security'); uses ('security');
uses ('model'.DS.'connection_manager');
uses ('model'.DS.'datasources'.DS.'dbo_source');
uses ('model'.DS.'model'); uses ('model'.DS.'model');
uses ('model'.DS.'dbo'.DS.'dbo_factory');
uses ('controller'.DS.'controller');
uses ('controller'.DS.'components'.DS.'acl'); uses ('controller'.DS.'components'.DS.'acl');
uses ('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aclnode'); uses ('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aclnode');
uses ('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aco'); uses ('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aco');
@ -105,12 +103,6 @@ class AclCLI {
* @var unknown_type * @var unknown_type
*/ */
var $acl; var $acl;
/**
* Enter description here...
*
* @var unknown_type
*/
var $controller;
/** /**
* Enter description here... * Enter description here...
@ -119,6 +111,13 @@ class AclCLI {
*/ */
var $args; var $args;
/**
* Enter description here...
*
* @var unknown_type
*/
var $dataSource = 'default';
/** /**
* Enter description here... * Enter description here...
* *
@ -143,9 +142,7 @@ class AclCLI {
$this->acl = $acl->getACL(); $this->acl = $acl->getACL();
$this->args = $args; $this->args = $args;
$this->db =& ConnectionManager::getDataSource($this->dataSource);
$this->controller =& new Controller();
$this->controller->constructClasses();
$this->stdin = fopen('php://stdin', 'r'); $this->stdin = fopen('php://stdin', 'r');
$this->stdout = fopen('php://stdout', 'w'); $this->stdout = fopen('php://stdout', 'w');
@ -382,7 +379,7 @@ class AclCLI {
`rght` int(11) default NULL, `rght` int(11) default NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
);"; );";
$this->controller->db->query($sql); $this->db->query($sql);
fwrite($this->stdout, "Creating access request objects table (acos)...\n"); fwrite($this->stdout, "Creating access request objects table (acos)...\n");
$sql2 = "CREATE TABLE `aros` ( $sql2 = "CREATE TABLE `aros` (
@ -393,7 +390,7 @@ class AclCLI {
`rght` int(11) default NULL, `rght` int(11) default NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
);"; );";
$this->controller->db->query($sql2); $this->db->query($sql2);
fwrite($this->stdout, "Creating relationships table (aros_acos)...\n"); fwrite($this->stdout, "Creating relationships table (aros_acos)...\n");
$sql3 = "CREATE TABLE `aros_acos` ( $sql3 = "CREATE TABLE `aros_acos` (
@ -406,7 +403,7 @@ class AclCLI {
`_delete` int(11) NOT NULL default '0', `_delete` int(11) NOT NULL default '0',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
);"; );";
$this->controller->db->query($sql3); $this->db->query($sql3);
fwrite($this->stdout, "\nDone.\n"); fwrite($this->stdout, "\nDone.\n");
} }
@ -574,7 +571,7 @@ class AclCLI {
$class = ucwords($type); $class = ucwords($type);
$vars['secondary_id'] = ($class == 'aro' ? 'user_id' : 'object_id'); $vars['secondary_id'] = ($class == 'aro' ? 'user_id' : 'object_id');
$vars['data_name'] = $type; $vars['data_name'] = $type;
$vars['table_name'] = $class . 's'; $vars['table_name'] = $type . 's';
$vars['class'] = $class; $vars['class'] = $class;
return $vars; return $vars;
} }