Commit 0bacb207 authored by leonnk's avatar leonnk Committed by Spleshka

Issue #2201913 by joelpittet, leon.nk, mukhsim, dberror, Spleshka: Add support for terms expire

parent af2f57b2
This diff is collapsed.
......@@ -56,6 +56,21 @@ function expire_drush_command() {
'callback' => 'drush_expire_node'
);
// Expire taxonomy term objects.
$items['expire-term'] = array(
'description' => 'Expire a taxonomy term by term ID.',
'arguments' => array(
'tids' => 'Numeric term ids to expire separated by spaces.',
),
'examples' => array(
'drush expire-term 2' => 'Expire single taxonomy term by term ID.',
'drush xp-term 2 24 612' => 'Expire multiple taxonomy terms by term IDs.',
),
'aliases' => array('xp-term'),
'drupal dependencies' => array('expire'),
'callback' => 'drush_expire_term',
);
// Expire user objects.
$items['expire-user'] = array(
'description' => 'Expire a user by user ID.',
......@@ -132,6 +147,13 @@ function drush_expire_node() {
_drush_expire_entity('node');
}
/**
* Callback for expire-term drush command.
*/
function drush_expire_term() {
_drush_expire_entity('taxonomy_term');
}
/**
* Callback for expire-user drush command.
*/
......
......@@ -11,6 +11,7 @@ files[] = includes/expire.domain.inc
files[] = includes/expire.interface.inc
files[] = includes/expire.menu_link.inc
files[] = includes/expire.node.inc
files[] = includes/expire.taxonomy_term.inc
files[] = includes/expire.user.inc
files[] = includes/expire.votingapi.inc
files[] = includes/expire.file.inc
......@@ -26,6 +26,11 @@ define('EXPIRE_NODE_INSERT', 1);
define('EXPIRE_NODE_UPDATE', 2);
define('EXPIRE_NODE_DELETE', 3);
// Taxonomy term actions.
define('EXPIRE_TAXONOMY_TERM_INSERT', 1);
define('EXPIRE_TAXONOMY_TERM_UPDATE', 2);
define('EXPIRE_TAXONOMY_TERM_DELETE', 3);
// Comment actions.
define('EXPIRE_COMMENT_INSERT' , 1);
define('EXPIRE_COMMENT_UPDATE' , 2);
......@@ -64,6 +69,12 @@ define('EXPIRE_NODE_TERM_PAGES' , FALSE);
define('EXPIRE_NODE_REFERENCE_PAGES' , FALSE);
define('EXPIRE_NODE_REFERENCE_FC_PAGES' , FALSE);
define('EXPIRE_NODE_CUSTOM' , FALSE);
define('EXPIRE_TAXONOMY_TERM_FRONT_PAGE' , FALSE);
define('EXPIRE_TAXONOMY_TERM_TAXONOMY_TERM_PAGE', TRUE);
define('EXPIRE_TAXONOMY_TERM_TERM_PAGES' , FALSE);
define('EXPIRE_TAXONOMY_TERM_REFERENCE_PAGES' , FALSE);
define('EXPIRE_TAXONOMY_TERM_REFERENCE_FC_PAGES', FALSE);
define('EXPIRE_TAXONOMY_TERM_CUSTOM' , FALSE);
define('EXPIRE_COMMENT_FRONT_PAGE' , FALSE);
define('EXPIRE_COMMENT_COMMENT_PAGE' , TRUE);
define('EXPIRE_COMMENT_REFERENCE_PAGES' , FALSE);
......@@ -132,6 +143,35 @@ function expire_node_delete($node) {
expire_execute_expiration('node', $node, EXPIRE_NODE_DELETE);
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function expire_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) {
module_load_include('admin.inc', 'expire');
expire_taxonomy_term_settings_form($form, $form_state);
}
/**
* Implements hook_taxonomy_term_insert().
*/
function expire_taxonomy_term_insert($taxonomy_term) {
expire_execute_expiration('taxonomy_term', $taxonomy_term, EXPIRE_TAXONOMY_TERM_INSERT);
}
/**
* Implements hook_taxonomy_term_update().
*/
function expire_taxonomy_term_update($taxonomy_term) {
expire_execute_expiration('taxonomy_term', $taxonomy_term, EXPIRE_TAXONOMY_TERM_UPDATE);
}
/**
* Implements hook_taxonomy_term_delete().
*/
function expire_taxonomy_term_delete($taxonomy_term) {
expire_execute_expiration('taxonomy_term', $taxonomy_term, EXPIRE_TAXONOMY_TERM_DELETE);
}
/**
* Implements hook_comment_insert().
*/
......
<?php
/**
* @file
* Provides class that expires taxonomy terms.
*/
class ExpireTaxonomyTerm implements ExpireInterface {
/**
* Executes expiration actions for taxonomy term.
*
* @param $taxonomy_term
* Taxonomy term object.
*
* @param $action
* Action that has been executed.
*
* @param $skip_action_check
* Shows whether should we check executed action or just
* expire taxonomy term.
*/
function expire($taxonomy_term, $action, $skip_action_check = FALSE) {
if (empty($taxonomy_term->tid) || empty($taxonomy_term->vocabulary_machine_name)) {
return;
}
// See if cache settings was overridden for this
// taxonomy_term vocabulary_machine_name.
$settings_overridden = variable_get('expire_taxonomy_term_override_defaults_' . $taxonomy_term->vocabulary_machine_name);
$variable_suffix = '';
if (!empty($settings_overridden)) {
// If page cache settings was overridden for this taxonomy_term
// vocabulary_machine_name we should add
// "[taxonomy_term-VOCABULARY_MACHINE_NAME]" to every variable name
// we use here.
$variable_suffix = '_' . $taxonomy_term->vocabulary_machine_name;
}
$enabled_actions = variable_get('expire_taxonomy_term_actions' . $variable_suffix, array());
$enabled_actions = array_filter($enabled_actions);
// Stop further expiration if executed action is not selected by admin.
if (!in_array($action, $enabled_actions) && !$skip_action_check) {
return;
}
$expire_urls = array();
// Expire front page.
$expire_front_page = variable_get('expire_taxonomy_term_front_page' . $variable_suffix, EXPIRE_TAXONOMY_TERM_FRONT_PAGE);
if ($expire_front_page) {
$expire_urls = ExpireAPI::getFrontPageUrls();
}
// Expire taxonomy_term page.
$expire_taxonomy_term_page = variable_get('expire_taxonomy_term_taxonomy_term_page' . $variable_suffix, EXPIRE_TAXONOMY_TERM_TAXONOMY_TERM_PAGE);
if ($expire_taxonomy_term_page) {
$expire_urls['taxonomy_term-' . $taxonomy_term->tid] = 'taxonomy/term/' . $taxonomy_term->tid;
}
// Expire taxonomy_term reference's pages.
$expire_taxonomy_term_references = variable_get('expire_taxonomy_term_reference_pages' . $variable_suffix, EXPIRE_TAXONOMY_TERM_REFERENCE_PAGES);
if ($expire_taxonomy_term_references) {
$urls = ExpireAPI::expireTermPages($taxonomy_term, 'taxonomy_term');
$expire_urls = array_merge($expire_urls, $urls);
if (module_exists('node_reference') || module_exists('user_reference') || module_exists('entityreference')) {
$traverse_field_collection = module_exists('field_collection') && variable_get('expire_taxonomy_term_reference_field_collection_pages' . $variable_suffix, EXPIRE_TAXONOMY_TERM_REFERENCE_FC_PAGES);
$urls = ExpireAPI::expireReferences($taxonomy_term, 'taxonomy_term', $traverse_field_collection);
$expire_urls = array_merge($expire_urls, $urls);
}
}
// Expire custom pages.
$expire_custom = variable_get('expire_taxonomy_term_custom' . $variable_suffix, EXPIRE_TAXONOMY_TERM_CUSTOM);
if ($expire_custom) {
$pages = variable_get('expire_taxonomy_term_custom_pages' . $variable_suffix);
$urls = ExpireAPI::expireCustomPages($pages, array('taxonomy_term' => $taxonomy_term));
$expire_urls = array_merge($expire_urls, $urls);
}
// Flush page cache for expired urls.
ExpireAPI::executeExpiration($expire_urls, 'taxonomy_term', $taxonomy_term);
}
}
......@@ -6,11 +6,13 @@
$('fieldset#edit-expire', context).drupalSetSummary(function(context) {
var vals = [];
if ($('#edit-expire-node-override-defaults', context).is(':checked')) {
vals.push(Drupal.t('Node expiration: settings are overriden'));
}
else {
vals.push(Drupal.t('Node expiration: default settings'));
if ($('#edit-expire-node-override-defaults', context).length) {
if ($('#edit-expire-node-override-defaults', context).is(':checked')) {
vals.push(Drupal.t('Node expiration: settings are overriden'));
}
else {
vals.push(Drupal.t('Node expiration: default settings'));
}
}
if ($('#edit-expire-comment-override-defaults', context).length) {
......@@ -22,6 +24,15 @@
}
}
if ($('#edit-expire-taxonomy-term-override-defaults', context).length) {
if ($('#edit-expire-taxonomy-term-override-defaults', context).is(':checked')) {
vals.push(Drupal.t('Taxonomy term expiration: settings are overriden'));
}
else {
vals.push(Drupal.t('Taxonomy term expiration: default settings'));
}
}
return vals.join(', ');
});
......
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