HeartbeatStorage.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Drupal\heartbeat;
  3. use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
  4. use Drupal\Core\Session\AccountInterface;
  5. use Drupal\Core\Language\LanguageInterface;
  6. use Drupal\heartbeat\Entity\HeartbeatInterface;
  7. /**
  8. * Defines the storage handler class for Heartbeat entities.
  9. *
  10. * This extends the base storage class, adding required special handling for
  11. * Heartbeat entities.
  12. *
  13. * @ingroup heartbeat
  14. */
  15. class HeartbeatStorage extends SqlContentEntityStorage implements HeartbeatStorageInterface {
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public function revisionIds(HeartbeatInterface $entity) {
  20. return $this->database->query(
  21. 'SELECT vid FROM {heartbeat_revision} WHERE id=:id ORDER BY vid',
  22. array(':id' => $entity->id())
  23. )->fetchCol();
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function userRevisionIds(AccountInterface $account) {
  29. return $this->database->query(
  30. 'SELECT vid FROM {heartbeat_field_revision} WHERE uid = :uid ORDER BY vid',
  31. array(':uid' => $account->id())
  32. )->fetchCol();
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function countDefaultLanguageRevisions(HeartbeatInterface $entity) {
  38. return $this->database->query('SELECT COUNT(*) FROM {heartbeat_field_revision} WHERE id = :id AND default_langcode = 1', array(':id' => $entity->id()))
  39. ->fetchField();
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function clearRevisionsLanguage(LanguageInterface $language) {
  45. return $this->database->update('heartbeat_revision')
  46. ->fields(array('langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED))
  47. ->condition('langcode', $language->getId())
  48. ->execute();
  49. }
  50. }