From 7821227bb5614305120d658755a99300aca6c624 Mon Sep 17 00:00:00 2001 From: Eli Zoller Date: Tue, 11 Jun 2019 13:18:55 -0700 Subject: [PATCH 1/8] add versioning true/false --- .../system.action.version_node_in_fedora.yml | 15 +++++++++++++++ src/EventGenerator/EmitEvent.php | 1 + src/EventGenerator/EventGenerator.php | 5 +++++ src/Plugin/ContextReaction/VersionReaction.php | 15 +++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 modules/islandora_core_feature/config/install/system.action.version_node_in_fedora.yml create mode 100644 src/Plugin/ContextReaction/VersionReaction.php diff --git a/modules/islandora_core_feature/config/install/system.action.version_node_in_fedora.yml b/modules/islandora_core_feature/config/install/system.action.version_node_in_fedora.yml new file mode 100644 index 00000000..cc424410 --- /dev/null +++ b/modules/islandora_core_feature/config/install/system.action.version_node_in_fedora.yml @@ -0,0 +1,15 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - islandora_core_feature + module: + - islandora +id: version_node_in_fedora +label: 'Version Node in Fedora' +type: node +plugin: emit_node_event +configuration: + queue: islandora-indexing-fcrepo-content + event: Version diff --git a/src/EventGenerator/EmitEvent.php b/src/EventGenerator/EmitEvent.php index 2ee5bd55..22d36ff2 100644 --- a/src/EventGenerator/EmitEvent.php +++ b/src/EventGenerator/EmitEvent.php @@ -207,6 +207,7 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact '#description' => t('Type of event to emit'), '#options' => [ 'Create' => t('Create'), + 'Version' => t('Version'), 'Update' => t('Update'), 'Delete' => t('Delete'), 'Generate Derivative' => t('Generate Derivative'), diff --git a/src/EventGenerator/EventGenerator.php b/src/EventGenerator/EventGenerator.php index a9e4ac66..eccb0d43 100644 --- a/src/EventGenerator/EventGenerator.php +++ b/src/EventGenerator/EventGenerator.php @@ -104,6 +104,11 @@ class EventGenerator implements EventGeneratorInterface { $event["type"] = ucfirst($data["event"]); $event["summary"] = ucfirst($data["event"]) . " a " . ucfirst($entity_type); } + if ($data["event"] == "Update"){ + $event["object"]["createVersion"] = TRUE; + } else { + $event["object"]["createVersion"] = FALSE; + } // Add REST links for non-file entities. if ($entity_type != 'file') { diff --git a/src/Plugin/ContextReaction/VersionReaction.php b/src/Plugin/ContextReaction/VersionReaction.php new file mode 100644 index 00000000..67590955 --- /dev/null +++ b/src/Plugin/ContextReaction/VersionReaction.php @@ -0,0 +1,15 @@ + Date: Thu, 25 Jul 2019 13:43:52 -0700 Subject: [PATCH 2/8] pass the event type through to alpaca, rename action, remove reaction since it can be fired with the IndexReaction --- ...stem.action.create_node_version_in_fedora.yml} | 4 ++-- src/EventGenerator/EventGenerator.php | 7 ++----- src/Plugin/ContextReaction/VersionReaction.php | 15 --------------- 3 files changed, 4 insertions(+), 22 deletions(-) rename modules/islandora_core_feature/config/install/{system.action.version_node_in_fedora.yml => system.action.create_node_version_in_fedora.yml} (75%) delete mode 100644 src/Plugin/ContextReaction/VersionReaction.php diff --git a/modules/islandora_core_feature/config/install/system.action.version_node_in_fedora.yml b/modules/islandora_core_feature/config/install/system.action.create_node_version_in_fedora.yml similarity index 75% rename from modules/islandora_core_feature/config/install/system.action.version_node_in_fedora.yml rename to modules/islandora_core_feature/config/install/system.action.create_node_version_in_fedora.yml index cc424410..bdaa1eb1 100644 --- a/modules/islandora_core_feature/config/install/system.action.version_node_in_fedora.yml +++ b/modules/islandora_core_feature/config/install/system.action.create_node_version_in_fedora.yml @@ -6,8 +6,8 @@ dependencies: - islandora_core_feature module: - islandora -id: version_node_in_fedora -label: 'Version Node in Fedora' +id: create_node_version_in_fedora +label: 'Create Node Version in Fedora' type: node plugin: emit_node_event configuration: diff --git a/src/EventGenerator/EventGenerator.php b/src/EventGenerator/EventGenerator.php index eccb0d43..4e73a145 100644 --- a/src/EventGenerator/EventGenerator.php +++ b/src/EventGenerator/EventGenerator.php @@ -104,11 +104,8 @@ class EventGenerator implements EventGeneratorInterface { $event["type"] = ucfirst($data["event"]); $event["summary"] = ucfirst($data["event"]) . " a " . ucfirst($entity_type); } - if ($data["event"] == "Update"){ - $event["object"]["createVersion"] = TRUE; - } else { - $event["object"]["createVersion"] = FALSE; - } + + $event["object"]["type"] = $event["type"]; // Add REST links for non-file entities. if ($entity_type != 'file') { diff --git a/src/Plugin/ContextReaction/VersionReaction.php b/src/Plugin/ContextReaction/VersionReaction.php deleted file mode 100644 index 67590955..00000000 --- a/src/Plugin/ContextReaction/VersionReaction.php +++ /dev/null @@ -1,15 +0,0 @@ - Date: Fri, 9 Aug 2019 16:00:15 -0700 Subject: [PATCH 3/8] check if the entityType isVersionable and check if it shouldCreateNewRevision before setting the Version flag --- src/EventGenerator/EventGenerator.php | 33 ++++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/EventGenerator/EventGenerator.php b/src/EventGenerator/EventGenerator.php index 4debec35..865c9b90 100644 --- a/src/EventGenerator/EventGenerator.php +++ b/src/EventGenerator/EventGenerator.php @@ -12,7 +12,8 @@ use Drupal\user\UserInterface; * * Provides Activity Stream 2.0 serialized events. */ -class EventGenerator implements EventGeneratorInterface { +class EventGenerator implements EventGeneratorInterface +{ /** * Islandora utils. @@ -36,7 +37,8 @@ class EventGenerator implements EventGeneratorInterface { * @param \Drupal\islandora\MediaSource\MediaSourceService $media_source * Media source service. */ - public function __construct(IslandoraUtils $utils, MediaSourceService $media_source) { + public function __construct(IslandoraUtils $utils, MediaSourceService $media_source) + { $this->utils = $utils; $this->mediaSource = $media_source; } @@ -44,7 +46,8 @@ class EventGenerator implements EventGeneratorInterface { /** * {@inheritdoc} */ - public function generateEvent(EntityInterface $entity, UserInterface $user, array $data) { + public function generateEvent(EntityInterface $entity, UserInterface $user, array $data) + { $user_url = $this->utils->getEntityUrl($user); @@ -53,8 +56,7 @@ class EventGenerator implements EventGeneratorInterface { if ($entity_type == 'file') { $entity_url = $this->utils->getDownloadUrl($entity); $mimetype = $entity->getMimeType(); - } - else { + } else { $entity_url = $this->utils->getEntityUrl($entity); $mimetype = 'text/html'; } @@ -93,13 +95,17 @@ class EventGenerator implements EventGeneratorInterface { if ($data["event"] == "Generate Derivative") { $event["type"] = "Activity"; $event["summary"] = $data["event"]; - } - else { + } else { $event["type"] = ucfirst($data["event"]); $event["summary"] = ucfirst($data["event"]) . " a " . ucfirst($entity_type); } - $event["object"]["type"] = $event["type"]; + if ($entity->getEntityType()->isRevisionable()) { + $isNewRev = $this->isNewRevision($entity); + if ($isNewRev) { + $event["object"]["type"] = "Version"; + } + } // Add REST links for non-file entities. if ($entity_type != 'file') { @@ -147,4 +153,15 @@ class EventGenerator implements EventGeneratorInterface { return json_encode($event); } + /** + * @param $entity EntityInterface + * returns Boolean + */ + protected function isNewRevision(EntityInterface $entity) + { + // revisions tab. + $bundle_entity_type = $entity->getEntityType()->getBundleEntityType(); + $bundle_entity = \Drupal::entityTypeManager()->getStorage($bundle_entity_type)->load($entity->bundle()); + return $bundle_entity->shouldCreateNewRevision(); + } } From bb0e5ee27e4b9f4411aafc7dbd16319c0a106fe2 Mon Sep 17 00:00:00 2001 From: Eli Zoller Date: Fri, 9 Aug 2019 16:01:23 -0700 Subject: [PATCH 4/8] change from event type is isNewVersion flag --- src/EventGenerator/EventGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EventGenerator/EventGenerator.php b/src/EventGenerator/EventGenerator.php index 865c9b90..f04b5bb0 100644 --- a/src/EventGenerator/EventGenerator.php +++ b/src/EventGenerator/EventGenerator.php @@ -103,7 +103,7 @@ class EventGenerator implements EventGeneratorInterface if ($entity->getEntityType()->isRevisionable()) { $isNewRev = $this->isNewRevision($entity); if ($isNewRev) { - $event["object"]["type"] = "Version"; + $event["object"]["isNewVersion"] = $isNewRev; } } From 97996cb77facaf0d5fbbdc6c0b1fe2a4856ec94e Mon Sep 17 00:00:00 2001 From: Eli Zoller Date: Fri, 9 Aug 2019 16:10:13 -0700 Subject: [PATCH 5/8] helps with travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 82b526f8..2743abda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ language: php php: - 7.1 - 7.2 +services: + - mysql matrix: fast_finish: true From 12e08a59b19b10a2fe798d890bddff01d4cf3e9f Mon Sep 17 00:00:00 2001 From: Eli Zoller Date: Fri, 9 Aug 2019 16:11:49 -0700 Subject: [PATCH 6/8] remove previous attempt with emitting a separate versioning event --- ...ystem.action.create_node_version_in_fedora.yml | 15 --------------- src/EventGenerator/EmitEvent.php | 1 - 2 files changed, 16 deletions(-) delete mode 100644 modules/islandora_core_feature/config/install/system.action.create_node_version_in_fedora.yml diff --git a/modules/islandora_core_feature/config/install/system.action.create_node_version_in_fedora.yml b/modules/islandora_core_feature/config/install/system.action.create_node_version_in_fedora.yml deleted file mode 100644 index bdaa1eb1..00000000 --- a/modules/islandora_core_feature/config/install/system.action.create_node_version_in_fedora.yml +++ /dev/null @@ -1,15 +0,0 @@ -langcode: en -status: true -dependencies: - enforced: - module: - - islandora_core_feature - module: - - islandora -id: create_node_version_in_fedora -label: 'Create Node Version in Fedora' -type: node -plugin: emit_node_event -configuration: - queue: islandora-indexing-fcrepo-content - event: Version diff --git a/src/EventGenerator/EmitEvent.php b/src/EventGenerator/EmitEvent.php index 22d36ff2..2ee5bd55 100644 --- a/src/EventGenerator/EmitEvent.php +++ b/src/EventGenerator/EmitEvent.php @@ -207,7 +207,6 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact '#description' => t('Type of event to emit'), '#options' => [ 'Create' => t('Create'), - 'Version' => t('Version'), 'Update' => t('Update'), 'Delete' => t('Delete'), 'Generate Derivative' => t('Generate Derivative'), From 6fa26131992660672378c47ce3518e0a44cd1142 Mon Sep 17 00:00:00 2001 From: Eli Zoller Date: Mon, 12 Aug 2019 09:59:58 -0700 Subject: [PATCH 7/8] phpcs got me --- src/EventGenerator/EventGenerator.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/EventGenerator/EventGenerator.php b/src/EventGenerator/EventGenerator.php index f04b5bb0..a7038ffb 100644 --- a/src/EventGenerator/EventGenerator.php +++ b/src/EventGenerator/EventGenerator.php @@ -154,12 +154,16 @@ class EventGenerator implements EventGeneratorInterface } /** - * @param $entity EntityInterface - * returns Boolean + * Method to check if an entity is a new revision. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * Drupal Entity. + * + * @return bool + * Is new version. */ protected function isNewRevision(EntityInterface $entity) { - // revisions tab. $bundle_entity_type = $entity->getEntityType()->getBundleEntityType(); $bundle_entity = \Drupal::entityTypeManager()->getStorage($bundle_entity_type)->load($entity->bundle()); return $bundle_entity->shouldCreateNewRevision(); From dca92ae8770f1f278b23ce6a6f49f7cda49b4bdd Mon Sep 17 00:00:00 2001 From: Eli Zoller Date: Mon, 12 Aug 2019 10:40:52 -0700 Subject: [PATCH 8/8] more phpc --- src/EventGenerator/EventGenerator.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/EventGenerator/EventGenerator.php b/src/EventGenerator/EventGenerator.php index a7038ffb..e5602f32 100644 --- a/src/EventGenerator/EventGenerator.php +++ b/src/EventGenerator/EventGenerator.php @@ -12,8 +12,7 @@ use Drupal\user\UserInterface; * * Provides Activity Stream 2.0 serialized events. */ -class EventGenerator implements EventGeneratorInterface -{ +class EventGenerator implements EventGeneratorInterface { /** * Islandora utils. @@ -37,8 +36,7 @@ class EventGenerator implements EventGeneratorInterface * @param \Drupal\islandora\MediaSource\MediaSourceService $media_source * Media source service. */ - public function __construct(IslandoraUtils $utils, MediaSourceService $media_source) - { + public function __construct(IslandoraUtils $utils, MediaSourceService $media_source) { $this->utils = $utils; $this->mediaSource = $media_source; } @@ -46,8 +44,7 @@ class EventGenerator implements EventGeneratorInterface /** * {@inheritdoc} */ - public function generateEvent(EntityInterface $entity, UserInterface $user, array $data) - { + public function generateEvent(EntityInterface $entity, UserInterface $user, array $data) { $user_url = $this->utils->getEntityUrl($user); @@ -56,7 +53,8 @@ class EventGenerator implements EventGeneratorInterface if ($entity_type == 'file') { $entity_url = $this->utils->getDownloadUrl($entity); $mimetype = $entity->getMimeType(); - } else { + } + else { $entity_url = $this->utils->getEntityUrl($entity); $mimetype = 'text/html'; } @@ -95,7 +93,8 @@ class EventGenerator implements EventGeneratorInterface if ($data["event"] == "Generate Derivative") { $event["type"] = "Activity"; $event["summary"] = $data["event"]; - } else { + } + else { $event["type"] = ucfirst($data["event"]); $event["summary"] = ucfirst($data["event"]) . " a " . ucfirst($entity_type); } @@ -162,10 +161,10 @@ class EventGenerator implements EventGeneratorInterface * @return bool * Is new version. */ - protected function isNewRevision(EntityInterface $entity) - { + protected function isNewRevision(EntityInterface $entity) { $bundle_entity_type = $entity->getEntityType()->getBundleEntityType(); $bundle_entity = \Drupal::entityTypeManager()->getStorage($bundle_entity_type)->load($entity->bundle()); return $bundle_entity->shouldCreateNewRevision(); } + }