Hi,

There is probably a really easy answer to this, but I'm stumped...

I have a rule which, on saving a piece of content, takes the values of some fields, bounces them into some other fields, and empties the fields they came from. This works fine for text fields, but, when it comes to file fields, it transfers the reference just fine but refuses to delete the old one. I've tried setting the data value for node:my_file to nothing and to 0, I've tried emptying out the record in the database, but nothing works (admittedly, my php skills are pretty limited). I can get rules to hide the content in question, but, for security reasons, that's less than ideal, because it basically leaves behind a publicly accessible download link for anyone who knows the URL.

Would really appreciate some help.

Thanks,

Pav

PS. Great module!

Comments

pav’s picture

Component: Rules Core » Rules Engine

Ok, cracked it eventually. Would be really useful if the function came out of the box though.

pav’s picture

Premature celebration... This looks like a bug, but I'm not sure whether it's with Rules or something else. Please see http://drupal.org/node/1450230.

mitchell’s picture

Status: Active » Postponed (maintainer needs more info)

Please provide more information so we can document or fix this issue.

mitchell’s picture

Version: 7.x-2.0 » 7.x-2.x-dev

Would you please compile the information you collected to make this issue more actionable?

tobiasb’s picture

Component: Rules Engine » Rules Core
Status: Postponed (maintainer needs more info) » Active

In my case I want delete the file from a file field (works - no records in file_managed), but it does not delete the data from the tables (field_data_field.../field_revision_field...).

When I use the action to set nothing, then it creates a new entry in file_managed.

rbrownell’s picture

Issue summary: View changes

I was able to do with with the custom php code. Here is a snippit. I got this code from http://dropbucket.org/node/235 and modified it. In this example my rule generates a list of nodes and loops through them. If you don't have a loop you may need to change [list-item:nid] to another token.

// Load the node.
$node = node_load('[list-item:nid]');
// Get the language for the file field.
$lang = field_language('node', $node, 'field_my_file_field');
// load the file
$file = file_load($node->field_my_file_field[$lang][0]['fid']);
// unset the field for the node
unset($node->field_my_file_field[$lang][0]);
// delete file from disk and from database
file_delete($file);
// Save the node.
node_save($node);
TR’s picture

Category: Bug report » Support request
Status: Active » Closed (works as designed)

I don't see any bug here, and no further information was given.

Deleting a reference to a file does not delete a file, that's the expected behavior. If you want to delete the file, #6 seems like a good solution.