Skip to content

Commit

Permalink
Merge pull request #454 from UN-OCHA/develop
Browse files Browse the repository at this point in the history
Develop -> Main - v1.3.2
  • Loading branch information
orakili committed Sep 6, 2022
2 parents 9de6965 + 1fcb4cd commit 6117ab2
Show file tree
Hide file tree
Showing 15 changed files with 388 additions and 212 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"drupal/social_auth_hid": "^3.0",
"drupal/svg_image": "^1.15",
"drupal/taxonomy_term_preview": "^1.0.0",
"drupal/taxonomy_term_revision": "1.x-dev",
"drupal/taxonomy_term_revision": "^1.1",
"drupal/theme_switcher": "^1.2",
"drupal/token": "^1.10",
"drupal/user_display_name": "^1.0",
Expand Down
447 changes: 249 additions & 198 deletions composer.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ process:
body/format:
plugin: default_value
default_value: markdown_editor
field_career_categories/value:
field_career_categories:
plugin: sub_process
source: field_career_categories
process:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ process:
plugin: skip_on_empty
method: process
source: field_bury/0/value
field_content_format/value:
field_content_format:
plugin: sub_process
source: field_content_format
process:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ process:
body/format:
plugin: default_value
default_value: markdown_editor
field_career_categories/value:
field_career_categories:
plugin: sub_process
source: field_career_categories
process:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ local attachment_file = ngx.var.attachment_file
-- the URL, URI in DB and file on disk in D7.
-- This can also be used to handle aliases for some specific files.
local symlink = ngx.var.document_root .. '/sites/default/files/legacy-attachments/' .. attachment_file;
local handle = io.popen('readlink "' .. symlink .. '"')
local escaped = symlink:gsub('"', ''):gsub("'", ""):gsub('`', ''):gsub('%$', ''):gsub('%!', '')
local handle = io.popen('readlink "' .. escaped .. '"')
local target = handle:read()
handle:close()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ end
-- Some legacy preview file names cannot be derived from the PDF file name, in
-- that case there should be a symlink pointing to the new preview.
local symlink = ngx.var.document_root .. '/sites/default/files/legacy-previews/' .. ngx.var.file_id .. '.' .. image_ext;
local handle = io.popen('readlink "' .. symlink .. '"')
local escaped = symlink:gsub('"', ''):gsub("'", ""):gsub('`', ''):gsub('%$', ''):gsub('%!', '')
local handle = io.popen('readlink "' .. escaped .. '"')
local target = handle:read()
handle:close()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ local image_ext = 'png'
-- Some legacy preview file names cannot be derived from the PDF file name, in
-- that case there should be a symlink pointing to the new preview.
local symlink = ngx.var.document_root .. '/sites/default/files/legacy-previews/' .. ngx.var.file_id .. '.' .. image_ext;
local handle = io.popen('readlink "' .. symlink .. '"')
local escaped = symlink:gsub('"', ''):gsub("'", ""):gsub('`', ''):gsub('%$', ''):gsub('%!', '')
local handle = io.popen('readlink "' .. escaped .. '"')
local target = handle:read()
handle:close()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ process:
body/format:
plugin: default_value
default_value: "markdown_editor"
field_career_categories/value:
field_career_categories:
plugin: sub_process
source: field_career_categories
process:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ process:
plugin: skip_on_empty
method: process
source: field_bury/0/value
field_content_format/value:
field_content_format:
plugin: sub_process
source: field_content_format
process:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ process:
body/format:
plugin: default_value
default_value: "markdown_editor"
field_career_categories/value:
field_career_categories:
plugin: sub_process
source: field_career_categories
process:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2160,4 +2160,126 @@ public function migrateFileRevisions($options = [
}
}

