Skip to content

Commit

Permalink
Merge pull request #321 from UN-OCHA/RW-245-import
Browse files Browse the repository at this point in the history
[RW-245] Fix job import
  • Loading branch information
orakili committed May 13, 2022
2 parents a95288f + 004253b commit ad376e9
Show file tree
Hide file tree
Showing 9 changed files with 843 additions and 279 deletions.
34 changes: 34 additions & 0 deletions html/modules/custom/reliefweb_import/reliefweb_import.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* @file
* Module file for the job importer.
*/

use Drupal\Core\Entity\EntityInterface;
use Drupal\reliefweb_entities\Entity\Job;

/**
* Implements hook_ENTITY_TYPE_presave() for node.
*/
function reliefweb_import_node_presave(EntityInterface $entity) {
// @todo remove when removing `reliefweb_migrate`.
if (!empty($entity->_is_migrating)) {
return;
}
if ($entity instanceof Job && !empty($entity->_is_importing)) {
$status = $entity->getModerationStatus();

// Set the status to draft/on-hold if there were validation errors.
if ($status !== 'refused' && !empty($entity->_import_errors)) {
$status = \Drupal::state()->get('reliefweb_import_status_when_errors', 'draft');
$entity->setModerationStatus($status);
}

// Set the revision user to the System user to differentiate modifications
// made via the UI from automated ones. We need to do that here so that
// the Job::preSave() uses the user associated with the import feed when
// determining the status to use based on the user posting rights.
$entity->setRevisionUserId(2);
}
}
Loading

0 comments on commit ad376e9

Please sign in to comment.