Add an option to delete all nodes when the feed source is empty

Created on 5 September 2014, about 10 years ago
Updated 11 July 2023, over 1 year ago

Hi everyone,

like stefan.r suggested , I am creating this issue to add an option to the recent resolution of #1470530: Unpublish/Delete nodes not included in feed .

Problem/Motivation

My problem is quite simple to understand : I want to reproduce the content of a distant folder with nodes in my Drupal instance. But, when my feed importer checks that folder and the response is empty, nodes are not deleted resulting in a bunch of nodes in Drupal that are no longer wanted.

Proposed resolution

Add an option when the node processors' settings "Delete non-existent nodes" is selected. It could be a checkbox like "Delete nodes even if feed is empty".

Remaining tasks

Well, I guess that's the approval of this issue.

User interface changes

A checkbox in the node processors' settings page

Original report by MegaChriz

MegaChriz explained quite well why this behavior is normal for a large part of feeds users but I think adding this would be great to achieve the previous 2,5 years work :)

Thank you.

Feature request
Status

RTBC

Component

Code

Created by

🇫🇷France AndrackOSnack

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇦Canada Nathan Tsai

    Crossposting from https://www.drupal.org/project/feeds/issues/3337811#comment-15145862: 🐛 Argument #1 ($value) must be of type Countable|array, null given in FeedsProcessor->clean() Fixed

    If looking for a work around so that feeds will unpublish missing nodes even when the response is empty...

    Set your importer to include the published status.

    Then use the following code to ensure there's always at least one node in your response.

    ...I did not realize that feeds do not import nodes when the response is empty or there are no items.

    For future reference, I added the following code for my REST Export to ensure there is always at least one item in my response.

    use Drupal\views\ViewExecutable;
    use Drupal\views\ResultRow;
    use Drupal\node\Entity\Node;
    
    /**
     * Implements hook_views_post_execute().
     */
    function HOOK_views_post_execute(ViewExecutable $view) {
      if ($view->id() == 'MY_VIEW_ID') {
        // Feeds does not import an empty response. Therefore, add a 
        // dummy feeds item
        if ($view->total_rows === 0) {
          $dummyNode = Node::create([
            'type' => 'job_posting',
            'nid'  => -1, // Our GUID. This is valid because we never save the node
            'title' => 'PLACEHOLDER NODE',
            'status' => 0, // Be unpublished, so it doesn't appear on the importing website
          ]);
          $view->result[] = new ResultRow([
            '_entity' => $dummyNode,
          ]);
        }
      }
    }
    
Production build 0.71.5 2024