save() public method

this method also saves the related components
public save ( Doctrine_Connection $conn = null ) : void
$conn Doctrine_Connection optional connection parameter
return void
Example #1
0
 public function save()
 {
     $identifier = $this->identifier();
     $identifier = implode(', ', $identifier);
     // If column aggregation is used on this model we will have $class_type defined. Ensure it's set model is loaded
     if (!empty($this->class_type)) {
         Doctrine::initializeModels($this->class_type);
     }
     $identifier = $this->identifier();
     $identifier = implode(', ', $identifier);
     // Look for Kohana errors, and if they exist, throw Bluebox_Validation_Exception
     if (count(Bluebox_Controller::$validation->field_names()) > 0 and Bluebox_Controller::$validation->validate() == FALSE) {
         Kohana::log('debug', 'Kohana validation failed while saving ' . get_class($this) . ' ' . $identifier, 1);
         throw new Bluebox_Validation_Exception('Kohana validation failed on ' . get_class($this) . ' ' . $identifier, 1);
         // re-throw
     }
     try {
         // Store only the first record in this save event, making it available for any events that may need to know who started the save
         if (!self::getBaseTransactionObject()) {
             self::setBaseSaveObject($this);
             $invalid = $this->checkValidation();
             if (!empty($invalid)) {
                 throw new Doctrine_Validator_Exception($invalid);
             }
         }
         parent::save();
         // Done with any events that may use this
         if (self::getBaseTransactionObject() == $this) {
             self::setBaseSaveObject(NULL);
         }
         Kohana::log('debug', 'Saved record ' . get_class($this) . ' ' . $identifier);
         return TRUE;
     } catch (Doctrine_Validator_Exception $e) {
         Kohana::log('error', 'Doctrine_Validator_Exception on record ' . get_class($this) . ' ' . $identifier . ': ' . $e->getMessage());
         self::normalizeErrors($e);
         return FALSE;
     } catch (Doctrine_Transaction_Exception $e) {
         Kohana::log('error', 'Doctrine_Transaction_Exception on record ' . get_class($this) . ' ' . $identifier . ': ' . $e->getMessage());
         self::setBaseSaveObject(NULL);
         throw new Doctrine_Transaction_Exception($e->getMessage());
         return FALSE;
     } catch (Doctrine_Connection_Exception $e) {
         Kohana::log('error', 'Doctrine_Connection_Exception on record ' . get_class($this) . ' ' . $identifier . ': ' . $e->getMessage());
         self::setBaseSaveObject(NULL);
         throw new Doctrine_Connection_Exception($e->getMessage());
         return FALSE;
     } catch (Exception $e) {
         Kohana::log('error', 'Unhandled ' . get_class($e) . ' on record ' . get_class($this) . ' ' . $identifier . ': ' . $e->getMessage());
         self::setBaseSaveObject(NULL);
         throw new Exception($e->getMessage());
         return FALSE;
     }
 }
 /**
  * Update
  *
  * @param Doctrine_Record $logo
  * @param array   $data
  * @return string $uuid
  */
 protected function rec_update($logo, $data)
 {
     $this->check_authz($logo->Inquiry, 'write');
     $this->require_data($data, array('logo'));
     try {
         $logo->set_image($data['logo']);
     } catch (Exception $e) {
         throw new Rframe_Exception(RFrame::BAD_DATA, $e->getMessage());
     }
     // save
     $logo->save();
     return $logo->img_uuid;
 }
 public function swapWith(Doctrine_Record $record2)
 {
     $record1 = $this->getInvoker();
     $many = $this->_options['manyListsColumn'];
     if (!empty($many)) {
         if ($record1->{$many} != $record2->{$many}) {
             throw new Doctrine_Record_Exception('Cannot swap items from different lists.');
         }
     }
     $conn = $this->getTable()->getConnection();
     $conn->beginTransaction();
     $pos1 = $record1->position;
     $pos2 = $record2->position;
     $record1->position = $pos2;
     $record2->position = $pos1;
     $record1->save();
     $record2->save();
     $conn->commit();
 }
 public function swapWith(Doctrine_Record $object2)
 {
     $object1 = $this->getInvoker();
     $fieldName = $this->_options['name'];
     foreach ($this->_options['parents'] as $col) {
         if ($object1->{$col} != $object2->{$col}) {
             throw new Doctrine_Record_Exception('Cannot swap items from different lists.');
         }
     }
     $conn = $this->getTable()->getConnection();
     $conn->beginTransaction();
     $pos1 = $object1->{$fieldName};
     $pos2 = $object2->{$fieldName};
     $object1->{$fieldName} = $pos2;
     $object2->{$fieldName} = $pos1;
     $object1->save();
     $object2->save();
     $conn->commit();
 }
Example #5
0
 public function swapWith(Doctrine_Record $record2)
 {
     $record1 = $this->getInvoker();
     $name = $this->getName();
     foreach ($this->_options['manyListsBy'] as $col) {
         if ($record1->{$col} != $record2->{$col}) {
             throw new Doctrine_Record_Exception('Cannot swap items from different lists.');
         }
     }
     $conn = $this->getTable()->getConnection();
     $conn->beginTransaction();
     $pos1 = $record1->{$name};
     $pos2 = $record2->{$name};
     $record1->{$name} = $pos2;
     $record2->{$name} = $pos1;
     $record1->save();
     $record2->save();
     $conn->commit();
 }
Example #6
0
 /**
  * Method to save entity. May be refined in child controller
  *
  * @param Doctrine_Record $entity
  * @param Zend_Form $form
  * @return void
  */
 protected function _saveEntity(Doctrine_Record $entity, Zend_Form $form)
 {
     $entity->merge($form->getValues());
     $entity->save();
 }
Example #7
0
 public function saveRecord()
 {
     $this->_record->save();
 }
Example #8
0
 /**
  * Save the changes
  *
  * @return void
  */
 public function save()
 {
     $this->_dbRecord->save();
 }
Example #9
0
 /**
  * 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;
 }
 /**
  * Save the record to the database
  *
  * @param object  $conn (optional)
  */
 public function save(Doctrine_Connection $conn = null)
 {
     // unless explicitly passed, we find the _master connection
     // for the current env.
     if ($conn === null) {
         $conn = AIR2_DBManager::get_master_connection();
     }
     parent::save($conn);
 }
 /**
  * Calls ->save() on $rec, wrapped in a try/catch,
  * and re-throws any exception as a Rframe_Exception.
  *
  * @param Doctrine_Record  $rec
  */
 public function air_save(Doctrine_Record $rec)
 {
     try {
         $rec->save();
         $this->update_parent($rec);
     } catch (Exception $e) {
         // rethrow as Rframe exception
         //Carper::carp("caught save() exception: $e");
         throw new Rframe_Exception(Rframe::BAD_DATA, $e->getMessage());
     }
 }