Skip to content

Commit

Permalink
Merge branch 'master' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
canni committed Feb 11, 2011
2 parents 8155832 + 1546150 commit 40795fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 63 deletions.
9 changes: 6 additions & 3 deletions EMongoDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,16 +663,19 @@ public function update(array $attributes=null, $modify = false)
}

if($modify)
{
if(isset($rawData['_id']) === true)
unset($rawData['_id']);
$result = $this->getCollection()->update(
array('_id' => $this->_id),
array('$set' => $rawData),
array(
'fsync'=>$this->getFsyncFlag(),
'safe'=>$this->getSafeFlag()
'safe'=>$this->getSafeFlag(),
'multiple'=>false
)
);
else
{
} else {
if(version_compare(Mongo::VERSION, '1.0.5','>=') === true)
$result = $this->getCollection()->save($rawData, array(
'fsync'=>$this->getFsyncFlag(),
Expand Down
68 changes: 8 additions & 60 deletions EMongoGridFS.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ abstract class EMongoGridFS extends EMongoDocument
*/
public $filename = null; // mandatory

/**
* Indicates the temporary folder where we will save updated files to ensure we dont loose data
* @var string $_temporaryFolder
*/
private $_temporaryFolder = null;

/**
* Returns current MongoGridFS object
* By default this method use {@see getCollectionName()}
Expand All @@ -66,30 +60,6 @@ public function getCollection()
return self::$_collections[$this->getCollectionName()];
}

/**
* Sets temporary folder, used for updates
* @param string $value
* @since v1.3
*/
public function setTemporaryFolder($value)
{
$this->_temporaryFolder = rtrim($value, DIRECTORY_SEPARATOR);
}

/**
* Gets temporary folder, used for updates
* @return string
* @since v1.3
*/
public function getTemporaryFolder()
{
if($this->_temporaryFolder !== null)
return $this->_temporaryFolder;
if(self::$_models[get_class($this)]->_temporaryFolder !== null)
return self::$_models[get_class($this)]->_temporaryFolder;
return $this->getMongoDBComponent()->gridFStemporaryFolder;
}

/**
* Inserts a row into the table based on this active record attributes.
* If the table's primary key is auto-incremental and is null before insertion,
Expand Down Expand Up @@ -223,42 +193,20 @@ public function update(array $attributes=null)
if($this->getIsNewRecord())
throw new CDbException(Yii::t('yii','The EMongoDocument cannot be updated because it is new.'));

if($this->getTemporaryFolder() === null)
Yii::trace('Trace: '.__CLASS__.'::'.__FUNCTION__.'() be careful, you are updating without safe mode, please enter your temporary folder', 'ext.MongoDb.EMongoGridFS');
else
$this->write($this->getTemporaryFolder().$this->getFilename());

//keep old values
$id = $this->_id;
$filename = $this->getFilename();
$gridFSFile = $this->_gridFSFile;

if($this->deleteByPk($id) !== false)
{
$result = $this->insertWithPk($this->_id, $attributes);
if($result === true)
return true;
else
if(is_file($this->filename) === true) {
if($this->deleteByPk($this->_id) !== false)
{
if($this->getTemporaryFolder() !== false)
{
//recover old file
$this->_gridFSFile = $gridFSFile;
$this->filename = $filename;
$this->insertWithPk($id, $attributes);
}
$result = $this->insertWithPk($this->_id, $attributes);
if($result === true)
return true;
else
throw new CDbException(Yii::t('yii','Unable to update MongoGridFSFile.'));

return false;
return false;
}
} else {
return parent::update($attributes, true);
}
else
throw new CDbException(Yii::t('yii','Unable to delete old MongoGridFSFile.'));
return false;
}


/**
* Creates an EMongoGridFS with the given attributes.
* This method is internally used by the find methods.
Expand Down

0 comments on commit 40795fe

Please sign in to comment.