Skip to content

Commit

Permalink
If staticpage cache gets deleted then structured data cache will as w…
Browse files Browse the repository at this point in the history
…ell.

For feature #902
  • Loading branch information
eSilverStrike committed Feb 26, 2019
1 parent d9424ed commit 7e992c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
14 changes: 12 additions & 2 deletions plugins/staticpages/services.inc.php
Expand Up @@ -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';
Expand Down Expand Up @@ -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}'";
Expand All @@ -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 {
Expand All @@ -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}'";
Expand All @@ -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']);
}
}
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 13 additions & 1 deletion system/classes/structureddata.class.php
Expand Up @@ -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);
Expand All @@ -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
*
Expand Down

0 comments on commit 7e992c1

Please sign in to comment.