Skip to content
Permalink
Browse files

Merge branch '1.2' into 1.3

  • Loading branch information...
gwoo
gwoo committed Aug 2, 2009
1 parent 7847044 commit 38221e7aa29ff742c9d66161ed4815b2cda2f1fb
@@ -877,9 +877,16 @@ function parseCookies($header) {
$cookies = array();
foreach ((array)$header['Set-Cookie'] as $cookie) {
$parts = preg_split('/(?<![^;]");[ \t]*/', $cookie);
if (strpos($cookie, '";"') !== false) {
$cookie = str_replace('";"', "{__cookie_replace__}", $cookie);
$parts = str_replace("{__cookie_replace__}", '";"', preg_split('/\;/', $cookie));
} else {
$parts = preg_split('/\;[ \t]*/', $cookie);
}
list($name, $value) = explode('=', array_shift($parts), 2);
$cookies[$name] = compact('value');
foreach ($parts as $part) {
if (strpos($part, '=') !== false) {
list($key, $value) = explode('=', $part);
@@ -323,7 +323,7 @@ function containments(&$Model, $contain, $containments = array(), $throwErrors =
$option = 'conditions';
$val = $Model->{$name}->alias.'.'.$key;
}
$children[$option] = isset($children[$option]) ? array_merge((array) $children[$option], (array) $val) : $val;
$children[$option] = is_array($val) ? $val : array($val);
$newChildren = null;
if (!empty($name) && !empty($children[$key])) {
$newChildren = $children[$key];
@@ -226,9 +226,10 @@ function describe(&$model) {
return $cache;
}
$fields = false;
$cols = $this->fetchAll("SELECT COLUMN_NAME as Field, DATA_TYPE as Type, COL_LENGTH('" . $this->fullTableName($model, false) . "', COLUMN_NAME) as Length, IS_NULLABLE As [Null], COLUMN_DEFAULT as [Default], COLUMNPROPERTY(OBJECT_ID('" . $this->fullTableName($model, false) . "'), COLUMN_NAME, 'IsIdentity') as [Key], NUMERIC_SCALE as Size FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $this->fullTableName($model, false) . "'", false);
$table = $this->fullTableName($model, false);
$cols = $this->fetchAll("SELECT COLUMN_NAME as Field, DATA_TYPE as Type, COL_LENGTH('" . $table . "', COLUMN_NAME) as Length, IS_NULLABLE As [Null], COLUMN_DEFAULT as [Default], COLUMNPROPERTY(OBJECT_ID('" . $table . "'), COLUMN_NAME, 'IsIdentity') as [Key], NUMERIC_SCALE as Size FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $table . "'", false);
$fields = false;
foreach ($cols as $column) {
$field = $column[0]['Field'];
$fields[$field] = array(
@@ -312,7 +313,8 @@ function fields(&$model, $alias = null, $fields = array(), $quote = true) {
$fields = parent::fields($model, $alias, $fields, false);
$count = count($fields);
if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) {
if ($count >= 1 && strpos($fields[0], 'COUNT(*)') === false) {
$result = array();
for ($i = 0; $i < $count; $i++) {
$prepend = '';
@@ -323,6 +325,19 @@ function fields(&$model, $alias = null, $fields = array(), $quote = true) {
$fieldAlias = count($this->__fieldMappings);
if (!preg_match('/\s+AS\s+/i', $fields[$i])) {
if (substr($fields[$i], -1) == '*') {
if (strpos($fields[$i], '.') !== false && $fields[$i] != $alias . '.*') {
$build = explode('.', $fields[$i]);
$AssociatedModel = $model->{$build[0]};
} else {
$AssociatedModel = $model;
}
$_fields = $this->fields($AssociatedModel, $AssociatedModel->alias, array_keys($AssociatedModel->schema()));
$result = array_merge($result, $_fields);
continue;
}
if (strpos($fields[$i], '.') === false) {
$this->__fieldMappings[$alias . '__' . $fieldAlias] = $alias . '.' . $fields[$i];
$fieldName = $this->name($alias . '.' . $fields[$i]);
@@ -338,10 +353,12 @@ function fields(&$model, $alias = null, $fields = array(), $quote = true) {
}
$fields[$i] = "{$fieldName} AS {$fieldAlias}";
}
$fields[$i] = $prepend . $fields[$i];
$result[] = $prepend . $fields[$i];
}
return $result;
} else {
return $fields;
}
return $fields;
}
/**
@@ -392,6 +409,9 @@ function update(&$model, $fields = array(), $values = null, $conditions = null)
if (isset($fields[$model->primaryKey])) {
unset($fields[$model->primaryKey]);
}
if (empty($fields)) {
return true;
}
return parent::update($model, array_keys($fields), array_values($fields), $conditions);
}
@@ -485,8 +505,8 @@ function column($real) {
}
return $col;
}
$col = str_replace(')', '', $real);
$limit = null;
$col = str_replace(')', '', $real);
$limit = null;
if (strpos($col, '(') !== false) {
list($col, $limit) = explode('(', $col);
}
@@ -692,21 +712,15 @@ function insertMulti($table, $fields, $values) {
* Generate a database-native column schema string
*
* @param array $column An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]),
* where options can be 'default', 'length', or 'key'.
* where options can be 'default', 'length', or 'key'.
* @return string
*/
function buildColumn($column) {
$result = preg_replace('/(int|integer)\([0-9]+\)/i', '$1', parent::buildColumn($column));
$null = (
(isset($column['null']) && $column['null'] == true) ||
(array_key_exists('default', $column) && $column['default'] === null) ||
(array_keys($column) == array('type', 'name'))
);
$primaryKey = (isset($column['key']) && $column['key'] == 'primary');
$stringKey = ($primaryKey && $column['type'] != 'integer');
if ($null && !$primaryKey) {
$result .= " NULL";
if (strpos($result, 'DEFAULT NULL') !== false) {
$result = str_replace('DEFAULT NULL', 'NULL', $result);
} else if (array_keys($column) == array('type', 'name')) {
$result .= ' NULL';
}
return $result;
}
@@ -758,7 +772,6 @@ function _getPrimaryKey($model) {
return $field;
}
}
return null;
}
}
@@ -497,24 +497,27 @@ function listSources() {
* @access public
*/
function describe(&$model) {
$table = $model->fullTableName($model, false);
if (!empty($model->sequence)) {
$this->_sequenceMap[$model->table] = $model->sequence;
$this->_sequenceMap[$table] = $model->sequence;
} elseif (!empty($model->table)) {
$this->_sequenceMap[$model->table] = $model->table . '_seq';
$this->_sequenceMap[$table] = $model->table . '_seq';
}
$cache = parent::describe($model);
if ($cache != null) {
return $cache;
}
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH FROM all_tab_columns WHERE table_name = \'';
$sql .= strtoupper($this->fullTableName($model)) . '\'';
if (!$this->execute($sql)) {
return false;
}
$fields = array();
for ($i = 0; $row = $this->fetchRow(); $i++) {
@@ -1447,6 +1447,7 @@ function update(&$model, $fields = array(), $values = null, $conditions = null)
function _prepareUpdateFields(&$model, $fields, $quoteValues = true, $alias = false) {
$quotedAlias = $this->startQuote . $model->alias . $this->endQuote;
$updates = array();
foreach ($fields as $field => $value) {
if ($alias && strpos($field, '.') === false) {
$quoted = $model->escapeField($field);
@@ -2459,11 +2460,12 @@ function buildIndex($indexes, $table = null) {
if (!empty($value['unique'])) {
$out .= 'UNIQUE ';
}
$name = $this->startQuote . $name . $this->endQuote;
}
if (is_array($value['column'])) {
$out .= 'KEY '. $name .' (' . join(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
$out .= 'KEY ' . $name . ' (' . join(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
} else {
$out .= 'KEY '. $name .' (' . $this->name($value['column']) . ')';
$out .= 'KEY ' . $name . ' (' . $this->name($value['column']) . ')';
}
$join[] = $out;
}
@@ -598,6 +598,15 @@ function includeScript($script = "", $options = array()) {
* Generates a JavaScript object in JavaScript Object Notation (JSON)
* from an array
*
* ### Options
*
* - block - Wraps the return value in a script tag if true. Default is false
* - prefix - Prepends the string to the returned data. Default is ''
* - postfix - Appends the string to the returned data. Default is ''
* - stringKeys - A list of array keys to be treated as a string.
* - quoteKeys - If false treats $stringKeys as a list of keys **not** to be quoted. Default is true.
* - q - The type of quote to use. Default is "'"
*
* @param array $data Data to be converted
* @param array $options Set of options: block, prefix, postfix, stringKeys, quoteKeys, q
* @param string $prefix DEPRECATED, use $options['prefix'] instead. Prepends the string to the returned data
@@ -216,6 +216,7 @@ function normalize($object, $keyName = null, $options = array()) {
}
$tagOpts = $this->__tagOptions($name);
if ($tagOpts === false) {
return;
}
@@ -236,7 +237,6 @@ function normalize($object, $keyName = null, $options = array()) {
$attributes = array();
$children = array();
$chldObjs = array();
$document =& $this->document();
if (is_object($object)) {
$chldObjs = get_object_vars($object);
@@ -254,29 +254,32 @@ function normalize($object, $keyName = null, $options = array()) {
$node->createTextNode($chldObjs[$tagOpts['value']]);
unset($chldObjs[$tagOpts['value']]);
}
unset($chldObjs['_name_']);
$n = $name;
if (!empty($chldObjs['_name_'])) {
$n = null;
unset($chldObjs['_name_']);
}
$c = 0;
foreach ($chldObjs as $key => $val) {
if (in_array($key, $attr) && !is_object($val) && !is_array($val)) {
$attributes[$key] = $val;
} else {
if (!isset($tagOpts['children']) || $tagOpts['children'] === array() || (is_array($tagOpts['children']) && in_array($key, $tagOpts['children']))) {
$n = $key;
if (is_numeric($n)) {
$n = $name;
if (!is_numeric($key)) {
$n = $key;
}
if (is_array($val)) {
foreach ($val as $i => $obj2) {
$n2 = $i;
foreach ($val as $n2 => $obj2) {
if (is_numeric($n2)) {
$n2 = $n;
}
$node->normalize($obj2, $n2, $options);
}
} else {
if (is_object($val)) {
$node->normalize($val, $n, $options);
} elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) {
$tmp =& $node->createElement($key);
@@ -661,7 +664,6 @@ function toString($options = array(), $depth = 0) {
if ($options['whitespace']) {
$d .= "\n";
}
$count = count($this->children);
$cDepth = $depth + 1;
for ($i = 0; $i < $count; $i++) {
@@ -66,9 +66,9 @@ class CakeTestFixtureTestFixture extends CakeTestFixture {
* @var array
*/
var $records = array(
array('name' => 'Gandalf'),
array('name' => 'Captain Picard'),
array('name' => 'Chewbacca')
array('name' => 'Gandalf', 'created' => '2009-04-28 19:20:00'),
array('name' => 'Captain Picard', 'created' => '2009-04-28 19:20:00'),
array('name' => 'Chewbacca', 'created' => '2009-04-28 19:20:00')
);
}
Oops, something went wrong.

0 comments on commit 38221e7

Please sign in to comment.
You can’t perform that action at this time.