craftcms / feed-me

Craft CMS plugin for importing entry data from XML, RSS or ATOM feeds—routine task or on-demand.
Other
288 stars 139 forks source link

Empty feed does not disable/delete existing elements #1363

Open murphy1484 opened 1 year ago

murphy1484 commented 1 year ago

Description

When a feed has "Disable/delete missing elements" enabled and the processed feed is empty no elements are disabled/deleted.

Steps to reproduce

  1. Feed with Disable/delete missing elements
  2. Run feed without results.

Additional info

I believe the following lines in the afterProcessFeed function in the Process service are responsible. In this case $processedElementIds is an empty array.

if ($processedElementIds) {
    $elementsToDeleteDisable = array_diff($settings['existingElements'], $processedElementIds);
    if ($elementsToDeleteDisable) {
        if (DuplicateHelper::isDisable($feed)) {
            $this->_service->disable($elementsToDeleteDisable);
            $message = 'The following elements have been disabled: ' . Json::encode($elementsToDeleteDisable) . '.';
        } elseif (DuplicateHelper::isDisableForSite($feed)) {
            $this->_service->disableForSite($elementsToDeleteDisable);
            $message = 'The following elements have been disabled for the target site: ' . Json::encode($elementsToDeleteDisable) . '.';
        } else {
            $this->_service->delete($elementsToDeleteDisable);
            $message = 'The following elements have been deleted: ' . Json::encode($elementsToDeleteDisable) . '.';
        }

        Plugin::info($message);
        Plugin::debug($message);
    }
}
sander-lameco commented 1 year ago

Just found out the same issue. Would be a nice feature to delete all entries if the data is empty. Weird it doesn't work like that out of the box.

jamiematrix commented 5 months ago

Also discovered this just now.

I would have thought the process would just take from settings e.g. if you chose to delete missing entries, then an empty feed will delete all missing entries ... same for disable.

johndwells commented 4 months ago

We've just run into this issue too.

It would be good to know if there's an intention to fix this bug, or if we need to consider a workaround solution for the future.

maxpdesign commented 3 months ago

Currently running into the same issue that missing entries don't get disabled when the feed is empty.

Any update on this?

strandofgenius commented 3 months ago

Also having this issue in Craft 5 and Feed me 6.1.0.