From 7e992c1415721dcc8898827be413129ffaa8b6bd Mon Sep 17 00:00:00 2001 From: Tom Homer Date: Tue, 26 Feb 2019 15:12:18 -0500 Subject: [PATCH] If staticpage cache gets deleted then structured data cache will as well. For feature #902 --- plugins/staticpages/services.inc.php | 14 ++++++++++++-- system/classes/structureddata.class.php | 14 +++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/plugins/staticpages/services.inc.php b/plugins/staticpages/services.inc.php index ae16375e0..aa49c28ae 100644 --- a/plugins/staticpages/services.inc.php +++ b/plugins/staticpages/services.inc.php @@ -60,7 +60,7 @@ function service_submit_staticpages($args, &$output, &$svc_msg) { global $_CONF, $_TABLES, $_USER, $LANG_ACCESS, $LANG12, $LANG_STATIC, - $_GROUPS, $_SP_CONF; + $_GROUPS, $_SP_CONF, $_STRUCT_DATA; if (!$_CONF['disable_webservices']) { require_once $_CONF['path_system'] . 'lib-webservices.php'; @@ -585,6 +585,8 @@ function service_submit_staticpages($args, &$output, &$svc_msg) // Clear Cache $cacheInstance = 'staticpage__' . $sp_id . '__'; CACHE_remove_instance($cacheInstance); + + $_STRUCT_DATA->clear_cachedScript('staticpages', $sp_id); } else { // If template then have to notify of all pages that use this template that a change to the page happened $sql = "SELECT sp_id FROM {$_TABLES['staticpage']} WHERE template_id = '{$sp_id}'"; @@ -595,6 +597,8 @@ function service_submit_staticpages($args, &$output, &$svc_msg) // Clear Cache $cacheInstance = 'staticpage__' . $A['sp_id'] . '__'; CACHE_remove_instance($cacheInstance); + + $_STRUCT_DATA->clear_cachedScript('staticpages', $A['sp_id']); } } } else { @@ -607,6 +611,8 @@ function service_submit_staticpages($args, &$output, &$svc_msg) // Clear Cache $cacheInstance = 'staticpage__' . $sp_old_id . '__'; CACHE_remove_instance($cacheInstance); + + $_STRUCT_DATA->clear_cachedScript('staticpages', $sp_old_id); } else { // If template then have to notify of all pages that use this template that a change to the page happened $sql = "SELECT sp_id FROM {$_TABLES['staticpage']} WHERE template_id = '{$sp_id}'"; @@ -617,6 +623,8 @@ function service_submit_staticpages($args, &$output, &$svc_msg) // Clear Cache $cacheInstance = 'staticpage__' . $A['sp_id'] . '__'; CACHE_remove_instance($cacheInstance); + + $_STRUCT_DATA->clear_cachedScript('staticpages', $A['sp_id']); } } } @@ -647,7 +655,7 @@ function service_submit_staticpages($args, &$output, &$svc_msg) */ function service_delete_staticpages($args, &$output, &$svc_msg) { - global $_CONF, $_TABLES, $_USER, $LANG_ACCESS, $LANG12, $LANG_STATIC; + global $_CONF, $_TABLES, $_USER, $LANG_ACCESS, $LANG12, $LANG_STATIC, $_STRUCT_DATA; $output = COM_refresh($_CONF['site_admin_url'] . '/plugins/staticpages/index.php?msg=20'); @@ -706,6 +714,8 @@ function service_delete_staticpages($args, &$output, &$svc_msg) // Clear Cache $cacheInstance = 'staticpage__' . $sp_id . '__'; CACHE_remove_instance($cacheInstance); + + $_STRUCT_DATA->clear_cachedScript('staticpages', $sp_id); return PLG_RET_OK; } diff --git a/system/classes/structureddata.class.php b/system/classes/structureddata.class.php index 1b126e6ce..4711c0f2b 100644 --- a/system/classes/structureddata.class.php +++ b/system/classes/structureddata.class.php @@ -293,7 +293,6 @@ public function get_cachedScript($type, $id, $cache_time) $retval = false; $sd_name = $this->create_name($type, $id); $cacheInstance = $this->get_cacheInstanceID($sd_name); - //$sd_cache = CACHE_check_instance($cacheInstance); $sd_cache = CACHE_check_instance($cacheInstance, true, true); // Not language or mobile cache specific (as this is ALL topic information) if ($sd_cache && $cache_time == -1) { $item = unserialize($sd_cache); @@ -314,6 +313,19 @@ public function get_cachedScript($type, $id, $cache_time) return $retval; } + /** + * Delete Structured Data item cache + * + * @param string $type Plugin of the content used to create the structured data + * @param string $id Id of content + */ + public function clear_cachedScript($type, $id) + { + $sd_name = $this->create_name($type, $id); + $cacheInstance = $this->get_cacheInstanceID($sd_name); + CACHE_remove_instance($cacheInstance); + } + /** * Returns JSON-LD script of either 1 or all structured data types. Can be included in head or body of webpage *