1

I have spent hours/days trying to figure out how to accomplish this in Drupal 7 using the Rules module, so I will greatly appreciate any help anyone can provide.

What I am trying to do:

When a user re-uploads a file to a node, the node should rollback from an Approved status to Pending Review. This requires some kind of automated rule that checks for when a file was updated.

Here's what I have:

  1. A node called Data_set with a File field called data_set_file.
  2. Data_set nodes also have a field called Status (e.g., Pending Review, Approved).

My problem:

When a user uploads and overwrites an existing attachment in the data_set_file field, I want the node's Status to change back from Approved (if already) to Pending Review. I am able to use Rules to check for when a user uploads a new file, but there are no rules conditions to check for which file or node file has been updated.

What I tried:

I created a "NOT Data Comparison" condition between node-unchanged:field-dataset-file:file:fid and (Equals/Negate) node:field-dataset-file:file:fid However, when updating the file, it did not register a change to the fid field (because it keeps the same fid). I also tried the file size field with no effect as well. When I tried the file's timestamp, it appeared to work at first until I realized that the timestamp updates every time, no matter what, that a user saves a node, regardless of whether or not a file was re-uploaded.

I may be going about this the wrong way. Anyone know what's the easiest way to accomplish this? Thanks a million!

0

Workflow

This module allows you to create arbitrary Workflows, and assign them to Entities.

Workflows are made up of workflow states. Transitions between states can be allowed per role. For example, a workflow with the states Draft, Review, and Published could be assigned to the Story node type. Only users with role 'chief editor' can set Stories to the published state. You can set up the Workflow to alter states from form, page, comment and a special workflow tab.

Transitions between workflow states can have actions assigned to them. In our example, we could assign an action so that when the story moves from the Draft state to the Review state an email is sent out. Another action could be assigned to the transition from Review to Published so that the node's status is set to Published (and becomes visible on your website).

How we use workflow module

Creating a Workflow

Editorial workflow with Rules

  • read its documentation – Adi Oct 14 '15 at 4:58
  • On second thought, I don't think the answer above actually answered the original question. The workflow module still uses rules and I need to know how to implement a condition based on a file upload. Regardless of whether or not I use the workflow module, I still need to solve the problem of how do you react to a file upload? Is there a way? The documentation does not mention anything about that. – Jason Luttrell Oct 14 '15 at 21:36
0

SOLUTION. After searching online, I found the answer to my own question. I'm sharing this for anyone else with a similar problem:

The first part is to implement file events. There is a patch to the Rules module that adds file events to react on (after saving new file, after updating existing file, and before saving file).

Discussion thread: https://www.drupal.org/node/826986

Patch: https://www.drupal.org/files/issues/file_events-826986-22.patch

  1. Copy the patch file to the rules module directory.
  2. From the command line, change to ("cd") the rules module directory.
  3. Enter: patch -p1 < file_events-826986-22.patch
  4. On the Rules page (admin/config/workflow/rules) click "Add event" and select the file event to add.

The next part is creating a rule to react to the file upload. A problem is that the timestamp on files are updated for every save, not just when it is first uploaded. So, I first opened my custom File Type (in my case "Dataset") and added a custom field using the Date Field Type called Time Uploaded (field_file_time_uploaded). I also created a new rule to update this field when the file is uploaded. Note that this rule gets called on the file insert event, which happens before a node is saved.

Below is what the rule export looks like for file uploads:

{ "rules_save_file_time_uploaded" : {
    "LABEL" : "File - Save Time Uploaded",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "file_insert" : [] },
    "IF" : [
      { "entity_is_of_type" : { "entity" : [ "file" ], "type" : "file" } },
      { "entity_has_field" : { "entity" : [ "file" ], "field" : "field_file_time_uploaded" } }
    ],
    "DO" : [
      { "data_set" : {
          "data" : [ "file:field-file-time-uploaded" ],
          "value" : [ "site:current-date" ]
        }
      },
      { "drupal_message" : { "message" : "The [file:type] file was uploaded." } }
    ]
  }
}

This Time Uploaded field can then be used by other rules, like when saving a node, to see if the file was updated using a data comparison with the site's current datetime.

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.