From 96beafc6cbf8e129c6634bc8bd67da91c6de4c8e Mon Sep 17 00:00:00 2001 From: Jagadedes Date: Wed, 19 Nov 2014 10:04:14 +0530 Subject: [PATCH] widget cache code cleanup and bug fixes. --- CRM/Wci/BAO/WidgetCache.php | 17 ++++++++--------- CRM/Wci/Upgrader.php | 1 + sql/install.sql | 5 +++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CRM/Wci/BAO/WidgetCache.php b/CRM/Wci/BAO/WidgetCache.php index 513bc5e..ca7232c 100644 --- a/CRM/Wci/BAO/WidgetCache.php +++ b/CRM/Wci/BAO/WidgetCache.php @@ -115,14 +115,16 @@ class CRM_Wci_BAO_WidgetCache extends CRM_Wci_DAO_WidgetCache { public static function setWidgetCache($widgetId, $code) { $cacheTime = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout')); - $expire_on = time() + ($cacheTime * 60); - $query = "INSERT INTO civicrm_wci_widget_cache (widget_id, widget_code, expire) - VALUES (%1, %2, %3) - ON DUPLICATE KEY UPDATE widget_id = %1, widget_code = %2, expire = %3"; + $timenow = time(); + $expire_on = $timenow + ($cacheTime * 60); + $query = "INSERT INTO civicrm_wci_widget_cache (widget_id, widget_code, expire, createdtime) + VALUES (%1, %2, %3, %4) + ON DUPLICATE KEY UPDATE widget_id = %1, widget_code = %2, expire = %3, createdtime = %4"; $params = array( 1 => array($widgetId, 'Integer'), 2 => array($code, 'String'), - 3 => array($expire_on, 'Integer') + 3 => array($expire_on, 'Integer'), + 4 => array($timenow, 'Integer') ); CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_WidgetCache'); } @@ -131,11 +133,8 @@ class CRM_Wci_BAO_WidgetCache extends CRM_Wci_DAO_WidgetCache { $code = ""; $query = "SELECT widget_code FROM civicrm_wci_widget_cache where widget_id = %1 AND expire >= %2"; - $cacheTime = civicrm_api3('setting', 'getValue', - array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout')); - $expire_on = time() + ($cacheTime * 60); $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($widgetId, 'Integer'), - 2 => array($expire_on, 'Integer')), TRUE, 'CRM_Wci_DAO_WidgetCache'); + 2 => array(time(), 'Integer')), TRUE, 'CRM_Wci_DAO_WidgetCache'); if ($dao->fetch()) { $code = $dao->widget_code; } diff --git a/CRM/Wci/Upgrader.php b/CRM/Wci/Upgrader.php index 5663574..08f32e8 100644 --- a/CRM/Wci/Upgrader.php +++ b/CRM/Wci/Upgrader.php @@ -67,6 +67,7 @@ class CRM_Wci_Upgrader extends CRM_Wci_Upgrader_Base { `widget_id` int(10) unsigned NOT NULL COMMENT "widget id.", `widget_code` text DEFAULT NULL COMMENT "Widget code.", `expire` int(10) DEFAULT 0 COMMENT "A Unix timestamp indicating when the cache entry should expire.", + `createdtime` int(10) DEFAULT 0 COMMENT "A Unix timestamp indicating create time.", PRIMARY KEY (`widget_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; '); diff --git a/sql/install.sql b/sql/install.sql index d20d672..a80194e 100644 --- a/sql/install.sql +++ b/sql/install.sql @@ -67,9 +67,10 @@ CREATE TABLE IF NOT EXISTS civicrm_wci_embed_code ( -- WCI widget cache. CREATE TABLE IF NOT EXISTS civicrm_wci_widget_cache ( - widget_id int(10) id int(10) unsigned NOT NULL COMMENT 'widget id.', + widget_id int(10) unsigned NOT NULL COMMENT 'widget id.', widget_code text DEFAULT NULL COMMENT 'Widget code.', - expire int(10) DEFAULT 0 COMMENT 'A Unix timestamp indicating when the cache entry should expire.';, + expire int(10) DEFAULT 0 COMMENT 'A Unix timestamp indicating when the cache entry should expire.', + createdtime int(10) DEFAULT 0 COMMENT 'A Unix timestamp indicating create time.', PRIMARY KEY (`widget_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; -- 2.25.1