Assign the inheritance column values
public assignInheritanceValues ( ) : void | ||
return | void |
/** * Saves the given record and all associated records. * (The save() operation is always cascaded in 0.10/1.0). * * @param Doctrine_Record $record * @return void */ public function saveGraph(Doctrine_Record $record, $replace = false) { $record->assignInheritanceValues(); $conn = $this->getConnection(); $conn->connect(); $state = $record->state(); if ($state === Doctrine_Record::STATE_LOCKED || $state === Doctrine_Record::STATE_TLOCKED) { return false; } $record->state($record->exists() ? Doctrine_Record::STATE_LOCKED : Doctrine_Record::STATE_TLOCKED); try { $conn->beginInternalTransaction(); $record->state($state); $event = $record->invokeSaveHooks('pre', 'save'); $state = $record->state(); $isValid = true; if (!$event->skipOperation) { $this->saveRelatedLocalKeys($record); switch ($state) { case Doctrine_Record::STATE_TDIRTY: case Doctrine_Record::STATE_TCLEAN: if ($replace) { $isValid = $this->replace($record); } else { $isValid = $this->insert($record); } break; case Doctrine_Record::STATE_DIRTY: case Doctrine_Record::STATE_PROXY: if ($replace) { $isValid = $this->replace($record); } else { $isValid = $this->update($record); } break; case Doctrine_Record::STATE_CLEAN: // do nothing break; } $aliasesUnlinkInDb = array(); if ($isValid) { // NOTE: what about referential integrity issues? foreach ($record->getPendingDeletes() as $pendingDelete) { $pendingDelete->delete(); } foreach ($record->getPendingUnlinks() as $alias => $ids) { if ($ids === false) { $record->unlinkInDb($alias, array()); $aliasesUnlinkInDb[] = $alias; } else { if ($ids) { $record->unlinkInDb($alias, array_keys($ids)); $aliasesUnlinkInDb[] = $alias; } } } $record->resetPendingUnlinks(); $record->invokeSaveHooks('post', 'save', $event); } else { $conn->transaction->addInvalid($record); } $state = $record->state(); $record->state($record->exists() ? Doctrine_Record::STATE_LOCKED : Doctrine_Record::STATE_TLOCKED); if ($isValid) { $saveLater = $this->saveRelatedForeignKeys($record); foreach ($saveLater as $fk) { $alias = $fk->getAlias(); if ($record->hasReference($alias)) { $obj = $record->{$alias}; // check that the related object is not an instance of Doctrine_Null if ($obj && !$obj instanceof Doctrine_Null) { $processDiff = !in_array($alias, $aliasesUnlinkInDb); $obj->save($conn, $processDiff); } } } // save the MANY-TO-MANY associations $this->saveAssociations($record); } } $record->state($state); $conn->commit(); } catch (Exception $e) { // Make sure we roll back our internal transaction //$record->state($state); $conn->rollback(); throw $e; } $record->clearInvokedSaveHooks(); return true; }
/** * Saves the given record and all associated records. * (The save() operation is always cascaded in 0.10/1.0). * * @param Doctrine_Record $record * @return void */ public function saveGraph(Doctrine_Record $record) { $record->assignInheritanceValues(); $conn = $this->getConnection(); $state = $record->state(); if ($state === Doctrine_Record::STATE_LOCKED || $state === Doctrine_Record::STATE_TLOCKED) { return false; } $record->state($record->exists() ? Doctrine_Record::STATE_LOCKED : Doctrine_Record::STATE_TLOCKED); try { $conn->beginInternalTransaction(); $saveLater = $this->saveRelated($record); $record->state($state); if ($record->isValid()) { $event = new Doctrine_Event($record, Doctrine_Event::RECORD_SAVE); $record->preSave($event); $record->getTable()->getRecordListener()->preSave($event); $state = $record->state(); if (!$event->skipOperation) { switch ($state) { case Doctrine_Record::STATE_TDIRTY: case Doctrine_Record::STATE_TCLEAN: $this->insert($record); break; case Doctrine_Record::STATE_DIRTY: case Doctrine_Record::STATE_PROXY: $this->update($record); break; case Doctrine_Record::STATE_CLEAN: // do nothing break; } } // NOTE: what about referential integrity issues? foreach ($record->getPendingDeletes() as $pendingDelete) { $pendingDelete->delete(); } $record->getTable()->getRecordListener()->postSave($event); $record->postSave($event); } else { $conn->transaction->addInvalid($record); } $state = $record->state(); $record->state($record->exists() ? Doctrine_Record::STATE_LOCKED : Doctrine_Record::STATE_TLOCKED); foreach ($saveLater as $fk) { $alias = $fk->getAlias(); if ($record->hasReference($alias)) { $obj = $record->{$alias}; // check that the related object is not an instance of Doctrine_Null if (!$obj instanceof Doctrine_Null) { $obj->save($conn); } } } // save the MANY-TO-MANY associations $this->saveAssociations($record); $record->state($state); $conn->commit(); } catch (Exception $e) { // Make sure we roll back our internal transaction //$record->state($state); $conn->rollback(); throw $e; } return true; }