From cc986a3fdb2cf92c272a2489053e2c75c45e99d9 Mon Sep 17 00:00:00 2001 From: Alexandre Quercia Date: Mon, 10 Sep 2018 20:48:34 +0200 Subject: [PATCH] Revert "Fix more than one record generator initialisation on same PHP process" This reverts commit a498c6b7d61069039e975200b52f00f2fecbd9b0. --- lib/Doctrine/Event.php | 1 - lib/Doctrine/Record.php | 7 ------- lib/Doctrine/Record/Generator.php | 10 +++++++--- lib/Doctrine/Search.php | 5 +++++ lib/Doctrine/Table.php | 8 -------- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/lib/Doctrine/Event.php b/lib/Doctrine/Event.php index 74975c787..408d8ba13 100644 --- a/lib/Doctrine/Event.php +++ b/lib/Doctrine/Event.php @@ -68,7 +68,6 @@ class Doctrine_Event const RECORD_DQL_SELECT = 28; const RECORD_DQL_UPDATE = 29; const RECORD_VALIDATE = 30; - const RECORD_POST_SETUP = 31; /** * @var mixed $_nextSequence the sequence of the next event that will be created diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 60e95d8e8..386286d29 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -600,13 +600,6 @@ public function preHydrate($event) public function postHydrate($event) { } - /** - * Empty template method to provide Record classes with the ability to alter setup - * after it runs - */ - public function postSetUp($event) - { } - /** * Get the record error stack as a human readable string. * Useful for outputting errors to user via web browser diff --git a/lib/Doctrine/Record/Generator.php b/lib/Doctrine/Record/Generator.php index 5d6175389..728207ee0 100644 --- a/lib/Doctrine/Record/Generator.php +++ b/lib/Doctrine/Record/Generator.php @@ -160,6 +160,12 @@ public function initialize(Doctrine_Table $table) $this->_options['tableName'] = str_replace('%TABLE%', $ownerTableName, $tableName); } + // check that class doesn't exist (otherwise we cannot create it) + if ($this->_options['generateFiles'] === false && class_exists($this->_options['className'])) { + $this->_table = Doctrine_Core::getTable($this->_options['className']); + return false; + } + $this->buildTable(); $fk = $this->buildForeignKeys($this->_options['table']); @@ -455,9 +461,7 @@ public function generateClass(array $definition = array()) } else { throw new Doctrine_Record_Exception('If you wish to generate files then you must specify the path to generate the files in.'); } - } elseif (!class_exists($definition['className'])) { - // The class is not defined then we can load the definition. - + } else { $def = $builder->buildDefinition($definition); eval($def); diff --git a/lib/Doctrine/Search.php b/lib/Doctrine/Search.php index e6a189bf2..f6449b3c4 100644 --- a/lib/Doctrine/Search.php +++ b/lib/Doctrine/Search.php @@ -311,6 +311,11 @@ public function setTableDefinition() $className = $this->getOption('className'); + $autoLoad = (bool) ($this->_options['generateFiles']); + if (class_exists($className, $autoLoad)) { + return false; + } + // move any columns currently in the primary key to the end // So that 'keyword' is the first field in the table $previousIdentifier = array(); diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index b09c15966..4cf111a0c 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -268,10 +268,6 @@ public function __construct($name, Doctrine_Connection $conn, $initDefinition = if ($this->isTree()) { $this->getTree()->setUp(); } - - $event = new Doctrine_Event($this->record, Doctrine_Event::RECORD_POST_SETUP); - - $this->record->postSetUp($event); } else { if ( ! isset($this->_options['tableName'])) { $this->setTableName(Doctrine_Inflector::tableize($this->_options['name'])); @@ -3061,10 +3057,6 @@ public function initializeFromCache(Doctrine_Connection $conn) $this->getTree()->setUp(); } - $event = new Doctrine_Event($this->record, Doctrine_Event::RECORD_POST_SETUP); - - $this->record->postSetUp($event); - $this->_filters[] = new Doctrine_Record_Filter_Standard(); if ($this->getAttribute(Doctrine_Core::ATTR_USE_TABLE_REPOSITORY)) { $this->_repository = new Doctrine_Table_Repository($this);