Skip to content

Commit

Permalink
fix: also handle ongoing training cases to decide status of organization
Browse files Browse the repository at this point in the history
Refs: RW-798
  • Loading branch information
orakili committed Nov 2, 2023
1 parent 4619447 commit e6d7e35
Showing 1 changed file with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function updateInactiveSources(array $options = [
$sources = $this->database->query("
SELECT
query.id AS id,
query.current_status,
query.status AS status
FROM (
SELECT
Expand All @@ -100,16 +99,41 @@ public function updateInactiveSources(array $options = [
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
Expand All @@ -122,10 +146,11 @@ public function updateInactiveSources(array $options = [
ON fjcd.entity_id = fs.entity_id
LEFT JOIN node__field_registration_deadline AS frd
ON frd.entity_id = fs.entity_id
WHERE
tfd.vid = 'source' AND
tfd.moderation_status IN ('active', 'inactive', 'archive') AND
tfd.created < UNIX_TIMESTAMP(NOW() - INTERVAL 2 WEEK)
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
Expand Down

0 comments on commit e6d7e35

Please sign in to comment.