An array to which unit information should be added
@param array $document (passed by reference)
550715
private function addUnits( &$document )
	{
		foreach ( $this->units as $unitRef => $unit )
		{
			$entry = array();
			$entry[] = "  <unit id=\"$unitRef\">";

			if ( isset( $unit['divide'] ) )
			{
				$entry[] = "    <divide>";

				if ( isset( $unit['divide']['numerator'] ) && count( $unit['divide']['numerator'] ) )
				{
					$entry[] = "      <unitNumerator>";

					foreach ( $unit['divide']['numerator'] as $measure )
					{
						$entry[] = "        <measure>$measure</measure>";
					}

					$entry[] = "      </unitNumerator>";
				}

				if ( isset( $unit['divide']['denominator'] ) && count( $unit['divide']['denominator'] ) )
				{
					$entry[] = "      <unitDenominator>";

					foreach ( $unit['divide']['denominator'] as $measure )
					{
						$entry[] = "        <measure>$measure</measure>";
					}

					$entry[] = "      </unitDenominator>";
				}

				$entry[] = "    </divide>";
			}
			else if ( isset( $unit['measures'] ) )
			{
				foreach ( $unit['measures'] as $measure )
				{
					$entry[] = "    <measure>$measure</measure>";
				}
			}
			else
			{
				$xbrli = STANDARD_PREFIX_XBRLI;
				$unit = str_replace( "{$xbrli}:", "", $unit );
				$entry[] = "    <measure>$unit</measure>";
			}
			$entry[] = "  </unit>";
			$entry[] = "";

			$document[] = implode( "\n", $entry );
		}
	}
1284596
private function cascadePreUpdate(ClassMetadata $class, $document)
    {
        foreach ($class->getEmbeddedAttributesMappings() as $mapping) {
            $value = $class->getPropertyMetadata($mapping->attributeName)->getValue($document);
            if ($value === null) {
                continue;
            }
            $values = $mapping->isOne() ? [$value] : $value;

            foreach ($values as $entry) {
                if ($this->uow->isScheduledForInsert($entry) || empty($this->uow->getDocumentChangeSet($entry))) {
                    continue;
                }
                $this->preUpdate($this->dm->getClassMetadata(get_class($entry)), $entry);
            }
        }
    }
59070
public function addDocument(Zend_Search_Lucene_Document $document)
    {
        if ($this->_documentDistributorCallBack !== null) {
            $index = call_user_func($this->_documentDistributorCallBack, $document, $this->_indices);
        } else {
            $index = $this->_indices[array_rand($this->_indices)];
        }

        $index->addDocument($document);
    }
591368
public function attach_files($document) {
        global $DB;

        $postid = $document->get('itemid');

        try {
            $post = $this->get_post($postid);
        } catch (\dml_missing_record_exception $e) {
            unset($this->postsdata[$postid]);
            debugging('Could not get record to attach files to '.$document->get('id'), DEBUG_DEVELOPER);
            return;
        }

        // Because this is used during indexing, we don't want to cache posts. Would result in memory leak.
        unset($this->postsdata[$postid]);

        $cm = $this->get_cm($this->get_module_name(), $post->forum, $document->get('courseid'));
        $context = \context_module::instance($cm->id);
        $contextid = $context->id;

        $fileareas = $this->get_search_fileareas();
        $component = $this->get_component_name();

        // Get the files and attach them.
        foreach ($fileareas as $filearea) {
            $fs = get_file_storage();
            $files = $fs->get_area_files($contextid, $component, $filearea, $postid, '', false);

            foreach ($files as $file) {
                $document->add_stored_file($file);
            }
        }
    }
897443
public function setDocuments(array $documents)
    {
        if ($documents instanceof PagSeguroDocument) {
            $this->documents = $documents;
        } else {
            if (is_array($documents)) {
                $this->addDocument($documents['type'], $documents['value']);
            }
        }
    }
118832
public function prepareUpdateData($document): array
    {
        $script = [];
        $body = [];

        $changeSet = $this->dm->getUnitOfWork()->getDocumentChangeSet($document);
        $class = $this->dm->getClassMetadata(get_class($document));
        $typeManager = $this->dm->getTypeManager();

        foreach ($changeSet as $name => $value) {
            $field = $class->getField($name);
            $type = $typeManager->getType($field->type);

            if ($field->multiple) {
                $body[$field->fieldName] = array_map(function ($item) use ($type, $field) {
                    return $type->toDatabase($item, $field->options);
                }, (array) $value[1]);
            } elseif (null !== $value[1]) {
                $body[$field->fieldName] = $type->toDatabase($value[1], $field->options);
            } else {
                $script[] = 'ctx._source.remove(\''.str_replace('\'', '\\\'', $field->fieldName).'\')';
            }
        }

        return [
            'body' => $body,
            'script' => implode('; ', $script),
        ];
    }
1313504
public function update(object $document, array $options = []) : void
    {
        $update = $this->pb->prepareUpdateData($document);

        $query = $this->getQueryForDocument($document);

        foreach (array_keys($query) as $field) {
            unset($update['$set'][$field]);
        }

        if (empty($update['$set'])) {
            unset($update['$set']);
        }

        // Include versioning logic to set the new version value in the database
        // and to ensure the version has not changed since this document object instance
        // was fetched from the database
        $nextVersion = null;
        if ($this->class->isVersioned) {
            $versionMapping = $this->class->fieldMappings[$this->class->versionField];
            $currentVersion = $this->class->reflFields[$this->class->versionField]->getValue($document);
            if ($versionMapping['type'] === 'int') {
                $nextVersion                             = $currentVersion + 1;
                $update['$inc'][$versionMapping['name']] = 1;
                $query[$versionMapping['name']]          = $currentVersion;
            } elseif ($versionMapping['type'] === 'date') {
                $nextVersion                             = new DateTime();
                $update['$set'][$versionMapping['name']] = Type::convertPHPToDatabaseValue($nextVersion);
                $query[$versionMapping['name']]          = Type::convertPHPToDatabaseValue($currentVersion);
            }
        }

        if (! empty($update)) {
            // Include locking logic so that if the document object in memory is currently
            // locked then it will remove it, otherwise it ensures the document is not locked.
            if ($this->class->isLockable) {
                $isLocked    = $this->class->reflFields[$this->class->lockField]->getValue($document);
                $lockMapping = $this->class->fieldMappings[$this->class->lockField];
                if ($isLocked) {
                    $update['$unset'] = [$lockMapping['name'] => true];
                } else {
                    $query[$lockMapping['name']] = ['$exists' => false];
                }
            }

            $options = $this->getWriteOptions($options);

            assert($this->collection instanceof Collection);
            $result = $this->collection->updateOne($query, $update, $options);

            if (($this->class->isVersioned || $this->class->isLockable) && $result->getModifiedCount() !== 1) {
                throw LockException::lockFailed($document);
            } elseif ($this->class->isVersioned) {
                $this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
            }
        }

        $this->handleCollections($document, $options);
    }
196601
public function addDocumentToDocumentPool(Document $document)
    {
        $documentId = (string) $document->getId();

        if (!isset($this->documentPool[$documentId])) {
            $this->documentPool[$documentId] = $document;
        } else {
            // merging because document after
            // load and before getting in second place may be changed
            // and this changes must be preserved:
            //
            // 1. Document loads and modifies in current session
            // 2. Document loads modified in another session
            // 3. Document loads once again in current session. Changes from stage 2 merges as unmodified

            $this->documentPool[$documentId]->mergeUnmodified($document->toArray());
        }

        return $this;
    }
368885
public function insert(array &$doc)
    {
        if (isset($doc['_id'])) {
            $clone = $doc;
            unset($clone['_id']);

            $response = $this->client->request('PUT', "/{$this->name}/{$doc['_id']}", [
                'body'    => JSONEncoder::encode($clone),
                'headers' => ['Content-Type' => 'application/json'],
            ]);
        } else {
            $response = $this->client->request('POST', "/{$this->name}/", [
                'body'    => JSONEncoder::encode($doc),
                'headers' => ['Content-Type' => 'application/json'],
            ]);
        }

        if (201 !== $response->getStatusCode()) {
            throw new Exception('Unable to save document');
        }

        $value = JSONEncoder::decode((string) $response->getBody());

        $doc['_id'] = $value['id'];
        $doc['_rev'] = $value['rev'];
    }
