1

My requirement is to import nodes daily night after deleting all the contents in that node type.

I enabled the cron settings in feeds module as 1 day and tried to write hook_cron() to delete all nodes.

function my_module_cron() {
  $results = db_select('node', 'n')
              ->fields('n', array('nid'))
              ->condition('type', 'ars', '=')
              ->execute()
              ->fetchCol();
  if (!empty($results)) {
    node_delete_multiple($results);
  }
}

But the doesn't seems to be deleted. I think this might be because of the user access problem.

I also want to know will the delete occurs before re-importing. How to order the cron jobs or shall I run the import via code after deleting the nodes.

0

There is no need to do that manually.

Under Settings for Node Processor just select Replace Existing Nodes.

For further details you can check https://www.ostraining.com/blog/drupal/feeds/ which explains the steps in detail.

There is a field called GUID. Make sure that you set it to an appropriate value so that nodes will be updated(deleted and reimported). If the GUID in your site matches to that of the import then current nodes will be deleted(irrespective of whether they were created manually or imported) and the nodes from your news source will be reimported.

| improve this answer | |
  • The added advantage is in case of a mishap you will miss only one node and other nodes will remain. Whereas in your previous approach you would have deleted all nodes and imports would have failed, leaving no content on site. – Gokul N K Jun 18 '15 at 13:07
  • by enabling Replace Existing Nodes will all the nodes of the particular content type will be deleted before re importing. Even if some nodes are manually created? – user46121 Jun 18 '15 at 13:09
  • I have updated the answer. Please check @alliswell – Gokul N K Jun 18 '15 at 13:12
  • I have a GUID but what I want to know is whether all the nodes of that content type deleted irrespective of any conditions? I just need to delete everything of that content type and import the fresh data. – user46121 Jun 18 '15 at 13:16
  • Once you enable Replace Existing Nodes and feeds module finds a node in Drupal with same GUID it will replace. – Gokul N K Jun 18 '15 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy