NodeStorage.php 1.67 KB
Newer Older
1 2 3 4
<?php

namespace Drupal\node;

5
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
6
use Drupal\Core\Session\AccountInterface;
7
use Drupal\Core\Language\LanguageInterface;
8 9

/**
10
 * Defines the storage handler class for nodes.
11 12 13 14
 *
 * This extends the base storage class, adding required special handling for
 * node entities.
 */
15
class NodeStorage extends SqlContentEntityStorage implements NodeStorageInterface {
16 17 18 19 20 21 22

  /**
   * {@inheritdoc}
   */
  public function revisionIds(NodeInterface $node) {
    return $this->database->query(
      'SELECT vid FROM {node_revision} WHERE nid=:nid ORDER BY vid',
23
      [':nid' => $node->id()]
24 25 26 27 28 29 30 31 32
    )->fetchCol();
  }

  /**
   * {@inheritdoc}
   */
  public function userRevisionIds(AccountInterface $account) {
    return $this->database->query(
      'SELECT vid FROM {node_field_revision} WHERE uid = :uid ORDER BY vid',
33
      [':uid' => $account->id()]
34 35 36
    )->fetchCol();
  }

37 38 39 40
  /**
   * {@inheritdoc}
   */
  public function countDefaultLanguageRevisions(NodeInterface $node) {
41
    return $this->database->query('SELECT COUNT(*) FROM {node_field_revision} WHERE nid = :nid AND default_langcode = 1', [':nid' => $node->id()])->fetchField();
42 43
  }

44 45 46 47 48
  /**
   * {@inheritdoc}
   */
  public function updateType($old_type, $new_type) {
    return $this->database->update('node')
49
      ->fields(['type' => $new_type])
50 51 52 53 54 55 56
      ->condition('type', $old_type)
      ->execute();
  }

  /**
   * {@inheritdoc}
   */
57
  public function clearRevisionsLanguage(LanguageInterface $language) {
58
    return $this->database->update('node_revision')
59
      ->fields(['langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED])
60
      ->condition('langcode', $language->getId())
61 62
      ->execute();
  }
63

64
}