-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting driver wide collection options for safe, fsync and timeout. #32
Open
elricho
wants to merge
33
commits into
ichikaway:master
Choose a base branch
from
HandsetDetection:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
5a2c3dd
Changes allow setting of driver wide colleciton options for safe, fsy…
elricho 9b2d990
Fixed bug in insert introduced in previous commit.
elricho afe9b9e
Updated to use collectionOptions on a per collection basis rather tha…
elricho fc17456
Library ported from using php-mongo extebsion to new php-mongodb exte…
c1a6c8b
Remove outdated directories.
437a15e
Remove outdated docs.
a61f886
Remove outdated Cakephp 1.3 samples.
ae89f69
Remove debug statements.
ca4d05c
Update readme.
0f4daec
Updated readme.
91412f9
Cleanup JSON for Packagist
39e9906
Remove uppercase chars from package name ! Doh, i always forget this.
d52cce6
Adjust composer instructions for lowercase composer name.
ec2eae5
Add Travis CI
acc2fa9
Install php-mongodb extension for php 5.6
5b9ef91
Use correct path to tests.
7e8513d
Remove debug from tests.
e784112
BugFix : Change MongoDate to new class MongoDB\BSON\UTCDateTime.
228ac24
BugFix : Replace MongoDate with MongoDB\BSON\UTCDateTime
20129c0
BugFIx : Use MongoDB::MONGODB_VERSION constant to get the driver vers…
70e745e
BugFix : Update exceptions to new exception classes.
eed4233
Have composer install deps.
034f278
Ensure composer autoload.php executes before tests run.
83621ba
Fix previous blunder - doh !
d378b79
Add composer autoload to cakephp bootstrap.
e350dc0
Update composer.json for correct phpunit version. (Cakephp 2.x needs …
a696900
Remove reference to mysql.
fc6357a
Cleanup better after tests.
ca8bdaf
BugFix : testCreateConnectionName using incorrect datasource name.
fcea761
Fix datasource issues with $test database defaults.
7c95938
Added debug to tests - tracing a travis issue.
3897805
Install Mongodb 3.2 (Travis uses 2.4).
b6a1d37
Don't drop system collections.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,9 +91,29 @@ class MongodbSource extends DboSource { | |
'port' => '27017', | ||
'login' => '', | ||
'password' => '', | ||
'replicaset' => '', | ||
'replicaset' => '' | ||
); | ||
|
||
/** | ||
* collection options | ||
* | ||
* set collection options for various mongo write operations. | ||
* options can be found in the php manual | ||
* http://www.php.net/manual/en/mongocollection.save.php | ||
* http://www.php.net/manual/en/mongocollection.insert.php | ||
* http://www.php.net/manual/en/mongocollection.batchinsert.php | ||
* http://www.php.net/manual/en/mongocollection.update.php | ||
* | ||
* @var array | ||
*/ | ||
|
||
public $collectionOptions = array( | ||
'save' => array(), | ||
'insert' => array(), | ||
'batchInsert' => array(), | ||
'update' => array() | ||
); | ||
|
||
/** | ||
* column definition | ||
* | ||
|
@@ -200,7 +220,7 @@ public function connect() { | |
|
||
$this->connected = true; | ||
} | ||
|
||
} catch(MongoException $e) { | ||
$this->error = $e->getMessage(); | ||
trigger_error($this->error); | ||
|
@@ -256,16 +276,17 @@ public function insertMulti($table, $fields, $values) { | |
$data[] = array_combine($fields, $row); | ||
} | ||
$this->_prepareLogQuery($table); // just sets a timer | ||
$params = array_merge($this->collectionOptions['batchInsert'], array('safe' => true)); | ||
try{ | ||
$return = $this->_db | ||
->selectCollection($table) | ||
->batchInsert($data, array('safe' => true)); | ||
->batchInsert($data, $params); | ||
} catch (MongoException $e) { | ||
$this->error = $e->getMessage(); | ||
trigger_error($this->error); | ||
} | ||
if ($this->fullDebug) { | ||
$this->logQuery("db.{$table}.insertMulti( :data , array('safe' => true))", compact('data')); | ||
$this->logQuery("db.{$table}.insertMulti( :data , :params )", compact('data','params')); | ||
} | ||
} | ||
|
||
|
@@ -466,16 +487,17 @@ public function create(&$Model, $fields = null, $values = null) { | |
} | ||
|
||
$this->_prepareLogQuery($Model); // just sets a timer | ||
$params = $this->collectionOptions['insert']; | ||
try{ | ||
$return = $this->_db | ||
->selectCollection($Model->table) | ||
->insert($data, true); | ||
->insert($data, $params); | ||
} catch (MongoException $e) { | ||
$this->error = $e->getMessage(); | ||
trigger_error($this->error); | ||
} | ||
if ($this->fullDebug) { | ||
$this->logQuery("db.{$Model->useTable}.insert( :data , true)", compact('data')); | ||
$this->logQuery("db.{$Model->useTable}.insert( :data , :params )", compact('data','params')); | ||
} | ||
|
||
if (!empty($return) && $return['ok']) { | ||
|
@@ -710,33 +732,35 @@ public function update(&$Model, $fields = null, $values = null, $conditions = nu | |
} | ||
|
||
$this->_prepareLogQuery($Model); // just sets a timer | ||
$return = false; | ||
if (!empty($data['_id'])) { | ||
$this->_convertId($data['_id']); | ||
$cond = array('_id' => $data['_id']); | ||
unset($data['_id']); | ||
|
||
$data = $this->setMongoUpdateOperator($Model, $data); | ||
|
||
$params = array_merge($this->collectionOptions['update'], array("multiple" => true)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
try{ | ||
$return = $mongoCollectionObj->update($cond, $data, array("multiple" => false)); | ||
$return = $mongoCollectionObj->update($cond, $data, $params); | ||
} catch (MongoException $e) { | ||
$this->error = $e->getMessage(); | ||
trigger_error($this->error); | ||
} | ||
if ($this->fullDebug) { | ||
$this->logQuery("db.{$Model->useTable}.update( :conditions, :data, :params )", | ||
array('conditions' => $cond, 'data' => $data, 'params' => array("multiple" => false)) | ||
array('conditions' => $cond, 'data' => $data, 'params' => $params) | ||
); | ||
} | ||
} else { | ||
$params = $this->collectionOptions['save']; | ||
try{ | ||
$return = $mongoCollectionObj->save($data); | ||
$return = $mongoCollectionObj->save($data, $params); | ||
} catch (MongoException $e) { | ||
$this->error = $e->getMessage(); | ||
trigger_error($this->error); | ||
} | ||
if ($this->fullDebug) { | ||
$this->logQuery("db.{$Model->useTable}.save( :data )", compact('data')); | ||
$this->logQuery("db.{$Model->useTable}.save( :data, :params )", compact('data', 'params')); | ||
} | ||
} | ||
return $return; | ||
|
@@ -804,20 +828,21 @@ public function updateAll(&$Model, $fields = null, $conditions = null) { | |
$this->_stripAlias($fields, $Model->alias, false, 'value'); | ||
|
||
$fields = $this->setMongoUpdateOperator($Model, $fields); | ||
|
||
$params = array_merge($this->collectionOptions['update'], array("multiple" => true)); | ||
|
||
$this->_prepareLogQuery($Model); // just sets a timer | ||
try{ | ||
$return = $this->_db | ||
->selectCollection($Model->table) | ||
->update($conditions, $fields, array("multiple" => true)); | ||
->update($conditions, $fields, $params); | ||
} catch (MongoException $e) { | ||
$this->error = $e->getMessage(); | ||
trigger_error($this->error); | ||
} | ||
|
||
if ($this->fullDebug) { | ||
$this->logQuery("db.{$Model->useTable}.update( :conditions, :fields, :params )", | ||
array('conditions' => $conditions, 'fields' => $fields, 'params' => array("multiple" => true)) | ||
array('conditions' => $conditions, 'fields' => $fields, 'params' => $params) | ||
); | ||
} | ||
return $return; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'insert' => array('safe' => true),