Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPC-9890: Fix some issues with the changed detection in content migrations #1210

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config/migrate_plus.migration.articles_hpc_content_module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ source:
label: Tags
selector: tags
-
name: content_space_title
name: content_space
label: 'Content space'
selector: content_space/title
selector: content_space
ids:
id:
type: integer
Expand Down Expand Up @@ -92,11 +92,11 @@ process:
-
plugin: skip_on_empty
method: process
source: content_space_title
source: content_space
-
plugin: entity_lookup
entity_type: taxonomy_term
source: content_space_title
source: content_space
bundle_key: vid
value_key: name
bundle: content_space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ source:
-
name: content_space
label: 'Content space'
selector: content_space/title
selector: content_space
ids:
id:
type: integer
Expand Down Expand Up @@ -85,11 +85,11 @@ process:
-
plugin: skip_on_empty
method: process
source: content_space/title
source: content_space
-
plugin: entity_lookup
entity_type: taxonomy_term
source: content_space/title
source: content_space
bundle_key: vid
value_key: name
bundle: content_space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,13 @@ abstract public function isUpToDateWithRemote(NodeInterface $node);
* A normalized array based on the given node object.
*/
protected function normalizeContentNodeData(NodeInterface $node) {
$migration = $this->getMigration($node);
$expected_fields = array_map(function ($item) {
return str_contains($item, '/') ? explode('/', $item)[0] : $item;
}, array_keys($migration->getProcess()));

$data = $node->toArray();
unset($data['changed']);
$data = array_intersect_key($data, array_flip($expected_fields));
ArrayHelper::sortMultiDimensionalArrayByKeys($data);
ArrayHelper::reduceArray($data);
$this->moduleHandler->alter('normalize_content', $data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use Drupal\hpc_api\Traits\SimpleCacheTrait;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\RequestOptions;

/**
* HPC Content Module specific remote source base class.
Expand Down Expand Up @@ -435,23 +437,19 @@ public function getContentUrl($id, $type = 'canonical') {
* {@inheritdoc}
*/
public function getFileSize($uri) {
$options = [
'http' => [
'method' => 'HEAD',
],
];
if ($basic_auth = $this->getRemoteBasicAuth()) {
$options['http'] = [
'header' => 'Authorization: Basic ' . base64_encode($basic_auth['user'] . ':' . $basic_auth['pass']),
$options[RequestOptions::AUTH] = [
$basic_auth['user'],
$basic_auth['pass'],
];
}
$context = stream_context_create($options);
$headers = @get_headers($uri, 1, $context);
if (!$headers) {
try {
$response = $this->httpClient->head($uri, $options);
}
catch (GuzzleException $e) {
return NULL;
}
$headers = array_change_key_case($headers);
return $headers['content-length'] ?? NULL;
return $response->getHeader('content-length') ?? NULL;
}

/**
Expand All @@ -460,13 +458,13 @@ public function getFileSize($uri) {
public function getFileContent($uri) {
$options = [];
if ($basic_auth = $this->getRemoteBasicAuth()) {
$options['http'] = [
'method' => 'GET',
'header' => 'Authorization: Basic ' . base64_encode($basic_auth['user'] . ':' . $basic_auth['pass']),
$options[RequestOptions::AUTH] = [
$basic_auth['user'],
$basic_auth['pass'],
];
}
$context = stream_context_create($options);
return @file_get_contents($uri, FALSE, $context);
$response = $this->httpClient->get($uri, $options);
return $response->getBody();
}

/**
Expand Down Expand Up @@ -534,6 +532,8 @@ public function getImportMetaData($type, ?array $tags) {
title
title_short
summary
content_space
tags
created
updated
status
Expand Down
Loading