From: Andrey Kutejko Date: Mon, 22 Jul 2013 22:55:29 +0000 (+0300) Subject: remove dead code related to "joinedParents" X-Git-Tag: 0.6~86 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=58d5f56c23b340047bb28223fb081cdcc0974f99;p=ipf-legacy-orm.git remove dead code related to "joinedParents" --- diff --git a/ipf/orm/connection/unitofwork.php b/ipf/orm/connection/unitofwork.php index ff77796..ad76646 100644 --- a/ipf/orm/connection/unitofwork.php +++ b/ipf/orm/connection/unitofwork.php @@ -184,9 +184,6 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module // adjust state, remove from identity map and inform postDelete listeners foreach ($deletedRecords as $record) { - // currently just for bc! - $this->_deleteCTIParents($table, $record); - //-- $record->state(IPF_ORM_Record::STATE_TCLEAN); $record->getTable()->removeRecord($record); $this->_postDelete($record); @@ -355,14 +352,8 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module if ( ! $event->skipOperation) { $identifier = $record->identifier(); - if ($table->getOption('joinedParents')) { - // currrently just for bc! - $this->_updateCTIRecord($table, $record); - //-- - } else { - $array = $record->getPrepared(); - $this->conn->update($table, $array, $identifier); - } + $array = $record->getPrepared(); + $this->conn->update($table, $array, $identifier); $record->assignIdentifier(true); } @@ -382,13 +373,7 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module $table->notifyRecordListeners('preInsert', $event); if ( ! $event->skipOperation) { - if ($table->getOption('joinedParents')) { - // just for bc! - $this->_insertCTIRecord($table, $record); - //-- - } else { - $this->processSingleInsert($record); - } + $this->processSingleInsert($record); } $table->addRecord($record); @@ -571,70 +556,6 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module return array_values($flushList); } - private function _deleteCTIParents(IPF_ORM_Table $table, $record) - { - if ($table->getOption('joinedParents')) { - foreach (array_reverse($table->getOption('joinedParents')) as $parent) { - $parentTable = $table->getConnection()->getTable($parent); - $this->conn->delete($parentTable, $record->identifier()); - } - } - } - - private function _insertCTIRecord(IPF_ORM_Table $table, IPF_ORM_Record $record) - { - $dataSet = $this->_formatDataSet($record); - $component = $table->getComponentName(); - - $classes = $table->getOption('joinedParents'); - $classes[] = $component; - - foreach ($classes as $k => $parent) { - if ($k === 0) { - $rootRecord = new $parent(); - $rootRecord->merge($dataSet[$parent]); - $this->processSingleInsert($rootRecord); - $record->assignIdentifier($rootRecord->identifier()); - } else { - foreach ((array) $rootRecord->identifier() as $id => $value) { - $dataSet[$parent][$id] = $value; - } - - $this->conn->insert($this->conn->getTable($parent), $dataSet[$parent]); - } - } - } - - private function _updateCTIRecord(IPF_ORM_Table $table, IPF_ORM_Record $record) - { - $identifier = $record->identifier(); - $dataSet = $this->_formatDataSet($record); - - $component = $table->getComponentName(); - - $classes = $table->getOption('joinedParents'); - $classes[] = $component; - - foreach ($record as $field => $value) { - if ($value instanceof IPF_ORM_Record) { - if ( ! $value->exists()) { - $value->save(); - } - $record->set($field, $value->getIncremented()); - } - } - - foreach ($classes as $class) { - $parentTable = $this->conn->getTable($class); - - if ( ! array_key_exists($class, $dataSet)) { - continue; - } - - $this->conn->update($this->conn->getTable($class), $dataSet[$class], $identifier); - } - } - private function _formatDataSet(IPF_ORM_Record $record) { $table = $record->getTable(); @@ -666,3 +587,4 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module return $dataSet; } } + diff --git a/ipf/orm/export.php b/ipf/orm/export.php index 43b76ed..66c813c 100644 --- a/ipf/orm/export.php +++ b/ipf/orm/export.php @@ -537,16 +537,6 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module $record = new $name(); $table = $record->getTable(); - $parents = $table->getOption('joinedParents'); - - foreach ($parents as $parent) { - $data = $table->getConnection()->getTable($parent)->getExportableFormat(); - - $query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']); - - $sql = array_merge($sql, (array) $query); - } - $data = $table->getExportableFormat(); $query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']); diff --git a/ipf/orm/query.php b/ipf/orm/query.php index 597b1a4..e7e8123 100644 --- a/ipf/orm/query.php +++ b/ipf/orm/query.php @@ -244,21 +244,9 @@ class IPF_ORM_Query extends IPF_ORM_Query_Abstract implements Countable, Seriali $sql = array(); foreach ($fields as $fieldName) { $columnName = $table->getColumnName($fieldName); - if (($owner = $table->getColumnOwner($columnName)) !== null && - $owner !== $table->getComponentName()) { - - $parent = $this->_conn->getTable($owner); - $columnName = $parent->getColumnName($fieldName); - $parentAlias = $this->getTableAlias($componentAlias . '.' . $parent->getComponentName()); - $sql[] = $this->_conn->quoteIdentifier($parentAlias . '.' . $columnName) - . ' AS ' - . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); - } else { - $columnName = $table->getColumnName($fieldName); - $sql[] = $this->_conn->quoteIdentifier($tableAlias . '.' . $columnName) - . ' AS ' - . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); - } + $sql[] = $this->_conn->quoteIdentifier($tableAlias . '.' . $columnName) + . ' AS ' + . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); } $this->_neededTables[] = $tableAlias; @@ -1336,31 +1324,7 @@ class IPF_ORM_Query extends IPF_ORM_Query_Abstract implements Countable, Seriali // get the short alias for this table $tableAlias = $this->getTableAlias($componentAlias, $tableName); - $queryPart = ''; - - foreach ($table->getOption('joinedParents') as $parent) { - $parentTable = $this->_conn->getTable($parent); - - $parentAlias = $componentAlias . '.' . $parent; - - // get the short alias for the parent table - $parentTableAlias = $this->getTableAlias($parentAlias, $parentTable->getTableName()); - - $queryPart .= ' LEFT JOIN ' . $this->_conn->quoteIdentifier($parentTable->getTableName()) - . ' ' . $this->_conn->quoteIdentifier($parentTableAlias) . ' ON '; - - //IPF_ORM::dump($table->getIdentifier()); - foreach ((array) $table->getIdentifier() as $identifier) { - $column = $table->getColumnName($identifier); - - $queryPart .= $this->_conn->quoteIdentifier($tableAlias) - . '.' . $this->_conn->quoteIdentifier($column) - . ' = ' . $this->_conn->quoteIdentifier($parentTableAlias) - . '.' . $this->_conn->quoteIdentifier($column); - } - } - - return $queryPart; + return ''; } public function getCountQuery() diff --git a/ipf/orm/table.php b/ipf/orm/table.php index 5d33ca2..706cfc4 100644 --- a/ipf/orm/table.php +++ b/ipf/orm/table.php @@ -28,7 +28,6 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable 'collation' => null, 'indexes' => array(), 'parents' => array(), - 'joinedParents' => array(), 'queryParts' => array(), 'versioning' => null, 'subclasses' => array(), @@ -112,54 +111,6 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable $class = new ReflectionClass($class); } - $this->_options['joinedParents'] = array(); - - foreach (array_reverse($this->_options['parents']) as $parent) { - - if ($parent === $class->getName()) { - continue; - } - $ref = new ReflectionClass($parent); - - if ($ref->isAbstract()) { - continue; - } - $parentTable = $this->_conn->getTable($parent); - - $found = false; - $parentColumns = $parentTable->getColumns(); - - foreach ($parentColumns as $columnName => $definition) { - if ( ! isset($definition['primary']) || $definition['primary'] === false) { - if (isset($this->_columns[$columnName])) { - $found = true; - break; - } else { - if ( ! isset($parentColumns[$columnName]['owner'])) { - $parentColumns[$columnName]['owner'] = $parentTable->getComponentName(); - } - - $this->_options['joinedParents'][] = $parentColumns[$columnName]['owner']; - } - } else { - unset($parentColumns[$columnName]); - } - } - - if ($found) { - continue; - } - - foreach ($parentColumns as $columnName => $definition) { - $fullName = $columnName . ' as ' . $parentTable->getFieldName($columnName); - $this->setColumn($fullName, $definition['type'], $definition['length'], $definition, true); - } - - break; - } - - $this->_options['joinedParents'] = array_values(array_unique($this->_options['joinedParents'])); - $this->_options['declaringClass'] = $class; $this->columnCount = count($this->_columns); @@ -175,39 +126,13 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable { switch (count($this->_identifier)) { case 0: - if ( ! empty($this->_options['joinedParents'])) { - $root = current($this->_options['joinedParents']); - - $table = $this->_conn->getTable($root); - - $this->_identifier = $table->getIdentifier(); - - $this->_identifierType = ($table->getIdentifierType() !== IPF_ORM::IDENTIFIER_AUTOINC) - ? $table->getIdentifierType() : IPF_ORM::IDENTIFIER_NATURAL; - - // add all inherited primary keys - foreach ((array) $this->_identifier as $id) { - $definition = $table->getDefinitionOf($id); - - // inherited primary keys shouldn't contain autoinc - // and sequence definitions - unset($definition['autoincrement']); - unset($definition['sequence']); - - // add the inherited primary key column - $fullName = $id . ' as ' . $table->getFieldName($id); - $this->setColumn($fullName, $definition['type'], $definition['length'], - $definition, true); - } - } else { - $definition = array('type' => 'integer', - 'length' => 20, - 'autoincrement' => true, - 'primary' => true); - $this->setColumn('id', $definition['type'], $definition['length'], $definition, true); - $this->_identifier = 'id'; - $this->_identifierType = IPF_ORM::IDENTIFIER_AUTOINC; - } + $definition = array('type' => 'integer', + 'length' => 20, + 'autoincrement' => true, + 'primary' => true); + $this->setColumn('id', $definition['type'], $definition['length'], $definition, true); + $this->_identifier = 'id'; + $this->_identifierType = IPF_ORM::IDENTIFIER_AUTOINC; $this->columnCount++; break; case 1: @@ -261,28 +186,6 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable } } - public function getColumnOwner($columnName) - { - if (isset($this->_columns[$columnName]['owner'])) { - return $this->_columns[$columnName]['owner']; - } else { - return $this->getComponentName(); - } - } - - public function getRecordInstance() - { - if ( ! $this->record) { - $this->record = new $this->_options['name']; - } - return $this->record; - } - - public function isInheritedColumn($columnName) - { - return (isset($this->_columns[$columnName]['owner'])); - } - public function isIdentifier($fieldName) { return ($fieldName === $this->getIdentifier() ||