Skip to content

Commit

Permalink
Merge pull request #680 from UN-OCHA/develop
Browse files Browse the repository at this point in the history
Develop -> Main - v2.1.4
  • Loading branch information
orakili authored Nov 14, 2023
2 parents 1ca30a6 + cfa2ada commit be83643
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 195 deletions.
15 changes: 0 additions & 15 deletions PATCHES/core-css-js-aggregation-3376927.patch

This file was deleted.

210 changes: 105 additions & 105 deletions composer.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions composer.patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"drupal/core" : {
"https://www.drupal.org/project/drupal/issues/3047110": "PATCHES/core--drupal--3047110-taxonomy-term-moderation-class.patch",
"https://www.drupal.org/project/drupal/issues/3008292": "PATCHES/core--drupal--3008292-image-upload-validators.patch",
"https://www.drupal.org/project/drupal/issues/3143617": "PATCHES/core--drupal--3143617-pager-parameter.patch",
"https://www.drupal.org/project/drupal/issues/3376927": "PATCHES/core-css-js-aggregation-3376927.patch"
"https://www.drupal.org/project/drupal/issues/3143617": "PATCHES/core--drupal--3143617-pager-parameter.patch"
},
"drupal/guidelines": {
"Drupal 10 compatibility": "PATCHES/guidelines-drupal-10-compatibility.patch"
Expand Down
33 changes: 33 additions & 0 deletions html/modules/custom/reliefweb_entities/src/DocumentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Drupal\reliefweb_entities;

use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Field\EntityReferenceFieldItemList;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\reliefweb_entities\Entity\Source;
use Drupal\reliefweb_moderation\EntityModeratedInterface;
use Drupal\reliefweb_rivers\RiverServiceBase;
use Drupal\reliefweb_utility\Helpers\HtmlSummarizer;
Expand Down Expand Up @@ -358,4 +360,35 @@ public function createDate($date) {
return new \DateTime($date, new \DateTimeZone('UTC'));
}

/**
* Update the status of the sources when publishing an opportunity.
*/
protected function updateSourceModerationStatus() {
if (!$this->hasField('field_source') || $this->field_source->isEmpty()) {
return;
}

if (!($this instanceof EntityPublishedInterface) || !$this->isPublished()) {
return;
}

// Make the inactive or archive sources active when the node is published.
foreach ($this->field_source as $item) {
$source = $item->entity;
if (empty($source) || !($source instanceof Source)) {
continue;
}

if (in_array($source->getModerationStatus(), ['inactive', 'archive'])) {
$source->notifications_content_disable = TRUE;
$source->setModerationStatus('active');
$source->setNewRevision(TRUE);
$source->setRevisionLogMessage('Automatic status update due to publication of node ' . $this->id());
$source->setRevisionUserId(2);
$source->setRevisionCreationTime(time());
$source->save();
}
}
}

}
3 changes: 3 additions & 0 deletions html/modules/custom/reliefweb_entities/src/Entity/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ public function preSave(EntityStorageInterface $storage) {
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);

// Make the sources active.
$this->updateSourceModerationStatus();

$this->sendPublicationNotification();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\reliefweb_entities;

use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\reliefweb_entities\Entity\Source;
use Drupal\reliefweb_moderation\Helpers\UserPostingRightsHelper;
Expand Down Expand Up @@ -169,36 +168,4 @@ protected function updateDateWhenPublished() {
}
}

