Commit 33bb25ac authored by zYne's avatar zYne

--no commit message

--no commit message
parent 936d442c
...@@ -492,7 +492,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -492,7 +492,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
// prepare and execute the statement // prepare and execute the statement
$this->execute($query, array_values($values)); $this->execute($query, array_values($values));
print $query . '(' . implode(', ', $values) . ")<br>";
return true; return true;
} }
/** /**
......
...@@ -77,8 +77,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -77,8 +77,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$type = $rel->getType(); $type = $rel->getType();
// skip self-referenced relations // skip self-referenced relations
if ($name === $nm) if ($name === $nm) {
continue; continue;
}
if ($rel instanceof Doctrine_Relation_ForeignKey) { if ($rel instanceof Doctrine_Relation_ForeignKey) {
if ($index2 !== false) { if ($index2 !== false) {
......
...@@ -403,7 +403,7 @@ class Doctrine_Hydrate ...@@ -403,7 +403,7 @@ class Doctrine_Hydrate
// we keep track of all the collections // we keep track of all the collections
$colls = array(); $colls = array();
$colls[] = $coll; print_r($array); $colls[] = $coll;
$prevRow = array(); $prevRow = array();
/** /**
* iterate over the fetched data * iterate over the fetched data
......
...@@ -107,6 +107,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -107,6 +107,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @var Doctrine_Validator_ErrorStack error stack object * @var Doctrine_Validator_ErrorStack error stack object
*/ */
protected $_errorStack; protected $_errorStack;
/**
* @var Doctrine_Record_Filter the filter object
*/
protected $_filter;
/** /**
* @var array $references an array containing all the references * @var array $references an array containing all the references
*/ */
...@@ -150,6 +154,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -150,6 +154,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$exists = false; $exists = false;
} }
// initialize the filter object
$this->_filter = new Doctrine_Record_Filter($this);
// Check if the current connection has the records table in its registry // Check if the current connection has the records table in its registry
// If not this record is only used for creating table definition and setting up // If not this record is only used for creating table definition and setting up
// relations. // relations.
...@@ -176,7 +183,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -176,7 +183,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$count = count($this->_data); $count = count($this->_data);
// clean data array // clean data array
$this->cleanData(); $this->_data = $this->_filter->cleanData($this->_data);
$this->prepareIdentifiers($exists); $this->prepareIdentifiers($exists);
...@@ -354,86 +361,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -354,86 +361,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
} }
} }
} }
/**
* cleanData
* this method does several things to records internal data
*
* 1. It unserializes array and object typed columns
* 2. Uncompresses gzip typed columns
* 3. Gets the appropriate enum values for enum typed columns
* 4. Initializes special null object pointer for null values (for fast column existence checking purposes)
*
*
* example:
*
* $data = array("name"=>"John","lastname"=> null, "id" => 1,"unknown" => "unknown");
* $names = array("name", "lastname", "id");
* $data after operation:
* $data = array("name"=>"John","lastname" => Object(Doctrine_Null));
*
* here column 'id' is removed since its auto-incremented primary key (read-only)
*
* @throws Doctrine_Record_Exception if unserialization of array/object typed column fails or
* if uncompression of gzip typed column fails
*
* @return integer
*/
private function cleanData()
{
$tmp = $this->_data;
$this->_data = array();
$count = 0;
foreach ($this->_table->getColumnNames() as $name) {
$type = $this->_table->getTypeOf($name);
if ( ! isset($tmp[$name])) {
$this->_data[$name] = self::$null;
} else {
switch ($type) {
case 'array':
case 'object':
if ($tmp[$name] !== self::$null) {
if (is_string($tmp[$name])) {
$value = unserialize($tmp[$name]);
if ($value === false)
throw new Doctrine_Record_Exception('Unserialization of ' . $name . ' failed.');
} else {
$value = $tmp[$name];
}
$this->_data[$name] = $value;
}
break;
case 'gzip':
if ($tmp[$name] !== self::$null) {
$value = gzuncompress($tmp[$name]);
if ($value === false)
throw new Doctrine_Record_Exception('Uncompressing of ' . $name . ' failed.');
$this->_data[$name] = $value;
}
break;
case 'enum':
$this->_data[$name] = $this->_table->enumValue($name, $tmp[$name]);
break;
case 'boolean':
case 'integer':
if ($tmp[$name] !== self::$null && ! ($tmp[$name] instanceof Doctrine_Record)) {
settype($tmp[$name], $type);
}
default:
$this->_data[$name] = $tmp[$name];
}
$count++;
}
}
return $count;
}
/** /**
* hydrate * hydrate
* hydrates this object from given array * hydrates this object from given array
...@@ -446,7 +373,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -446,7 +373,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
foreach ($data as $k => $v) { foreach ($data as $k => $v) {
$this->_data[$k] = $v; $this->_data[$k] = $v;
} }
$this->cleanData(); $this->_data = $this->_filter->cleanData($this->_data);
$this->prepareIdentifiers(); $this->prepareIdentifiers();
} }
/** /**
...@@ -562,7 +489,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -562,7 +489,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->_table->getRepository()->add($this); $this->_table->getRepository()->add($this);
$this->cleanData(); $this->_data = $this->_filter->cleanData($this->_data);
$this->prepareIdentifiers($this->exists()); $this->prepareIdentifiers($this->exists());
...@@ -640,7 +567,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -640,7 +567,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
} }
$id = array_values($id); $id = array_values($id);
$query = $this->_table->getQuery()." WHERE ".implode(" = ? AND ",$this->_table->getPrimaryKeys())." = ?"; $query = $this->_table->getQuery() . ' WHERE ' . implode(' = ? AND ', $this->_table->getPrimaryKeys()) . ' = ?';
$stmt = $this->_table->getConnection()->execute($query,$id); $stmt = $this->_table->getConnection()->execute($query,$id);
$this->_data = $stmt->fetch(PDO::FETCH_ASSOC); $this->_data = $stmt->fetch(PDO::FETCH_ASSOC);
...@@ -673,7 +600,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -673,7 +600,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->_data = $this->_table->getData(); $this->_data = $this->_table->getData();
$old = $this->_id; $old = $this->_id;
$this->cleanData(); $this->_data = $this->_filter->cleanData($this->_data);
$this->prepareIdentifiers(); $this->prepareIdentifiers();
...@@ -1234,7 +1161,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -1234,7 +1161,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
{ {
if ($id === false) { if ($id === false) {
$this->_id = array(); $this->_id = array();
$this->cleanData(); $this->_data = $this->_filter->cleanData($this->_data);
$this->_state = Doctrine_Record::STATE_TCLEAN; $this->_state = Doctrine_Record::STATE_TCLEAN;
$this->_modified = array(); $this->_modified = array();
} elseif ($id === true) { } elseif ($id === true) {
...@@ -1266,8 +1193,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -1266,8 +1193,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
final public function getIncremented() final public function getIncremented()
{ {
$id = current($this->_id); $id = current($this->_id);
if ($id === false) if ($id === false) {
return null; return null;
}
return $id; return $id;
} }
...@@ -1305,18 +1233,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -1305,18 +1233,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
} }
throw new Doctrine_Record_Exception("Unknown reference $name"); throw new Doctrine_Record_Exception("Unknown reference $name");
} }
/**
* addReference
* @param Doctrine_Record $record
* @param mixed $key
* @return void
*/
public function addReference(Doctrine_Record $record, Doctrine_Relation $connector, $key = null)
{
$alias = $connector->getAlias();
$this->references[$alias]->add($record, $key);
}
/** /**
* getReferences * getReferences
* @return array all references * @return array all references
......
...@@ -67,31 +67,28 @@ class Doctrine_Record_Filter ...@@ -67,31 +67,28 @@ class Doctrine_Record_Filter
* *
* example: * example:
* *
* $data = array("name"=>"John","lastname"=> null, "id" => 1,"unknown" => "unknown"); * $data = array("name" => "John", "lastname" => null, "id" => 1, "unknown" => "unknown");
* $names = array("name", "lastname", "id");
* $data after operation: * $data after operation:
* $data = array("name"=>"John","lastname" => Object(Doctrine_Null)); * $data = array("name" => "John", "lastname" => Object(Doctrine_Null));
* *
* here column 'id' is removed since its auto-incremented primary key (read-only) * here column 'id' is removed since its auto-incremented primary key (read-only)
* *
* @throws Doctrine_Record_Exception if unserialization of array/object typed column fails or * @throws Doctrine_Record_Exception if unserialization of array/object typed column fails or
* if uncompression of gzip typed column fails * if uncompression of gzip typed column fails
* *
* @param array $data data array to be cleaned
* @return integer * @return integer
*/ */
public function cleanData() public function cleanData($data)
{ {
$tmp = $this->_data; $tmp = $data;
$data = array();
$this->_data = array();
$count = 0;
foreach ($this->_table->getColumnNames() as $name) { foreach ($this->_table->getColumnNames() as $name) {
$type = $this->_table->getTypeOf($name); $type = $this->_table->getTypeOf($name);
if ( ! isset($tmp[$name])) { if ( ! isset($tmp[$name])) {
$this->_data[$name] = self::$null; $data[$name] = self::$null;
} else { } else {
switch ($type) { switch ($type) {
case 'array': case 'array':
...@@ -106,7 +103,7 @@ class Doctrine_Record_Filter ...@@ -106,7 +103,7 @@ class Doctrine_Record_Filter
} else { } else {
$value = $tmp[$name]; $value = $tmp[$name];
} }
$this->_data[$name] = $value; $data[$name] = $value;
} }
break; break;
case 'gzip': case 'gzip':
...@@ -117,20 +114,20 @@ class Doctrine_Record_Filter ...@@ -117,20 +114,20 @@ class Doctrine_Record_Filter
throw new Doctrine_Record_Exception('Uncompressing of ' . $name . ' failed.'); throw new Doctrine_Record_Exception('Uncompressing of ' . $name . ' failed.');
} }
$this->_data[$name] = $value; $data[$name] = $value;
} }
break; break;
case 'enum': case 'enum':
$this->_data[$name] = $this->_table->enumValue($name, $tmp[$name]); $data[$name] = $this->_table->enumValue($name, $tmp[$name]);
break; break;
default: default:
$this->_data[$name] = $tmp[$name]; $data[$name] = $tmp[$name];
} }
$count++;
} }
} }
return $count; return $data;
} }
/** /**
* prepareIdentifiers * prepareIdentifiers
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment