Skip to content

Commit

Permalink
Merge pull request #122 from nlisgo/feature/articles_endpoint_for_mig…
Browse files Browse the repository at this point in the history
…ration

Add alternative endpoint for articles during migration
  • Loading branch information
nlisgo committed Mar 17, 2017
2 parents a79adc4 + 25b4c27 commit 8041e80
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 25 deletions.
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"drupal/paragraphs": "~1.0",
"drupal-composer/drupal-project": "8.x-dev",
"drupal/migrate_plus": "~3.0-beta1",
"drupal/migrate_tools": "~2.0@dev",
"drupal/migrate_tools": "^2.0",
"drupal/migrate_manifest": "^1",
"drupal/redis": "~1.0-beta1",
"drupal/restui": "1.x-dev",
Expand Down Expand Up @@ -109,9 +109,6 @@
]
},
"patches": {
"drupal/config_installer": {
"array_diff warning during profile installation": "https://www.drupal.org/files/issues/config_installer-array-warning-2760923-2.patch"
},
"drupal/core": {
"CommandLineOrUnsafeMethodTest::testHttpMethod failures": "https://www.drupal.org/files/issues/options_trace_error-2776367-3.patch",
"View output is not used for autocomplete display": "https://www.drupal.org/files/issues/2174633-76-entity-reference-views.patch",
Expand Down
33 changes: 15 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/modules/jcms_article/jcms_article.module
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ function jcms_article_node_presave(EntityInterface $entity) {
return NULL;
}
$node_presave = \Drupal::service('jcms_article.hooks.node_presave');
if (!empty($entity->migration)) {
$node_presave->forMigrationOnly();
}
$article = $node_presave->getArticleById($entity->label());
$node_presave->addJsonFields($entity, $article);
$node_presave->setPublishedStatus($entity, $article);
Expand Down
11 changes: 11 additions & 0 deletions src/modules/jcms_article/src/FetchArticleVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public function __construct(Client $client) {
}
}

/**
* Allow an alternate endpoint to be set.
*
* @param $endpoint
*/
public function setEndpoint($endpoint) {
if (!empty($endpoint)) {
$this->endpoint = $endpoint;
}
}

/**
* Gets article versions by ID.
*
Expand Down
8 changes: 8 additions & 0 deletions src/modules/jcms_article/src/Hooks/NodePresave.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\jcms_article\Hooks;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Site\Settings;
use Drupal\jcms_article\FetchArticleVersions;
use Drupal\paragraphs\Entity\Paragraph;

Expand Down Expand Up @@ -170,4 +171,11 @@ private function loadTermIdByIdField(string $id): int {
return $tid;
}

/**
* Set alternative endpoint if we are fetching for migration only.
*/
public function forMigrationOnly() {
$this->fetchArticleVersions->setEndpoint(Settings::get('jcms_articles_endpoint_for_migration'));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ process:
migration_dependencies:
required:
- jcms_users_db
- jcms_subjects_json
- jcms_blog_articles_db
- jcms_collections_db
- jcms_collections_json
Expand Down
4 changes: 4 additions & 0 deletions src/modules/jcms_migrate/jcms_migrate.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ services:
jcms_migrate.s3_client:
class: Aws\S3\S3Client
arguments: ['%jcms_migrate.s3_client.options%']

jcms_migrate.article_crud:
class: Drupal\jcms_migrate\ArticleCrud
arguments: ["@entity_type.manager"]
52 changes: 52 additions & 0 deletions src/modules/jcms_migrate/src/ArticleCrud.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Drupal\jcms_migrate;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\jcms_article\Entity\ArticleVersions;
use Drupal\node\Entity\Node;
use Drupal\paragraphs\Entity\Paragraph;

/**
* Class ArticleCrud
*
* @package Drupal\jcms_migrate
*/
class ArticleCrud extends \Drupal\jcms_article\ArticleCrud {

/**
* ArticleCrud constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
*/
public function __construct(EntityTypeManager $entity_type_manager) {
parent::__construct($entity_type_manager);
}

/**
* Creates a new article node.
*
* @param \Drupal\jcms_article\Entity\ArticleVersions $articleVersions
*
* @return \Drupal\Core\Entity\EntityInterface
*/
public function createArticle(ArticleVersions $articleVersions) {
$node = Node::create([
'type' => 'article',
'title' => $articleVersions->getId(),
]);
// Set flag for article nodes created during migration.
$node->migration = TRUE;
$paragraph = $this->createParagraph($node, $articleVersions);
$node->field_article_json = [
[
'target_id' => $paragraph->id(),
'target_revision_id' => $paragraph->getRevisionId(),
],
];
$node->save();
return $node;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function processItemValue($type, $source, MigrateExecutableInterface $mi
return $this->migrationDestionationIDs('jcms_podcast_episodes_json', $source, $migrate_executable, $row, $destination_property);
break;
case 'article':
$crud_service = \Drupal::service('jcms_article.article_crud');
$crud_service = \Drupal::service('jcms_migrate.article_crud');
if ($nid = $crud_service->getNodeIdByArticleId($source)) {
return $nid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
$values['field_related_content'][] = ['target_id' => $this->migrationDestionationIDs('jcms_collections_db', $content['source'], $migrate_executable, $row, $destination_property)];
break;
case 'article':
$crud_service = \Drupal::service('jcms_article.article_crud');
$crud_service = \Drupal::service('jcms_migrate.article_crud');
if ($article_nid = $crud_service->getNodeIdByArticleId($content['source'])) {
$values['field_related_content'][] = ['target_id' => $article_nid];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private function processItemValue($type, $source, MigrateExecutableInterface $mi
return $chapter['target_id'];
break;
case 'article':
$crud_service = \Drupal::service('jcms_article.article_crud');
$crud_service = \Drupal::service('jcms_migrate.article_crud');
if ($nid = $crud_service->getNodeIdByArticleId($source)) {
return $nid;
}
Expand Down
1 change: 1 addition & 0 deletions sync/migrate_plus.migration.jcms_highlight_lists_json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ destination:
migration_dependencies:
required:
- jcms_users_db
- jcms_subjects_json
- jcms_blog_articles_db
- jcms_collections_db
- jcms_collections_json
Expand Down

0 comments on commit 8041e80

Please sign in to comment.