Issue #2074229 by Gábor Hojtsy, tstoeckler: Add changed time tracking to taxonomy terms.

8.0.x
webchick 2013-09-04 11:31:38 -07:00
parent 65c125e577
commit e346ac5fda
5 changed files with 114 additions and 1 deletions

View File

@ -106,6 +106,10 @@ class FilledStandardUpgradePathTest extends UpgradePathTestBase {
$this->assertTrue(isset($entity_view_modes['full']));
}
// Ensure that taxonomy terms have a 'changed' timestamp.
$term = entity_load('taxonomy_term', 1);
$this->assertNotEqual($term->getChangedTime(), 0);
// Check that user data has been migrated correctly.
$query = db_query('SELECT * FROM {users_data}');

View File

@ -173,6 +173,14 @@ class Term extends EntityNG implements TermInterface {
}
}
/**
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
// Before saving the term, set changed time.
$this->changed->value = REQUEST_TIME;
}
/**
* {@inheritdoc}
*/
@ -241,7 +249,19 @@ class Term extends EntityNG implements TermInterface {
'settings' => array('default_value' => 0),
'computed' => TRUE,
);
$properties['changed'] = array(
'label' => t('Changed'),
'description' => t('The time that the term was last edited.'),
'type' => 'integer_field',
);
return $properties;
}
/**
* {@inheritdoc}
*/
public function getChangedTime() {
return $this->changed->value;
}
}

View File

@ -8,10 +8,11 @@
namespace Drupal\taxonomy;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
/**
* Provides an interface defining a taxonomy term entity.
*/
interface TermInterface extends ContentEntityInterface {
interface TermInterface extends ContentEntityInterface, EntityChangedInterface {
}

View File

@ -83,6 +83,12 @@ function taxonomy_schema() {
'default' => 0,
'description' => 'The weight of this term in relation to other terms.',
),
'changed' => array(
'description' => 'The Unix timestamp when the term was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('tid'),
'unique keys' => array(
@ -393,3 +399,17 @@ function taxonomy_update_8007() {
}
}
}
/**
* Add a changed column for taxonomy terms.
*/
function taxonomy_update_8008() {
$spec = array(
'description' => 'The Unix timestamp when the term was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'initial' => REQUEST_TIME,
);
db_add_field('taxonomy_term_data', 'changed', $spec);
}

View File

@ -179,6 +179,74 @@ function taxonomy_views_data() {
),
);
$data['taxonomy_term_data']['changed'] = array(
'title' => t('Updated date'),
'help' => t('The date the term was last updated.'),
'field' => array(
'id' => 'date',
),
'sort' => array(
'id' => 'date'
),
'filter' => array(
'id' => 'date',
),
);
$data['taxonomy_term_data']['changed_fulldate'] = array(
'title' => t('Updated date'),
'help' => t('Date in the form of CCYYMMDD.'),
'argument' => array(
'field' => 'changed',
'id' => 'date_fulldate',
),
);
$data['taxonomy_term_data']['changed_year_month'] = array(
'title' => t('Updated year + month'),
'help' => t('Date in the form of YYYYMM.'),
'argument' => array(
'field' => 'changed',
'id' => 'date_year_month',
),
);
$data['taxonomy_term_data']['changed_year'] = array(
'title' => t('Updated year'),
'help' => t('Date in the form of YYYY.'),
'argument' => array(
'field' => 'changed',
'id' => 'date_year',
),
);
$data['taxonomy_term_data']['changed_month'] = array(
'title' => t('Updated month'),
'help' => t('Date in the form of MM (01 - 12).'),
'argument' => array(
'field' => 'changed',
'id' => 'date_month',
),
);
$data['taxonomy_term_data']['changed_day'] = array(
'title' => t('Updated day'),
'help' => t('Date in the form of DD (01 - 31).'),
'argument' => array(
'field' => 'changed',
'id' => 'date_day',
),
);
$data['taxonomy_term_data']['changed_week'] = array(
'title' => t('Updated week'),
'help' => t('Date in the form of WW (01 - 53).'),
'argument' => array(
'field' => 'changed',
'id' => 'date_week',
),
);
// Content translation field.
if (Drupal::moduleHandler()->moduleExists('content_translation')) {
$data['taxonomy_term_data']['translation_link'] = array(