Same name and namespace in other branches
  1. 7.x-1.x exif.drush.inc \__drush_exif_node_update() 1 comment
  2. 8.x-2.x exif.drush.inc \__drush_exif_node_update() 1 comment

Update all node of specified type.

Parameters

string $type: Name of the node type.

Return value

int Node count updated.

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to __drush_exif_node_update()
drush_exif_update in ./exif.drush.inc
Implements Drush callback.

File

./exif.drush.inc, line 287

Code

function __drush_exif_node_update($type = '') {
    $query = "SELECT n.nid FROM {node} n WHERE n.type = :type";
    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
    // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
    $result = \Drupal::database()->query($query, [
        ':type' => $type,
    ]);
    $count = 0;
    foreach ($result as $record) {
        // Load the node object from the database.
        $node = Node::load($record->nid);
        // Resave the node to make exif changes.
        $node->save();
        $count++;
    }
    drush_log(dt('Updated %count %type nodes.', [
        '%count' => $count,
        '%type' => $type,
    ]), "ok");
    return $count;
}