/** * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. * * This will only work if the object has been saved and has a valid primary key set. * * @param boolean $deep (optional) Whether to also de-associated any related objects. * @param PropelPDO $con (optional) The PropelPDO connection to use. * @return void * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db */ public function reload($deep = false, PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("Cannot reload a deleted object."); } if ($this->isNew()) { throw new PropelException("Cannot reload an unsaved object."); } if ($con === null) { $con = Propel::getConnection(DropFolderFilePeer::DATABASE_NAME, Propel::CONNECTION_READ); } // We don't need to alter the object instance pool; we're just modifying this instance // already in the pool. DropFolderFilePeer::setUseCriteriaFilter(false); $stmt = DropFolderFilePeer::doSelectStmt($this->buildPkeyCriteria(), $con); DropFolderFilePeer::setUseCriteriaFilter(true); $row = $stmt->fetch(PDO::FETCH_NUM); $stmt->closeCursor(); if (!$row) { throw new PropelException('Cannot find matching row in the database to reload object values.'); } $this->hydrate($row, 0, true); // rehydrate if ($deep) { // also de-associate any related objects? } // if (deep) }
/** * Persists this object to the database. * * If the object is new, it inserts it; otherwise an update is performed. * All modified related objects will also be persisted in the doSave() * method. This method wraps all precipitate database operations in a * single transaction. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see doSave() */ public function save(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("You cannot save an object that has been deleted."); } if ($con === null) { $con = Propel::getConnection(DropFolderFilePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); $isInsert = $this->isNew(); try { $ret = $this->preSave($con); if ($isInsert) { $ret = $ret && $this->preInsert($con); } else { $ret = $ret && $this->preUpdate($con); } if (!$ret || !$this->isModified()) { $con->commit(); return 0; } for ($retries = 1; $retries < KalturaPDO::SAVE_MAX_RETRIES; $retries++) { $affectedRows = $this->doSave($con); if ($affectedRows || !$this->isColumnModified(DropFolderFilePeer::CUSTOM_DATA)) { //ask if custom_data wasn't modified to avoid retry with atomic column break; } KalturaLog::debug("was unable to save! retrying for the {$retries} time"); $criteria = $this->buildPkeyCriteria(); $criteria->addSelectColumn(DropFolderFilePeer::CUSTOM_DATA); $stmt = DropFolderFilePeer::doSelectStmt($criteria, $con); $cutsomDataArr = $stmt->fetchAll(PDO::FETCH_COLUMN); $newCustomData = $cutsomDataArr[0]; $this->custom_data_md5 = md5($newCustomData); $valuesToChangeTo = $this->m_custom_data->toArray(); $this->m_custom_data = myCustomData::fromString($newCustomData); //set custom data column values we wanted to change to foreach ($this->oldCustomDataValues as $namespace => $namespaceValues) { foreach ($namespaceValues as $name => $oldValue) { if ($namespace) { $newValue = $valuesToChangeTo[$namespace][$name]; } else { $newValue = $valuesToChangeTo[$name]; } $this->putInCustomData($name, $newValue, $namespace); } } $this->setCustomData($this->m_custom_data->toString()); } if ($isInsert) { $this->postInsert($con); } else { $this->postUpdate($con); } $this->postSave($con); DropFolderFilePeer::addInstanceToPool($this); $con->commit(); return $affectedRows; } catch (PropelException $e) { $con->rollBack(); throw $e; } }