Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / workspaces / src / WorkspaceAssociationStorage.php
1 <?php
2
3 namespace Drupal\workspaces;
4
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
7
8 /**
9  * Defines the storage handler class for the Workspace association entity type.
10  */
11 class WorkspaceAssociationStorage extends SqlContentEntityStorage implements WorkspaceAssociationStorageInterface {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function postPush(WorkspaceInterface $workspace) {
17     $this->database
18       ->delete($this->entityType->getBaseTable())
19       ->condition('workspace', $workspace->id())
20       ->execute();
21     $this->database
22       ->delete($this->entityType->getRevisionTable())
23       ->condition('workspace', $workspace->id())
24       ->execute();
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function getTrackedEntities($workspace_id, $all_revisions = FALSE) {
31     $table = $all_revisions ? $this->getRevisionTable() : $this->getBaseTable();
32     $query = $this->database->select($table, 'base_table');
33     $query
34       ->fields('base_table', ['target_entity_type_id', 'target_entity_id', 'target_entity_revision_id'])
35       ->orderBy('target_entity_revision_id', 'ASC')
36       ->condition('workspace', $workspace_id);
37
38     $tracked_revisions = [];
39     foreach ($query->execute() as $record) {
40       $tracked_revisions[$record->target_entity_type_id][$record->target_entity_revision_id] = $record->target_entity_id;
41     }
42
43     return $tracked_revisions;
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function getEntityTrackingWorkspaceIds(EntityInterface $entity) {
50     $query = $this->database->select($this->getBaseTable(), 'base_table');
51     $query
52       ->fields('base_table', ['workspace'])
53       ->condition('target_entity_type_id', $entity->getEntityTypeId())
54       ->condition('target_entity_id', $entity->id());
55
56     return $query->execute()->fetchCol();
57   }
58
59 }