From 68285792b4a463ba5fc9808a37851ea3e1e85445 Mon Sep 17 00:00:00 2001 From: EC2 Default User Date: Tue, 23 Jul 2019 12:25:40 +0000 Subject: [PATCH] NEPT-1530: Implement file flushing. --- nexteuropa_varnish.module | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/nexteuropa_varnish.module b/nexteuropa_varnish.module index 6498f86..ca45491 100644 --- a/nexteuropa_varnish.module +++ b/nexteuropa_varnish.module @@ -279,6 +279,21 @@ function nexteuropa_varnish_node_delete($node) { } } +/** + * Implements hook_file_delete(). + */ +function nexteuropa_varnish_file_delete($file) { + $scheme = file_uri_scheme($file->uri); + + if ($scheme !== FALSE && file_stream_wrapper_valid_scheme($scheme) === TRUE) { + // Get path on filesystem. + $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme); + _nexteuropa_varnish_purge_paths(array( + 'escaped_alias' => preg_quote($wrapper->getDirectoryPath($file) . '/' . $file->filename, '/'), + )); + } +} + /** * Implements hook_path_delete(). */ @@ -288,14 +303,15 @@ function nexteuropa_varnish_path_delete($path) { } $node = menu_get_object('node', 1, $path['source']); + $is_file = strpos($path['source'], 'file/'); - // Its a node path. - if (empty($node)) { + // Has to be a node or file path. + if ($node === NULL && $is_file === FALSE) { return; } // No rule defined for the node: Ignore the rest of the process. - if (!nexteuropa_varnish_node_has_rules($node)) { + if ($node !== NULL && nexteuropa_varnish_node_has_rules($node) === FALSE) { return; }