Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MongoDbStore.php

function MongoDbStore::upsert

Update or Insert a Key.

Parameters

float $ttl Expiry in seconds from now:

2 calls to MongoDbStore::upsert()
MongoDbStore::putOffExpiration in vendor/symfony/lock/Store/MongoDbStore.php
MongoDbStore::save in vendor/symfony/lock/Store/MongoDbStore.php

File

vendor/symfony/lock/Store/MongoDbStore.php, line 300

Class

MongoDbStore
MongoDbStore is a StoreInterface implementation using MongoDB as a storage engine. Support for MongoDB server >=2.2 due to use of TTL indexes.

Namespace

Symfony\Component\Lock\Store

Code

private function upsert(Key $key, float $ttl) : void {
    $now = microtime(true);
    $token = $this->getUniqueToken($key);
    $write = new BulkWrite();
    $write->update([
        '_id' => (string) $key,
        '$or' => [
            [
                'token' => $token,
            ],
            [
                'expires_at' => [
                    '$lte' => $this->createMongoDateTime($now),
                ],
            ],
        ],
    ], [
        '$set' => [
            '_id' => (string) $key,
            'token' => $token,
            'expires_at' => $this->createMongoDateTime($now + $ttl),
        ],
    ], [
        'upsert' => true,
    ]);
    $this->getManager()
        ->executeBulkWrite($this->namespace, $write);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal