-
-
Save OnkelTem/272ea3daad0934c67062 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "rules_export_images" : { | |
"LABEL" : "Export Images", | |
"PLUGIN" : "rule", | |
"OWNER" : "rules", | |
"REQUIRES" : [ "rules", "fs_rules", "php" ], | |
"USES VARIABLES" : { "product_display" : { "label" : "Product display", "type" : "node" } }, | |
"IF" : [ | |
{ "entity_has_field" : { "entity" : [ "product-display" ], "field" : "field_images" } }, | |
{ "NOT data_is_empty" : { "data" : [ "product-display:field-images" ] } }, | |
{ "entity_has_field" : { "entity" : [ "product-display" ], "field" : "field_category" } } | |
], | |
"DO" : [ | |
{ "fs_rules_action_create_dir" : { | |
"USING" : { "uri" : "public:\/\/export", "base_dir" : [ "" ] }, | |
"PROVIDE" : { "created_dir" : { "export_dir" : "Export dir" } } | |
} | |
}, | |
{ "variable_add" : { | |
"USING" : { "type" : "text", "value" : [ "product-display:field-category:name" ] }, | |
"PROVIDE" : { "variable_added" : { "category_name" : "Category name" } } | |
} | |
}, | |
{ "fs_rules_action_create_dir" : { | |
"USING" : { | |
"uri" : "\u003C?php echo str_replace(\u0027\/\u0027, \u0027,\u0027, $category_name); ?\u003E", | |
"base_dir" : [ "export-dir" ] | |
}, | |
"PROVIDE" : { "created_dir" : { "category_dir" : "Category dir" } } | |
} | |
}, | |
{ "fs_rules_action_find_dirs" : { | |
"USING" : { | |
"dir" : [ "category-dir" ], | |
"mask" : "__[product-display:nid]", | |
"operation" : "ends" | |
}, | |
"PROVIDE" : { "found_dirs" : { "found_dirs" : "Found directories" } } | |
} | |
}, | |
{ "LOOP" : { | |
"USING" : { "list" : [ "found-dirs" ] }, | |
"ITEM" : { "found_dir" : "Found dir" }, | |
"DO" : [ { "fs_rules_action_delete_dir" : { "dir" : [ "found-dir" ] } } ] | |
} | |
}, | |
{ "variable_add" : { | |
"USING" : { "type" : "text", "value" : [ "product-display:title" ] }, | |
"PROVIDE" : { "variable_added" : { "product_title" : "Product title" } } | |
} | |
}, | |
{ "fs_rules_action_create_dir" : { | |
"USING" : { | |
"uri" : "\u003C?php echo str_replace(\u0027\/\u0027, \u0027,\u0027, $product_title); ?\u003E__[product-display:nid]", | |
"base_dir" : [ "category-dir" ] | |
}, | |
"PROVIDE" : { "created_dir" : { "node_dir" : "Node dir" } } | |
} | |
}, | |
{ "LOOP" : { | |
"USING" : { "list" : [ "product-display:field-images" ] }, | |
"ITEM" : { "list_item" : "Current list item" }, | |
"DO" : [ | |
{ "fs_rules_action_copy_file" : { | |
"USING" : { "file" : [ "list-item:file" ], "dir" : [ "node-dir" ] }, | |
"PROVIDE" : { "copied_file" : { "copied_file" : "Copied file" } } | |
} | |
} | |
] | |
} | |
} | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "rules_import_images" : { | |
"LABEL" : "Import Images", | |
"PLUGIN" : "rule", | |
"OWNER" : "rules", | |
"REQUIRES" : [ "rules", "fs_rules", "php", "rules_conditional" ], | |
"USES VARIABLES" : { "product_display" : { "label" : "Product display", "type" : "node" } }, | |
"IF" : [ | |
{ "entity_has_field" : { "entity" : [ "product-display" ], "field" : "field_images" } }, | |
{ "entity_has_field" : { "entity" : [ "product-display" ], "field" : "field_category" } } | |
], | |
"DO" : [ | |
{ "fs_rules_action_open_dir" : { | |
"USING" : { "uri" : "public:\/\/export", "base_dir" : [ "" ] }, | |
"PROVIDE" : { "dir" : { "export_dir" : "Export dir" } } | |
} | |
}, | |
{ "variable_add" : { | |
"USING" : { "type" : "text", "value" : [ "product-display:field-category:name" ] }, | |
"PROVIDE" : { "variable_added" : { "category_name" : "Category name" } } | |
} | |
}, | |
{ "fs_rules_action_open_dir" : { | |
"USING" : { | |
"uri" : "\u003C?php echo str_replace(\u0027\/\u0027, \u0027,\u0027, $category_name); ?\u003E", | |
"base_dir" : [ "export-dir" ] | |
}, | |
"PROVIDE" : { "dir" : { "category_dir" : "Category dir" } } | |
} | |
}, | |
{ "fs_rules_action_create_dir" : { | |
"USING" : { "uri" : "public:\/\/[product-display:type]s", "base_dir" : [ "" ] }, | |
"PROVIDE" : { "created_dir" : { "images_dir" : "Images dir" } } | |
} | |
}, | |
{ "fs_rules_action_find_dirs" : { | |
"USING" : { | |
"dir" : [ "category-dir" ], | |
"mask" : "__[product-display:nid]", | |
"operation" : "ends" | |
}, | |
"PROVIDE" : { "found_dirs" : { "found_dirs" : "Found directories" } } | |
} | |
}, | |
{ "LOOP" : { | |
"USING" : { "list" : [ "found-dirs" ] }, | |
"ITEM" : { "node_dir" : "Node dir" }, | |
"DO" : [ | |
{ "fs_rules_action_find_files" : { | |
"USING" : { | |
"dir" : [ "node-dir" ], | |
"mask" : "\\.(jpg|jpeg|JPG|JPEG|png|PNG)$", | |
"operation" : "regex" | |
}, | |
"PROVIDE" : { "found_files" : { "found_files" : "Found files" } } | |
} | |
}, | |
{ "CONDITIONAL" : [ | |
{ | |
"IF" : { "NOT data_is_empty" : { "data" : [ "found-files" ] } }, | |
"DO" : [ | |
{ | |
"COMMENT" : { | |
"comment:label" : "Delete node\u0027s images", | |
"comment:text" : { "value" : "", "format" : "plain_text" } | |
}, | |
"DO" : [] | |
}, | |
{ "LOOP" : { | |
"USING" : { "list" : [ "product-display:field-images" ] }, | |
"ITEM" : { "node_image" : "Node image" }, | |
"DO" : [ | |
{ "list_remove" : { "list" : [ "product-display:field-images" ], "item" : [ "node-image" ] } } | |
] | |
} | |
}, | |
{ | |
"COMMENT" : { | |
"comment:label" : "asd", | |
"comment:text" : { "value" : "", "format" : "plain_text" } | |
}, | |
"DO" : [] | |
}, | |
{ "LOOP" : { | |
"USING" : { "list" : [ "found-files" ] }, | |
"ITEM" : { "file" : "File" }, | |
"DO" : [ | |
{ "fs_rules_action_copy_file" : { | |
"USING" : { "file" : [ "file" ], "dir" : [ "images-dir" ] }, | |
"PROVIDE" : { "copied_file" : { "copied_file" : "Copied file" } } | |
} | |
}, | |
{ "fs_rules_action_save_file" : { | |
"USING" : { "file" : [ "copied-file" ] }, | |
"PROVIDE" : { "saved_file" : { "saved_file" : "Saved file" } } | |
} | |
}, | |
{ "fs_rules_action_add_file_to_list" : { "list" : [ "product-display:field-images" ], "file" : [ "saved-file" ] } }, | |
{ "entity_save" : { "data" : [ "product-display" ] } } | |
] | |
} | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment