Jobs altered by hook_entity_load to be inactive are used anyway

Created on 8 June 2023, about 1 year ago

Problem/Motivation

In #2682771: Ignore status changes for continuous jobs β†’ an inactive state was introduced for continuous jobs. There is currently no UI to set that value.
Given the fact I wanted to be able to disable my jobs if my api_key wasn't set, I used an implementation of hook_ENTITY_TYPE_load that would change the state value on the fly.

While \Drupal\tmgmt\ContinuousManager::getContinuousJobs() does load only Jobs that are active (in the database), tmgmt_content_create_continuous_job_items(), which is its only known caller, does not double check the state before trying to add the item.

Steps to reproduce

  1. Create a continuous job
  2. Implement hook_ENTITY_TYPE_load to change its state without using the setState() method. Ex:
    function my_module_tmgmt_job_load($entities) {
      foreach ($entities as $job) {
        /** @var \Drupal\tmgmt\Entity\Job $job */
        if ($job->isContinuous()) {
          $job->state->value = Job::STATE_CONTINUOUS_INACTIVE;
        }
      }
    }
  3. Create a content that would be translated by the continous job if active

Expected: the job doesn't try ton translate the node
Current: the job does translate the node

Proposed resolution

Add a test in tmgmt_content_create_continuous_job_items() to ensure that we never add an item to an inactive job.

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Source: Node

Created by

πŸ‡«πŸ‡·France DuaelFr Montpellier, France

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024