From a36654cfbbbc4fe8470920fc99e54540afecedac Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 29 May 2020 22:43:58 +0100 Subject: [PATCH] Remove custom migration code References #77 --- .../migrate_plus.migration.post_node.yml | 82 --------------- .../migrate_plus.migration.redirect.yml | 51 ---------- .../migrate_plus.migration.tag_term.yml | 27 ----- .../migrate_plus.migration.talk_node.yml | 86 ---------------- .../Plugin/migrate/destination/OpdTalk.php | 99 ------------------- .../Plugin/migrate/process/OpdRedirect.php | 29 ------ 6 files changed, 374 deletions(-) delete mode 100644 web/modules/custom/custom/migrations/migrate_plus.migration.post_node.yml delete mode 100644 web/modules/custom/custom/migrations/migrate_plus.migration.redirect.yml delete mode 100644 web/modules/custom/custom/migrations/migrate_plus.migration.tag_term.yml delete mode 100644 web/modules/custom/custom/migrations/migrate_plus.migration.talk_node.yml delete mode 100644 web/modules/custom/custom/src/Plugin/migrate/destination/OpdTalk.php delete mode 100644 web/modules/custom/custom/src/Plugin/migrate/process/OpdRedirect.php diff --git a/web/modules/custom/custom/migrations/migrate_plus.migration.post_node.yml b/web/modules/custom/custom/migrations/migrate_plus.migration.post_node.yml deleted file mode 100644 index 3a7f6ff..0000000 --- a/web/modules/custom/custom/migrations/migrate_plus.migration.post_node.yml +++ /dev/null @@ -1,82 +0,0 @@ -id: post_node - -source: - plugin: url - data_fetcher_plugin: http - data_parser_plugin: json - - urls: https://opdavies.netlify.app/posts.json - - ids: - id: - type: integer - - item_selector: posts/ - - fields: - - name: id - selector: id - label: Node ID - - - name: title - selector: title - label: Title - - - name: excerpt - selector: excerpt - label: Excerpt - - - name: created - selector: created - label: Created - - - name: status - selector: status - label: Status - - - name: content - selector: content - label: Content - - - name: path - selector: path - label: Path - - - name: tags - selector: tags - label: Tags - -process: - body/0/format: - plugin: default_value - default_value: full_html - - body/0/value: content - - title: title - created: created - changed: created - path: path - status: status - - field_excerpt: excerpt - - field_tags: - plugin: migration_lookup - migration: tag_term - source: tags - - type: - plugin: default_value - default_value: post - - uid: - plugin: default_value - default_value: 1 - -destination: - plugin: 'entity:node' - -migration_dependencies: - required: - - tag_term diff --git a/web/modules/custom/custom/migrations/migrate_plus.migration.redirect.yml b/web/modules/custom/custom/migrations/migrate_plus.migration.redirect.yml deleted file mode 100644 index 6b405fa..0000000 --- a/web/modules/custom/custom/migrations/migrate_plus.migration.redirect.yml +++ /dev/null @@ -1,51 +0,0 @@ -id: redirect - -source: - plugin: url - data_fetcher_plugin: http - data_parser_plugin: json - - urls: https://opdavies.netlify.app/redirects.json - - ids: - id: - type: integer - - item_selector: redirects/ - - fields: - - name: id - selector: id - label: Redirect ID - - - name: from - selector: from - label: From - - - name: to - selector: to - label: To - -process: - redirect_source/path: from - redirect_redirect/uri: - plugin: opd_redirect - source: to - - language: - plugin: default_value - default_value: und - - status_code: - plugin: default_value - default_value: 301 - - uid: - plugin: default_value - default_value: 1 - -destination: - plugin: 'entity:redirect' - -migration_dependencies: - required: { } diff --git a/web/modules/custom/custom/migrations/migrate_plus.migration.tag_term.yml b/web/modules/custom/custom/migrations/migrate_plus.migration.tag_term.yml deleted file mode 100644 index 3634ec5..0000000 --- a/web/modules/custom/custom/migrations/migrate_plus.migration.tag_term.yml +++ /dev/null @@ -1,27 +0,0 @@ -id: tag_term - -source: - plugin: url - data_fetcher_plugin: http - data_parser_plugin: json - urls: https://opdavies.netlify.app/tags.json - ids: - name: - type: string - item_selector: tags/ - fields: - - - name: id - selector: id - label: Tag ID - - - name: name - selector: name - label: Name - -process: - name: name - -destination: - plugin: 'entity:taxonomy_term' - default_bundle: tags diff --git a/web/modules/custom/custom/migrations/migrate_plus.migration.talk_node.yml b/web/modules/custom/custom/migrations/migrate_plus.migration.talk_node.yml deleted file mode 100644 index e2b1183..0000000 --- a/web/modules/custom/custom/migrations/migrate_plus.migration.talk_node.yml +++ /dev/null @@ -1,86 +0,0 @@ -id: talk_node - -source: - plugin: url - data_fetcher_plugin: http - data_parser_plugin: json - - urls: https://opdavies.netlify.app/talks.json - - ids: - id: - type: integer - - item_selector: talks/ - - fields: - - name: id - selector: id - label: Node ID - - - name: title - selector: title - label: Title - - - name: description - selector: description - label: Description - - - name: created - selector: created - label: Created - - - name: content - selector: content - label: Content - - - name: path - selector: path - label: Path - - - name: speakerdeck - selector: speakerdeck - label: Speakerdeck - - - name: events - selector: events - label: Events - - - name: video - selector: video - label: Video - -process: - body/0/format: - plugin: default_value - default_value: full_html - - body/0/value: content - - field_excerpt: description - - title: title - created: created - changed: created - path: path - - field_slides/0/data_id: speakerdeck/id - field_slides/0/data_ratio: speakerdeck/ratio - - status: - plugin: default_value - default_value: 1 - - type: - plugin: default_value - default_value: talk - - uid: - plugin: default_value - default_value: 1 - -destination: - plugin: opd_talk - -migration_dependencies: - required: { } diff --git a/web/modules/custom/custom/src/Plugin/migrate/destination/OpdTalk.php b/web/modules/custom/custom/src/Plugin/migrate/destination/OpdTalk.php deleted file mode 100644 index 623c490..0000000 --- a/web/modules/custom/custom/src/Plugin/migrate/destination/OpdTalk.php +++ /dev/null @@ -1,99 +0,0 @@ -getDestination(); - - if ($nodes = $this->storage->loadByProperties(['title' => $data['title']])) { - $node = current($nodes); - } - else { - $node = $this->storage->create($data); - } - - $this->createEventParagraphs($row, $node); - $this->createVideoMedia($row, $node); - - $node->save(); - - return [$node->id()]; - } - - private function createEventParagraphs(Row $row, EntityInterface $node): void { - $eventData = $row->getSourceProperty('events'); - - Collection::make($eventData)->map(function (array $event): array { - $paragraph = Paragraph::create([ - 'field_date' => DrupalDateTime::createFromTimestamp($event['date']) - ->format(DateTimeItemInterface::DATE_STORAGE_FORMAT), - 'field_link' => $event['url'], - 'field_location' => $event['location'], - 'field_name' => $event['name'], - 'field_remote' => $event['remote'] == 'true' ? 1 : 0, - 'type' => 'event', - ]); - - $paragraph->save(); - - return [ - 'target_id' => $paragraph->id(), - 'target_revision_id' => $paragraph->getRevisionId(), - ]; - })->pipe(function (Collection $events) use ($node) { - $node->set('field_events', $events->toArray()); - }); - } - - private function createVideoMedia(Row $row, EntityInterface $node): void { - $video = $row->getSourceProperty('video'); - - if (!empty($video['type']) && !empty($video['id'])) { - $video = Media::create([ - 'bundle' => 'video', - 'field_media_oembed_video' => [ - 'value' => $this->getVideoUrlFromId($video), - ], - 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(), - 'uid' => 1, - ]); - - $node->set('field_video', tap($video)->save()); - } - } - - private function getVideoUrlFromId(array $video): string { - $urls = new Collection([ - 'vimeo' => 'https://vimeo.com/', - 'youtube' => 'https://www.youtube.com/watch?v=', - ]); - - return $urls->get($video['type']) . $video['id']; - } - -} diff --git a/web/modules/custom/custom/src/Plugin/migrate/process/OpdRedirect.php b/web/modules/custom/custom/src/Plugin/migrate/process/OpdRedirect.php deleted file mode 100644 index 6be1d82..0000000 --- a/web/modules/custom/custom/src/Plugin/migrate/process/OpdRedirect.php +++ /dev/null @@ -1,29 +0,0 @@ -