public function update($document) { $id = $this->_uow->getDocumentIdentifier($document); $update = $this->prepareUpdateData($document); if (!empty($update)) { /** * temporary fix for @link http://jira.mongodb.org/browse/SERVER-1050 * atomic modifiers $pushAll and $pullAll, $push, $pop and $pull * are not allowed on the same field in one update */ $id = new \MongoId($id); if (isset($update['$pushAll']) && isset($update['$pullAll'])) { $fields = array_intersect(array_keys($update['$pushAll']), array_keys($update['$pullAll'])); if (!empty($fields)) { $tempUpdate = array(); foreach ($fields as $field) { $tempUpdate[$field] = $update['$pullAll'][$field]; unset($update['$pullAll'][$field]); } if (empty($update['$pullAll'])) { unset($update['$pullAll']); } $tempUpdate = array('$pullAll' => $tempUpdate); $this->_collection->update(array('_id' => $id), $tempUpdate); } } $this->_collection->update(array('_id' => $id), $update); } }
/** * Updates persisted document, using atomic operators * * @param mixed $document */ public function update($document) { $id = $this->_uow->getDocumentIdentifier($document); $update = $this->prepareUpdateData($document); if (!empty($update)) { if ($this->_dm->getEventManager()->hasListeners(ODMEvents::onUpdatePrepared)) { $this->_dm->getEventManager()->dispatchEvent(ODMEvents::onUpdatePrepared, new OnUpdatePreparedArgs($this->_dm, $document, $update)); } /** * temporary fix for @link http://jira.mongodb.org/browse/SERVER-1050 * atomic modifiers $pushAll and $pullAll, $push, $pop and $pull * are not allowed on the same field in one update */ $id = $this->_class->getDatabaseIdentifierValue($id); if (isset($update[$this->_cmd . 'pushAll']) && isset($update[$this->_cmd . 'pullAll'])) { $fields = array_intersect(array_keys($update[$this->_cmd . 'pushAll']), array_keys($update[$this->_cmd . 'pullAll'])); if (!empty($fields)) { $tempUpdate = array(); foreach ($fields as $field) { $tempUpdate[$field] = $update[$this->_cmd . 'pullAll'][$field]; unset($update[$this->_cmd . 'pullAll'][$field]); } if (empty($update[$this->_cmd . 'pullAll'])) { unset($update[$this->_cmd . 'pullAll']); } $tempUpdate = array($this->_cmd . 'pullAll' => $tempUpdate); $this->_collection->update(array('_id' => $id), $tempUpdate); } } $this->_collection->update(array('_id' => $id), $update); } }
/** * Releases any lock that exists on this document. * * @param object $document */ public function unlock($document) { $criteria = array('_id' => $this->uow->getDocumentIdentifier($document)); $lockMapping = $this->class->fieldMappings[$this->class->lockField]; $this->collection->update($criteria, array($this->cmd.'unset' => array($lockMapping['name'] => true))); $this->class->reflFields[$this->class->lockField]->setValue($document, null); }