/** * Constructor. * * @param string $bin * The name of the cache bin for which to build a backend. */ public function __construct($bin) { $this->bin = $bin; $this->collection = mongodb_collection($bin); // Default is FALSE: this is a cache, so a missed write is not an issue. $this->unsafe = mongodb_default_write_options(FALSE); $this->stampedeDelay = variable_get('mongodb_cache_stampede_delay', 5); $this->flushVarName = "flush_cache_{$bin}"; $this->binDataCreator = $this->getBinDataCreator(); }
/** * Select invidual votes from the database * * @param $criteria * A keyed array used to build the select query. Keys can contain * a single value or an array of values to be matched. * $criteria['vote_id'] (If this is set, all other keys are skipped) * $criteria['entity_id'] * $criteria['entity_type'] * $criteria['value_type'] * $criteria['tag'] * $criteria['uid'] * $criteria['vote_source'] * $criteria['timestamp'] If this is set, records with timestamps * GREATER THAN the set value will be selected. Defaults to * REQUEST_TIME - variable_get('votingapi_anonymous_window', 3600); if * the anonymous window is above zero. * @param $limit * An integer specifying the maximum number of votes to return. 0 means * unlimited and is the default. * @return * An array of votes matching the criteria. */ function hook_votingapi_storage_select_votes($criteria, $limit) { _mongodb_votingapi_prepare_vote($criteria); $find = array(); foreach ($criteria as $key => $value) { $find[$key] = is_array($value) ? array('$in' => $value) : $value; } $cursor = mongodb_collection('votingapi_vote')->find($find); if (!empty($limit)) { $cursor->limit($limit); } $votes = array(); foreach ($cursor as $vote) { $votes[] = $vote; } return $votes; }
'timestamp' => REQUEST_TIME, 'nid' => $nid, ), ), array('upsert' => TRUE) ); } if (variable_get('mongodb_statistics_enable_user_counter', 0)) { global $user; if (variable_get('mongodb_statistics_track_first_visit', 0)) { // A node has been viewed, maybe we'll have to record it's the first time for that user. // here we will act only if DRUPAL_BOOTSTRAP_SESSION was run and if the user is not anonymous if (isset($user) && $user->uid != 0) { $collectionname = variable_get('mongodb_user_counter_collection_name', 'user_counter'); $collection = mongodb_collection($collectionname); $uid = (int) $user->uid; $nid = isset($_POST['nid']) ? (int) $_POST['nid'] : 0; if ($nid) { $find = array( '_id' => $uid, 'visited' => $nid, ); $user_record = $collection->findOne($find, array('_id')); if (!$user_record) { // the user never visited that node before // record it and update timestamp for sync operations $collection->update( array('_id' => $uid), array( '$addToSet' => array(