You are here

protected function MongodbUserStorage::doSave in MongoDB 8

Performs storage-specific saving of the entity.

Parameters

int|string $id: The original entity ID.

\Drupal\Core\Entity\EntityInterface $entity: The entity to save.

Return value

bool|int If the record insert or update failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Overrides ContentEntityStorage::doSave

File

mongodb_user/src/MongodbUserStorage.php, line 35
Definition of Drupal\mongodb_user\MongodbUserStorage.

Class

MongodbUserStorage

Namespace

Drupal\mongodb_user

Code

protected function doSave($id, EntityInterface $entity) {
  if ($id === 1) {
    $this->mongo
      ->get('sequences')
      ->update([
      '_id' => 'entity.user',
    ], [
      '$setOnInsert' => [
        'seq' => 1,
      ],
    ], [
      'upsert' => TRUE,
    ]);
  }
  return parent::doSave($id, $entity);
}