722419
public function insert(array $document)
    {
        $result = $this->getMongoCollection()->insert($document);

        // if write concern acknowledged
        if (is_array($result)) {
            if ($result['ok'] != 1) {
                throw new Exception('Insert error: ' . $result['err'] . ': ' . $result['errmsg']);
            }

            return $this;
        }

        // if write concern unacknowledged
        if (!$result) {
            throw new Exception('Insert error');
        }

        return $this;
    }
1359189
private function mergePartial(array &$document, array $updatedDocument, $prefix = null)
    {
        foreach ($updatedDocument as $key => $newValue) {
            // if original data is embedded document and value also - then merge
            if (is_array($newValue) && isset($document[$key]) && $this->isEmbeddedDocument($document[$key])) {
                $this->mergePartial($document[$key], $newValue, $prefix . $key . '.');
            } // in other cases just set new value
            else {
                $document[$key] = $newValue;
                $this->modifiedFields[] = $prefix . $key;
            }
        }
    }
181545
private function cascadePreUpdate(ClassMetadata $class, object $document) : void
    {
        foreach ($class->getEmbeddedFieldsMappings() as $mapping) {
            $value = $class->reflFields[$mapping['fieldName']]->getValue($document);
            if ($value === null) {
                continue;
            }
            $values = $mapping['type'] === ClassMetadata::ONE ? [$value] : $value;

            foreach ($values as $entry) {
                if ($this->uow->isScheduledForInsert($entry) || empty($this->uow->getDocumentChangeSet($entry))) {
                    continue;
                }
                $this->preUpdate($this->dm->getClassMetadata(get_class($entry)), $entry);
            }
        }
    }
573642
void addDocuments(final Document[] docs) throws IOException
   {
      final IndexWriter writer = getIndexWriter();

      IOException ioExc = null;
      try
      {
         for (Document doc : docs)
         {
            try
            {
               writer.addDocument(doc);
            }
            catch (Throwable e) //NOSONAR
            {
               if (ioExc == null)
               {
                  if (e instanceof IOException)
                  {
                     ioExc = (IOException)e;
                  }
                  else
                  {
                     ioExc = Util.createIOException(e);
                  }
               }

               log.warn("Exception while inverting document", e);
            }
         }
      }
      finally
      {
         invalidateSharedReader();
      }

      if (ioExc != null)
      {
         throw ioExc;
      }
   }
689497
public function delete($document): void
    {
        $class = $this->dm->getClassMetadata(get_class($document));
        $id = $class->getSingleIdentifier($document);

        $this->collection->delete((string) $id);
    }
1119904
public function getDocumentActualData(object $document) : array
    {
        $class      = $this->dm->getClassMetadata(get_class($document));
        $actualData = [];
        foreach ($class->reflFields as $name => $refProp) {
            $mapping = $class->fieldMappings[$name];
            // skip not saved fields
            if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) {
                continue;
            }
            $value = $refProp->getValue($document);
            if ((isset($mapping['association']) && $mapping['type'] === 'many')
                && $value !== null && ! ($value instanceof PersistentCollectionInterface)) {
                // If $actualData[$name] is not a Collection then use an ArrayCollection.
                if (! $value instanceof Collection) {
                    $value = new ArrayCollection($value);
                }

                // Inject PersistentCollection
                $coll = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $mapping, $value);
                $coll->setOwner($document, $mapping);
                $coll->setDirty(! $value->isEmpty());
                $class->reflFields[$name]->setValue($document, $coll);
                $actualData[$name] = $coll;
            } else {
                $actualData[$name] = $value;
            }
        }
        return $actualData;
    }
1158131
public function setOriginalDocumentData($document, array $data)
    {
        $oid                              = spl_object_hash($document);
        $this->originalDocumentData[$oid] = $data;

        unset($this->documentChangeSets[$oid]);
    }
225854
protected function addTagContentFields(Document  $document, $tagContent = [])
    {
        foreach ($tagContent as $fieldName => $fieldValue) {
            $document->setField($fieldName, $fieldValue);
        }
    }