Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Better ID usage when using custom_id #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions mongodbadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ function getServer($server)
/**
* Render a document preview for the black code box with referenced
* linked to the collection and id for that database reference.
*
* @param string $document
**
* @param string $mongo
* @param array $document
* @return string $preview
*/
function renderDocumentPreview($mongo, $document)
function renderDocumentPreview($mongo, array $document)
{
$document = prepareMongoDBDocumentForEdit($document);
$preview = linkDocumentReferences($mongo, $document);
Expand Down Expand Up @@ -167,7 +168,7 @@ function prepareValueForMongoDB($value)
* @param array $value
* @return array $prepared
*/
function prepareMongoDBDocumentForEdit($value)
function prepareMongoDBDocumentForEdit(array $value)
{
$prepared = array();
foreach ($value as $key => $value) {
Expand Down Expand Up @@ -203,10 +204,13 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
$collection = $mongo->selectDB($db)->selectCollection($collection);

if (isset($_REQUEST['custom_id']) || $forceCustomId) {
if (is_numeric($id)) {
$id = (int) $id;
$document = $collection->findOne(array('_id' => $id));
if (!$document) {
if (is_numeric($id) && $id < PHP_INT_MAX) {
$id = (int) $id;
}
$document = $collection->findOne(array('_id' => $id));
}
$document =$collection->findOne(array('_id' => $id));
} else {
$document = $collection->findOne(array('_id' => new MongoId($id)));
}
Expand Down