You are here

function mongodb_collection_name in MongoDB 6

Same name and namespace in other branches
  1. 7 mongodb.module \mongodb_collection_name()

Returns the name to use for the collection.

Works with prefixes and simpletest.

Parameters

string $name: The base name for the collection.

Return value

string Unlike the base name, the returned name works with prefixes and simpletest.

2 calls to mongodb_collection_name()
mongodb_collection in ./mongodb.module
Returns a MongoCollection object.
mongodb_next_id in ./mongodb.module
Return the next id in a sequence.

File

./mongodb.module, line 228
A library of common mechanisms for modules using MongoDB.

Code

function mongodb_collection_name($name) {
  global $db_prefix;
  static $simpletest_prefix;

  // We call this function earlier than the database is initalized so we would
  // read the parent collection without this.
  if (!isset($simpletest_prefix)) {
    if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^(simpletest\\d+);/", $_SERVER['HTTP_USER_AGENT'], $matches)) {
      $simpletest_prefix = $matches[1];
    }
    else {
      $simpletest_prefix = '';
    }
  }

  // However, once the test information is initialized, simpletest_prefix
  // is no longer needed.
  if (!empty($GLOBALS['drupal_test_info']['test_run_id'])) {
    $simpletest_prefix = $GLOBALS['drupal_test_info']['test_run_id'];
  }
  return $simpletest_prefix . $name;
}