You are here

public function MongodbNodeStorage::updateType in MongoDB 8

Updates all nodes of one type to be of another type.

Parameters

string $old_type: The current node type of the nodes.

string $new_type: The new node type of the nodes.

Return value

int The number of nodes whose node type field was modified.

Overrides NodeStorageInterface::updateType

File

mongodb_node/src/MongodbNodeStorage.php, line 47
Contains \Drupal\node\MongodbNodeStorage.

Class

MongodbNodeStorage

Namespace

Drupal\mongodb_node

Code

public function updateType($old_type, $new_type) {
  $n = count(\Drupal::languageManager()
    ->getLanguages());
  $newobj['$set']['bundle'] = $new_type;
  for ($i = 0; $i < $n; $i++) {
    $newobj['$set']["values.{$i}.type.0.value"] = $new_type;
  }
  $this->mongo
    ->get('entity.node')
    ->update([
    'bundle' => $old_type,
  ], $newobj, [
    'multi' => TRUE,
  ]);
}