0

I wants to delete the below folder every time only on each view bulk operations but currently it is getting deleted for each node selected in VBO. I am executing this action in rules module.

Please let men know how to run this only once for each VBO.

$pdfdir = "/var/www/websites/test/sites/default/files/pdffolder";
$directory = escapeshellarg($pdfdir);
shell_exec("rm -rf $directory");

This code is executed via the Rules module.

4
  • How did you configure your rule? Commented Jul 23, 2020 at 3:19
  • In 'Execute custom PHP code in Rules Action' I am writing this code
    – Imhere1966
    Commented Jul 23, 2020 at 4:06
  • What are the events/conditions for the rule? VBO triggers a batch process of all the items shown in the view, so if you attach your action to an individual node, it will be executed every time. Commented Jul 23, 2020 at 5:44
  • Events are after saving new node, condition i have not defined. How to execute this only for each VBO operation
    – Imhere1966
    Commented Jul 23, 2020 at 5:46

1 Answer 1

0

If you define a VBO event in rules that triggers on every node save, then it will happen once per node saved by VBO. VBO takes all the selected items in a view and runs them through a batch process, performing operations per item.

So, you need to change the rule event to something else.

If the goal is to run the code once per time, here is one lazy way to do it:

  1. Set the event to be "page is viewed". (doing this from memory, actual event name is different)
  2. Set a condition on the rule to be the path of the VBO page.
  3. Use your execute PHP code as the action.

This will cause the code to execute whenever the VBO url is accessed. This is not exactly what you asked for, but hopefully this gives you an idea of how to use events and conditions in rules to get what you want.

1
  • Thank you so much for your suggestion. 1. Page is viewed is not available there is 'Content is viewed' i selected this option and set everything but it did not worked. Later is tried using 'content is viewed' of type 'page' then condition-> URL has alias and execute. It worked.Not sure if it will work for all content type in that VBO page.
    – Imhere1966
    Commented Jul 23, 2020 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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