Commit 4d38b322 authored by Jonathan.Wage's avatar Jonathan.Wage

Added ability to put php in all inputted files/strings to parser.

parent dd71ec4b
...@@ -139,7 +139,6 @@ class Doctrine_Data_Import extends Doctrine_Data ...@@ -139,7 +139,6 @@ class Doctrine_Data_Import extends Doctrine_Data
$obj = $pending['obj']; $obj = $pending['obj'];
$key = $pending['key']; $key = $pending['key'];
$local = $pending['local']; $local = $pending['local'];
$foreign = $pending['foreign'];
$pks = $primaryKeys[$key]; $pks = $primaryKeys[$key];
$obj->$local = $pks['id']; $obj->$local = $pks['id'];
} }
......
...@@ -1034,7 +1034,6 @@ class Doctrine_Export extends Doctrine_Connection_Module ...@@ -1034,7 +1034,6 @@ class Doctrine_Export extends Doctrine_Connection_Module
} catch (Doctrine_Connection_Exception $e) { } catch (Doctrine_Connection_Exception $e) {
// we only want to silence table already exists errors // we only want to silence table already exists errors
if ($e->getPortableCode() !== Doctrine::ERR_ALREADY_EXISTS) { if ($e->getPortableCode() !== Doctrine::ERR_ALREADY_EXISTS) {
echo $query."\n";
$connection->rollback(); $connection->rollback();
throw $e; throw $e;
} }
......
...@@ -100,4 +100,30 @@ abstract class Doctrine_Parser ...@@ -100,4 +100,30 @@ abstract class Doctrine_Parser
return $parser->dumpData($array, $path); return $parser->dumpData($array, $path);
} }
/**
* getContents
*
* Get contents whether it is the path to a file file or a string of txt.
* Either should allow php code in it.
*
* @param string $path
* @return void
* @author Jonathan H. Wage
*/
public function getContents($path)
{
ob_start();
if (!file_exists($path)) {
$contents = $path;
$path = '/tmp/dparser_' . microtime();
file_put_contents($path, $contents);
}
include($path);
$contents = ob_get_clean();
return $contents;
}
} }
\ No newline at end of file
...@@ -62,13 +62,9 @@ class Doctrine_Parser_Json extends Doctrine_Parser ...@@ -62,13 +62,9 @@ class Doctrine_Parser_Json extends Doctrine_Parser
*/ */
public function loadData($path) public function loadData($path)
{ {
if (file_exists($path) && is_readable($path)) { $contents = $this->getContents($path);
$data = file_get_contents($path);
} else {
$data = $path;
}
$json = json_decode($data); $json = json_decode($contents);
return $this->prepareData($json); return $this->prepareData($json);
} }
......
...@@ -62,12 +62,8 @@ class Doctrine_Parser_Serialize extends Doctrine_Parser ...@@ -62,12 +62,8 @@ class Doctrine_Parser_Serialize extends Doctrine_Parser
*/ */
public function loadData($path) public function loadData($path)
{ {
if (file_exists($path) && is_readable($path)) { $contents = $this->getContents($path);
$data = file_get_contents($path);
} else {
$data = $path;
}
return unserialize($data); return unserialize($contents);
} }
} }
\ No newline at end of file
...@@ -66,13 +66,9 @@ class Doctrine_Parser_Xml extends Doctrine_Parser ...@@ -66,13 +66,9 @@ class Doctrine_Parser_Xml extends Doctrine_Parser
public function loadData($path) public function loadData($path)
{ {
if (file_exists($path) && is_readable($path)) { $contents = $this->getContents($path);
$xmlString = file_get_contents($path);
} else {
$xmlString = $path;
}
$simpleXml = simplexml_load_string($xmlString); $simpleXml = simplexml_load_string($contents);
return $this->prepareData($simpleXml); return $this->prepareData($simpleXml);
} }
......
...@@ -66,9 +66,7 @@ class Doctrine_Parser_Yml extends Doctrine_Parser ...@@ -66,9 +66,7 @@ class Doctrine_Parser_Yml extends Doctrine_Parser
*/ */
public function loadData($path) public function loadData($path)
{ {
ob_start(); $contents = $this->getContents($path);
$retval = include($path);
$contents = ob_get_clean();
$spyc = new DoctrineSpyc(); $spyc = new DoctrineSpyc();
......
...@@ -100,8 +100,8 @@ class Doctrine_Export_Record_TestCase extends Doctrine_UnitTestCase ...@@ -100,8 +100,8 @@ class Doctrine_Export_Record_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($this->adapter->pop(), 'COMMIT'); $this->assertEqual($this->adapter->pop(), 'COMMIT');
$this->assertEqual($this->adapter->pop(), 'ALTER TABLE cms__category_languages ADD CONSTRAINT FOREIGN KEY (category_id) REFERENCES cms__category(id) ON DELETE CASCADE'); $this->assertEqual($this->adapter->pop(), 'ALTER TABLE cms__category_languages ADD CONSTRAINT FOREIGN KEY (category_id) REFERENCES cms__category(id) ON DELETE CASCADE');
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category (id BIGINT AUTO_INCREMENT, created DATETIME, parent BIGINT, position MEDIUMINT, active BIGINT, INDEX index_parent_idx (parent), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category_languages (id BIGINT AUTO_INCREMENT, name TEXT, category_id BIGINT, language_id BIGINT, INDEX index_category_idx (category_id), INDEX index_language_idx (language_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB'); $this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category_languages (id BIGINT AUTO_INCREMENT, name TEXT, category_id BIGINT, language_id BIGINT, INDEX index_category_idx (category_id), INDEX index_language_idx (language_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
$this->assertEqual($this->adapter->pop(), 'CREATE TABLE cms__category (id BIGINT AUTO_INCREMENT, created DATETIME, parent BIGINT, position MEDIUMINT, active BIGINT, INDEX index_parent_idx (parent), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB');
$this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION'); $this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');
} }
......
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