/**
* Update the status of the sources when publishing an opportunity.
*/
protected function updateSourceModerationStatus() {
if (!$this->hasField('field_source') || $this->field_source->isEmpty()) {
return;
}

if (!($this instanceof EntityPublishedInterface) || !$this->isPublished()) {
return;
}

// Make the inactive or archive sources active when an apportunity is
// published.
foreach ($this->field_source as $item) {
$source = $item->entity;
if (empty($source) || !($source instanceof Source)) {
continue;
}

if (in_array($source->getModerationStatus(), ['inactive', 'archive'])) {
$source->notifications_content_disable = TRUE;
$source->setModerationStatus('active');
$source->setNewRevision(TRUE);
$source->setRevisionLogMessage('Automatic status update due to publication of node ' . $this->id());
$source->setRevisionUserId(2);
$source->setRevisionCreationTime(time());
$source->save();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,40 +80,81 @@ public function updateInactiveSources(array $options = [
return TRUE;
}

// Retrieve sources with status to update.
$sources = $this->database->query("
SELECT query.id, query.status
SELECT
query.id AS id,
query.status AS status
FROM (
SELECT subquery.id,
CASE
WHEN subquery.published > 0 THEN 'active'
WHEN subquery.recent > 0 THEN 'inactive'
ELSE 'archive'
END AS status
SELECT
subquery.id,
CASE
WHEN subquery.active > 0 THEN 'active'
WHEN subquery.inactive > 0 THEN 'inactive'
ELSE 'archive'
END AS status,
subquery.current_status AS current_status
FROM (
SELECT fs.field_source_target_id AS id,
SUM(CASE
WHEN n.type = 'job' AND UNIX_TIMESTAMP(fjcd.field_job_closing_date_value) > UNIX_TIMESTAMP(NOW() - INTERVAL 1 YEAR) THEN 1
WHEN n.type = 'training' AND UNIX_TIMESTAMP(frd.field_registration_deadline_value) > UNIX_TIMESTAMP(NOW() - INTERVAL 1 YEAR) THEN 1
ELSE 0
END) AS recent,
SUM(IF(n.moderation_status = 'published', 1, 0)) AS published
FROM node__field_source AS fs
INNER JOIN node_field_data AS n
SELECT
tfd.tid AS id,
tfd.moderation_status AS current_status,
SUM(CASE
# Published jobs or training.
WHEN n.type IN ('job', 'training') AND n.status = 1 THEN 1
# Jobs that were open during the past 2 months.
WHEN n.type = 'job' AND UNIX_TIMESTAMP(fjcd.field_job_closing_date_value) > UNIX_TIMESTAMP(NOW() - INTERVAL 2 MONTH) THEN 1
# Training that were open during the past 2 months.
WHEN n.type = 'training' AND UNIX_TIMESTAMP(frd.field_registration_deadline_value) > UNIX_TIMESTAMP(NOW() - INTERVAL 2 MONTH) THEN 1
# Reports created during the past 3 years.
WHEN n.type = 'report' AND n.created > UNIX_TIMESTAMP(NOW() - INTERVAL 3 YEAR) THEN 1
# Ongoing training that were published during the past 2 months.
WHEN n.type = 'training' AND frd.field_registration_deadline_value IS NULL AND (
SELECT MAX(tnr.revision_timestamp)
FROM node_field_revision AS tnfr
INNER JOIN node_revision AS tnr
ON tnr.vid = tnfr.vid
WHERE tnfr.moderation_status = 'published'
AND tnfr.nid = n.nid
) > UNIX_TIMESTAMP(NOW() - INTERVAL 2 MONTH) THEN 1
ELSE 0
END) AS active,
SUM(CASE
# Jobs that were open during the past 1 year.
WHEN n.type = 'job' AND UNIX_TIMESTAMP(fjcd.field_job_closing_date_value) > UNIX_TIMESTAMP(NOW() - INTERVAL 1 YEAR) THEN 1
# Training that were open during the past 1 year.
WHEN n.type = 'training' AND UNIX_TIMESTAMP(frd.field_registration_deadline_value) > UNIX_TIMESTAMP(NOW() - INTERVAL 1 YEAR) THEN 1
# Published reports.
WHEN n.type = 'report' AND n.status = 1 THEN 1
# Ongoing training that were published during the past year.
WHEN n.type = 'training' AND frd.field_registration_deadline_value IS NULL AND (
SELECT MAX(tnr.revision_timestamp)
FROM node_field_revision AS tnfr
INNER JOIN node_revision AS tnr
ON tnr.vid = tnfr.vid
WHERE tnfr.moderation_status = 'published'
AND tnfr.nid = n.nid
) > UNIX_TIMESTAMP(NOW() - INTERVAL 1 YEAR) THEN 1
ELSE 0
END) AS inactive
FROM taxonomy_term_field_data AS tfd
LEFT JOIN node__field_source AS fs
ON fs.field_source_target_id = tfd.tid
LEFT JOIN node_field_data AS n
ON n.nid = fs.entity_id
AND n.type IN ('job', 'training')
AND n.type IN ('job', 'training', 'report')
LEFT JOIN node__field_job_closing_date AS fjcd
ON fjcd.entity_id = fs.entity_id
LEFT JOIN node__field_registration_deadline AS frd
ON frd.entity_id = fs.entity_id
WHERE fs.field_source_target_id NOT IN (SELECT field_source_target_id FROM node__field_source WHERE bundle = 'report')
GROUP BY fs.field_source_target_id
WHERE tfd.vid = 'source'
# Skip blocked or duplicate sources.
AND tfd.moderation_status IN ('active', 'inactive', 'archive')
# Skip recently created organizations.
AND tfd.created < UNIX_TIMESTAMP(NOW() - INTERVAL 2 WEEK)
GROUP BY tfd.tid
) AS subquery
) AS query
INNER JOIN taxonomy_term_field_data AS tfd
ON tfd.tid = query.id
AND tfd.vid = 'source'
AND tfd.moderation_status NOT IN ('duplicate', 'blocked', query.status)
WHERE query.status <> 'active'
WHERE query.status IN ('inactive', 'archive') AND query.status <> query.current_status
")?->fetchAllKeyed(0, 1) ?? [];

if (empty($sources)) {
Expand Down
Loading

0 comments on commit be83643

Please sign in to comment.