Commit 37c86ef3 authored by spleshka's avatar spleshka

Added possibility to expire voted entity (for VotingAPI).

parent afb51193
......@@ -318,7 +318,7 @@ function expire_admin_settings_form() {
'#type' => 'checkboxes',
'#description' => t('Page cache for votes will be expired after selected actions.'),
'#options' => array(
EXPIRE_VOTINGAPI_INSERT=> t('Vote insert'),
EXPIRE_VOTINGAPI_INSERT => t('Vote insert'),
EXPIRE_VOTINGAPI_DELETE => t('Vote delete'),
),
'#default_value' => variable_get('expire_votingapi_actions', array()),
......@@ -329,9 +329,16 @@ function expire_admin_settings_form() {
'#title' => t('What URLs should be expired when votingapi action is triggered?'),
);
$form['tabs']['votingapi']['expire']['expire_votingapi_entity'] = array(
$form['tabs']['votingapi']['expire']['expire_votingapi_entity_page'] = array(
'#type' => 'checkbox',
'#title' => t('Voted entity page'),
'#default_value' => variable_get('expire_votingapi_entity_page', EXPIRE_VOTINGAPI_ENTITY_PAGE),
);
$form['tabs']['votingapi']['expire']['expire_votingapi_entity'] = array(
'#type' => 'checkbox',
'#title' => t('Voted entity'),
'#description' => t('Note that will be executed expiration selected for voted entity type.'),
'#default_value' => variable_get('expire_votingapi_entity', EXPIRE_VOTINGAPI_ENTITY),
);
......
......@@ -149,7 +149,7 @@ function _drush_expire_entity($entity_type) {
$ids = drush_get_arguments();
unset($ids[0]);
$handler = _expiration_get_object($entity_type);
$handler = _expire_get_expiration_handler($entity_type);
$entities = entity_load($entity_type, $ids);
if (is_object($handler) && !empty($entities)) {
foreach ($entities as $entity) {
......
......@@ -41,7 +41,7 @@ define('EXPIRE_DEBUG_DISABLED', 0);
define('EXPIRE_DEBUG_WATCHDOG', 1);
define('EXPIRE_DEBUG_FULL', 2);
// Default values for cache expirations.
// Default values for cache expiration.
define('EXPIRE_NODE_FRONT_PAGE' , FALSE);
define('EXPIRE_NODE_NODE_PAGE' , TRUE);
define('EXPIRE_NODE_TERM_PAGES' , FALSE);
......@@ -57,6 +57,7 @@ define('EXPIRE_USER_FRONT_PAGE' , FALSE);
define('EXPIRE_USER_USER_PAGE' , TRUE);
define('EXPIRE_USER_CUSTOM' , FALSE);
define('EXPIRE_VOTINGAPI_ENTITY' , FALSE);
define('EXPIRE_VOTINGAPI_ENTITY_PAGE' , FALSE);
define('EXPIRE_VOTINGAPI_CUSTOM' , FALSE);
/**
......@@ -195,7 +196,7 @@ function expire_votingapi_delete($votes) {
function expire_execute_expiration($type, $object, $action) {
$status = variable_get('expire_status', EXPIRE_STATUS_DISABLED);
if ($status) {
return _expiration_get_object($type)->expire($object, $action);
return _expire_get_expiration_handler($type)->expire($object, $action);
}
return FALSE;
}
......@@ -209,7 +210,7 @@ function expire_execute_expiration($type, $object, $action) {
*
* @return mixed
*/
function _expiration_get_object($type) {
function _expire_get_expiration_handler($type) {
static $cache_objects;
if (!isset($cache_objects[$type])) {
$class = variable_get('expire_handler_' . $type, 'Expire' . drupal_ucfirst($type));
......
......@@ -49,14 +49,14 @@ class ExpireVotingapi implements ExpireInterface {
$entity_id = $vote['entity_id'];
// Expire voted entity url.
$expire_entity_page = variable_get('expire_votingapi_entity', EXPIRE_VOTINGAPI_ENTITY);
$expire_entity_page = variable_get('expire_votingapi_entity_page', EXPIRE_VOTINGAPI_ENTITY_PAGE);
if ($expire_entity_page) {
$entities = entity_load($entity_type, array($entity_id));
// Load entity.
$entity = entity_load_single($entity_type, $entity_id);
// Check whether entity is loaded.
if (isset($entities[$entity_id])) {
$entity = $entities[$entity_id];
if (!empty($entity)) {
// Check whether entity has uri.
$uri = entity_uri($entity_type, $entity);
......@@ -66,6 +66,18 @@ class ExpireVotingapi implements ExpireInterface {
}
}
// Execute expiration for voted entity.
$expire_entity = variable_get('expire_votingapi_entity', EXPIRE_VOTINGAPI_ENTITY_PAGE);
if ($expire_entity) {
// Load entity.
$entity = entity_load_single($entity_type, $entity_id);
$handler = _expire_get_expiration_handler($entity_type);
if (is_object($handler) && !empty($entity)) {
$handler->expire($entity, 0, $skip_action_check = TRUE);
}
}
// Expire custom pages.
$expire_custom = variable_get('expire_votingapi_custom', EXPIRE_VOTINGAPI_CUSTOM);
if ($expire_custom) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment