Skip to content
Browse files

Merge pull request #5 from jmikola/optional-dbref

Support optional "$db" keys in linkDocumentReferences()
  • Loading branch information...
2 parents affc267 + fe1fc0b commit edd2f8dbfb751b54cf9b93945d691eaeabad0f98 @jwage jwage committed Jun 8, 2011
Showing with 8 additions and 4 deletions.
  1. +8 −4 mongodbadmin.php
View
12 mongodbadmin.php
@@ -95,15 +95,19 @@ function linkDocumentReferences($mongo, $document)
$ref = findMongoDbDocument($value['$id'], $_REQUEST['db'], $value['$ref'], true);
}
- $document[$key]['$ref'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$value['$db'].'&collection='.$value['$ref'].'">'.$document[$key]['$ref'].'</a>';
+ $refDb = isset($value['$db']) ? $value['$db'] : $_REQUEST['db'];
+
+ $document[$key]['$ref'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$refDb.'&collection='.$value['$ref'].'">'.$value['$ref'].'</a>';
if ($ref['_id'] instanceof MongoId) {
- $document[$key]['$id'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$value['$db'].'&collection='.$value['$ref'].'&id='.$value['$id'].'">'.$document[$key]['$id'].'</a>';
+ $document[$key]['$id'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$refDb.'&collection='.$value['$ref'].'&id='.$value['$id'].'">'.$value['$id'].'</a>';
} else {
- $document[$key]['$id'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$value['$db'].'&collection='.$value['$ref'].'&id='.$value['$id'].'&custom_id=1">'.$document[$key]['$id'].'</a>';
+ $document[$key]['$id'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$refDb.'&collection='.$value['$ref'].'&id='.$value['$id'].'&custom_id=1">'.$value['$id'].'</a>';
}
- $document[$key]['$db'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$value['$db'].'">'.$document[$key]['$db'].'</a>';
+ if (isset($value['$db'])) {
+ $document[$key]['$db'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$refDb.'">'.$refDb.'</a>';
+ }
} else {
$document[$key] = linkDocumentReferences($mongo, $value);
}

0 comments on commit edd2f8d

Please sign in to comment.
Something went wrong with that request. Please try again.