/**
* Migrated job/training career categories revisions.
*
* @command rw-migrate:migrate-career-categories-revisions
*
* @usage rw-migrate:migrate-career-categories-revisions
* Migrated career categories revisions
*
* @validate-module-enabled reliefweb_migrate
*/
public function migrateCareerCategoriesRevisions(array $options = [
'dry-run' => FALSE,
]) {
$last_id = 0;
$count = 0;
$fields = [
'bundle',
'deleted',
'entity_id',
'revision_id',
'langcode',
'delta',
'field_career_categories_target_id',
];
$query_options = [
// Note: this is deprecated in Drupal 9.4 and will be removed in Drupal
// 11 and there is no replacement. We don't really care because the
// reliefweb_migrate will be removed way before that.
'return' => Database::RETURN_AFFECTED,
];
$dry_run = !empty($options['dry-run']);

while (TRUE) {
$rw7_records = Database::getConnection('default', 'rwint7')
->select('field_revision_field_career_categories', 'f')
->fields('f')
->condition('f.bundle', ['job', 'training'], 'IN')
->condition('f.revision_id', $last_id, '>')
->orderBy('f.revision_id', 'ASC')
->range(0, 1000)
->execute()
?->fetchAll() ?? [];

if (empty($rw7_records)) {
break;
}

// Extract the revision IDs.
$revision_ids = [];
foreach ($rw7_records as $record) {
$revision_ids[$record->revision_id] = $record->revision_id;
}
$last_id = max($revision_ids);

// Get the existing revision IDs.
$existing_revision_ids = [];
$query = $this->database->select('node_revision', 'nr');
$query->fields('nr', ['vid']);
$query->leftJoin('node_revision__field_career_categories', 'f', 'f.revision_id = nr.vid');
$query->fields('f', ['field_career_categories_target_id']);
$query->condition('nr.vid', $revision_ids, 'IN');
foreach ($query->execute() ?? [] as $record) {
if (empty($existing_revision_ids[$record->vid])) {
$existing_revision_ids[$record->vid] = !empty($record->field_career_categories_target_id);
}
}

// Generate the list of records to insert.
$nids = [];
$rw9_records = [];
foreach ($rw7_records as $record) {
if (isset($existing_revision_ids[$record->revision_id]) && $existing_revision_ids[$record->revision_id] === FALSE) {
$rw9_records[] = [
'bundle' => $record->bundle,
'deleted' => $record->deleted,
'entity_id' => $record->entity_id,
'revision_id' => $record->revision_id,
'langcode' => 'en',
'delta' => $record->delta,
'field_career_categories_target_id' => $record->field_career_categories_tid,
];
$nids[$record->entity_id] = $record->entity_id;
}
}

if (!empty($rw9_records)) {
try {
$transaction = $this->database->startTransaction();

$query = $this->database
->insert('node_revision__field_career_categories', $query_options)
->fields($fields);
foreach ($rw9_records as $record) {
$query->values($record);
}
$query->execute();

if ($dry_run) {
$transaction->rollback();
}
}
catch (\Exception $exception) {
$transaction->rollback();
$this->logger()->error(dt('Error while trying to update the database: @error', [
'@error' => $exception->getMessage(),
]));
return FALSE;
}

$count += count($rw9_records);

$this->logger()->info(dt('Inserted @count records', [
'@count' => $count,
]));
}
}

if ($count === 0) {
$this->logger()->info(dt('Nothing to insert'));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function getEntity(Row $row, array $old_destination_id_values) {
if ($source_plugin instanceof EntityBase) {
$exists = $this->migration->getSourcePlugin()->entityExists($entity_id);
}
elseif ($original = $this->storage->load($entity_id)) {
elseif ($this->storage->load($entity_id)) {
$exists = TRUE;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ public function isViewableStatus($status, ?AccountInterface $account = NULL) {
* {@inheritdoc}
*/
public function entityPresave(EntityModeratedInterface $entity) {
parent::entityPresave($entity);

// Ensure all posting rights are 'blocked' if the status is 'blocked'.
$status = $entity->getModerationStatus();
if ($status === 'blocked') {
Expand All @@ -233,8 +235,6 @@ public function entityPresave(EntityModeratedInterface $entity) {
])));
}
}

return $status;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
.setAttribute('data-cd-focus-target', 'site-search-input')
.addClass('cd-search__form')
}}>
<h2 id="site-search-title" class="visually-hidden"><?php rwpt("Content Search"); ?></h2>
<h2 id="site-search-title" class="visually-hidden">{{ 'Content Search'|t }}</h2>
<form action="/search/results" method="GET" accept-charset="UTF-8" class="[ cd-flow ]">
<div class="cd-form__item">
<label for="site-search-input" class="visually-hidden">{{ 'What are you looking for?'|t }}</label>
Expand Down

0 comments on commit 6117ab2

Please sign in to comment.