/** * Prepares update array for document, using atomic operators * * @param mixed $document * @return array */ public function prepareUpdateData($document) { $oid = spl_object_hash($document); $changeset = $this->_uow->getDocumentChangeSet($document); $result = array(); foreach ($this->_class->fieldMappings as $mapping) { if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) { continue; } $old = isset($changeset[$mapping['fieldName']][0]) ? $changeset[$mapping['fieldName']][0] : null; $new = isset($changeset[$mapping['fieldName']][1]) ? $changeset[$mapping['fieldName']][1] : null; $new = $this->_prepareValue($mapping, $new); $old = $this->_prepareValue($mapping, $old); if ($this->_class->isIdentifier($mapping['fieldName']) && !$this->_equals($new, $old)) { throw MongoDBException::identifierCannotBeUpdated(); } if ($mapping['type'] === 'many' || $mapping['type'] === 'collection') { $this->_addArrayUpdateAtomicOperator($mapping, (array) $new, (array) $old, $result); } else { $this->_addFieldUpdateAtomicOperator($mapping, $new, $old, $result); } } return $result; }