Custom module wiped out all content of type I've recently written a custom module for my site that deletes nodes older than two years whenever cron runs. It worked perfectly!

However a few weeks later, after updating Drupal 8 to 8.1.10, all the nodes of type "recent" were deleted! I don't know if it is connected to the module or not, but I have a hunch that it is.

Here is the .module file:

&lt;?php

function delete_old_nodes_cron() {

        $node = $variables['node'];

        $query = \Drupal::entityQuery('node')
        -&gt;condition('created', strtotime('-2 year'), '&lt;=')
        -&gt;condition('type', 'recent');
        $nids = $query-&gt;execute();
        foreach ($nids as $nid) {
            $node = node_load($nid);
            $node-&gt;delete();
        }
}
?&gt;


and the .info.yml file:

name: Delete old nodes
description: Deletes nodes older than 2 years.
package: Custom
type: module
version: 1.0
core: 8.x
Your query seems to be ok, irrespective of drupal version it should work. Here are the few pointers to debug.


Check the query output, is your query returning all nodes of type 'recent' without filtering by created

function delete_old_nodes_cron() {
  $query = \Drupal::entityQuery('node')
      -&gt;condition('created', strtotime('-2 year'), '&lt;=')
      -&gt;condition('type', 'recent');
  $nids = $query-&gt;execute();
  dpm($nids);
}

Make sure for your recent created nodes created time is not altered somewhere.