Empty template method to provide concrete Record classes with the possibility
to hook into the saving procedure only when the record is going to be
updated.
public preUpdate ( $event ) |
/** * updates given record * * @param Doctrine_Record $record record to be updated * @return boolean whether or not the update was successful */ public function update(Doctrine_Record $record) { $event = new Doctrine_Event($record, Doctrine_Event::RECORD_UPDATE); $record->preUpdate($event); $table = $record->getTable(); $table->getRecordListener()->preUpdate($event); 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); } $record->assignIdentifier(true); } $table->getRecordListener()->postUpdate($event); $record->postUpdate($event); return true; }
/** * Preupdate hook for transactional activity logging. * * @param Doctrine_Event $event */ public function preUpdate($event) { parent::preUpdate($event); AIR2Logger::log($this, 'update'); }
/** * update * updates the given record * * @param Doctrine_Record $record record to be updated * @return boolean whether or not the update was successful */ public function update(Doctrine_Record $record) { $event = new Doctrine_Event($this, Doctrine_Event::RECORD_UPDATE); $record->preUpdate($event); if (!$event->skipOperation) { $array = $record->getPrepared(); if (empty($array)) { return false; } $set = array(); foreach ($array as $name => $value) { if ($value instanceof Doctrine_Expression) { $set[] = $value->getSql(); unset($array[$name]); } else { $set[] = $name . ' = ?'; if ($value instanceof Doctrine_Record) { if (!$value->exists()) { $record->save($this->conn); } $array[$name] = $value->getIncremented(); $record->set($name, $value->getIncremented()); } } } $params = array_values($array); $id = $record->identifier(); if (!is_array($id)) { $id = array($id); } $id = array_values($id); $params = array_merge($params, $id); $sql = 'UPDATE ' . $this->conn->quoteIdentifier($record->getTable()->getTableName()) . ' SET ' . implode(', ', $set) . ' WHERE ' . implode(' = ? AND ', $record->getTable()->getPrimaryKeys()) . ' = ?'; $stmt = $this->conn->getDbh()->prepare($sql); $stmt->execute($params); $record->assignIdentifier(true); } $record->postUpdate($event); return true; }
/** * updates given record * * @param Doctrine_Record $record record to be updated * @return boolean whether or not the update was successful */ public function update(Doctrine_Record $record) { $event = new Doctrine_Event($record, Doctrine_Event::RECORD_UPDATE); $record->preUpdate($event); $table = $record->getTable(); $table->getRecordListener()->preUpdate($event); if (!$event->skipOperation) { $identifier = $record->identifier(); if ($table->getOption('joinedParents')) { $dataSet = $this->formatDataSet($record); $component = $table->getComponentName(); $classes = $table->getOption('joinedParents'); $classes[] = $component; foreach ($record as $field => $value) { if ($value instanceof Doctrine_Record) { if (!$value->exists()) { $value->save(); } $record->set($field, $value->getIncremented()); } } foreach ($classes as $class) { $parentTable = $this->conn->getTable($class); $this->conn->update($this->conn->getTable($class), $dataSet[$class], $identifier); } } else { $array = $record->getPrepared(); $this->conn->update($table, $array, $identifier); } $record->assignIdentifier(true); } $table->getRecordListener()->postUpdate($event); $record->postUpdate($event); return true; }