Skip to content

Commit 218c421

Browse files
author
Steven Surowiec
committed
Fixed bug that caused updates to generate MongoIds when using custom ids
1 parent 7edc6aa commit 218c421

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

mongodbadmin.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,20 @@ function prepareValueForMongoDB($value)
101101

102102
if (is_string($value)) {
103103
eval('$value = ' . $value . ';');
104+
104105
if (!$value) {
105-
header('location: '.$_SERVER['HTTP_REFERER']);
106+
header('location: ' . $_SERVER['HTTP_REFERER'] . ($customId ? '&custom_id=1' : null));
106107
exit;
107108
}
108109
}
109110

110111
$prepared = array();
111112
foreach ($value as $k => $v) {
112-
if ($k === '_id' && $customId) {
113+
if ($k === '_id' && !$customId) {
113114
$v = new MongoId($v);
114-
}
115+
}
115116

116-
if ($k === '$id' && $customId) {
117+
if ($k === '$id' && !$customId) {
117118
$v = new MongoId($v);
118119
}
119120

@@ -271,13 +272,14 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
271272

272273
// INSERT OR UPDATE A DB COLLECTION DOCUMENT
273274
if (isset($_POST['save'])) {
275+
$customId = isset($_REQUEST['custom_id']);
274276
$collection = $mongo->selectDB($_REQUEST['db'])->selectCollection($_REQUEST['collection']);
275277

276278
$document = prepareValueForMongoDB($_REQUEST['value']);
277279
$collection->save($document);
278280

279281
$url = $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] . '&id=' . (string) $document['_id'];
280-
header('location: ' . $url);
282+
header('location: ' . $url . ($customId ? '&custom_id=1' : null));
281283
exit;
282284
}
283285

@@ -625,4 +627,3 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
625627
</div>
626628
</body>
627629
</html>
628-

0 commit comments

Comments
 (0)