0

I'm deleting my 'articles' created before Sat Nov 1 00:00:00 2014 GMT from Drupal 7.34 site, but I'm not sure whether the node_delete() delete the media files as well?

Below is my processing code:

<?php

// Fetch the NIDs of 'articles' created before Sat Nov 1 00:00:00 2014 GMT
$query = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', 'article')
->condition('created', 1414800000, '<') // 1414800000 = Sat Nov 1 00:00:00 2014 GMT
->orderBy('created', 'DESC')
->range(0, 100);
$result = $query->execute();

// Code to delete my articles in bulk
while ($record = $result->fetchAssoc()) {
  $nid = $record['nid'];
  echo $nid;
  node_delete($nid);
}

?>
2

It depends.

If the file has no references left to it in the file_usage table, then yes, it will be deleted.

If there are remaining references, it won't be deleted.

Either way, file_delete() is definitely invoked for the file.

| improve this answer | |
0

Yes node_delete function delete all the media files as well.

| improve this answer | |
0

As far as I know node_delete() does it all for you ,, it removes associated fields and everything ..

| improve this answer | |
0

You are right node_delete() will delete all associated files uploaded in the file system and in managed_files table and all entries related to that node id you pass.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.