Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/zendframework/zendframework#6361-fix-zendframewo…
Browse files Browse the repository at this point in the history
…rk/zf2#6281-mongodb-saveoptions-not-recognized'

Close zendframework/zendframework#6361
Close zendframework/zendframework#6281
  • Loading branch information
Ocramius committed Jul 28, 2014
2 parents bfab3bd + 1d63254 commit 4506dc7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/SaveHandler/MongoDBOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ class MongoDBOptions extends AbstractOptions
*/
protected $modifiedField = 'modified';


/**
* {@inheritdoc}
*/
public function __construct($options = null)
{
parent::__construct($options);

if ($this->saveOptions === array('w' => 1) && version_compare(phpversion('mongo'), '1.3.0', '<')) {
$this->saveOptions = array('safe' => true);
}
}

/**
* Set database name
*
Expand Down
3 changes: 2 additions & 1 deletion test/SaveHandler/MongoDBOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function testDefaults()
$options = new MongoDBOptions();
$this->assertNull($options->getDatabase());
$this->assertNull($options->getCollection());
$this->assertEquals(array('w' => true), $options->getSaveOptions());
$defaultSaveOptions = version_compare(phpversion('mongo'), '1.3.0', '<') ? array('safe' => true) : array('w' => 1);
$this->assertEquals($defaultSaveOptions, $options->getSaveOptions());
$this->assertEquals('name', $options->getNameField());
$this->assertEquals('data', $options->getDataField());
$this->assertEquals('lifetime', $options->getLifetimeField());
Expand Down

0 comments on commit 4506dc7

Please sign in to comment.