From 635a1aa5b98ba8772d381c48774d4d7ebf82da28 Mon Sep 17 00:00:00 2001 From: "sws-developers@lists.stanford.edu" Date: Fri, 11 Jun 2021 18:12:15 +0000 Subject: [PATCH 1/3] Back to dev --- stanford_fields.info.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stanford_fields.info.yml b/stanford_fields.info.yml index ea50935..4cfd096 100755 --- a/stanford_fields.info.yml +++ b/stanford_fields.info.yml @@ -3,6 +3,6 @@ type: module description: 'Field types, widgets and formatters to enhance Drupal and Contrib.' core_version_requirement: ^8 || ^9 package: Stanford -version: 8.x-1.6 +version: 8.x-1.7-dev dependencies: - drupal:field From f17490e3aff9697be61cb22df50e3c31e43cad5c Mon Sep 17 00:00:00 2001 From: pookmish Date: Tue, 28 Sep 2021 07:49:30 -0700 Subject: [PATCH 2/3] D8CORE-4693 Invalidate events whose end dates have recently passed (#19) --- src/Service/FieldCache.php | 28 +++++++++++++++---- stanford_fields.module | 1 - tests/src/Kernel/Service/FieldCacheTest.php | 30 ++++++++++++++++++++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/Service/FieldCache.php b/src/Service/FieldCache.php index d5ece68..b2576e7 100644 --- a/src/Service/FieldCache.php +++ b/src/Service/FieldCache.php @@ -73,6 +73,7 @@ public function invalidateDateFieldsCache() { } Cache::invalidateTags(array_unique($cache_tags)); + $this->state->set('stanford_fields.dates_cleared', time() - 5); } /** @@ -111,21 +112,38 @@ protected function getExpiredDateCacheTags($entity_type, $field_name, array $bun // Query all entities for the given date field that is between the last ran // time and the current time. - $query = $entity_storage->getQuery() + $start_query = $entity_storage->getQuery() ->accessCheck(FALSE) - ->exists($field_name) + ->exists($field_name); + $end_query = clone $start_query; + $condition_group = $start_query->andConditionGroup() ->condition($field_name, $now->format($field_date_format), '<=') ->condition($field_name, $last_ran->format($field_date_format), '>='); + $start_query->condition($condition_group); // Some entity types don't have bundles, so don't add the condition if not // applicable. if ($bundle_key) { - $query->condition($bundle_key, $bundles, 'IN'); + $start_query->condition($bundle_key, $bundles, 'IN'); + $end_query->condition($bundle_key, $bundles, 'IN'); } - $tags = []; + $field_properties = $field_definition->getPropertyNames(); + // If the field type has an end value, modify the end query's conditions to + // check for those values. + if (in_array('end_value', $field_properties)) { + $condition_group = $end_query->andConditionGroup() + ->condition("$field_name.end_value", $now->format($field_date_format), '<=') + ->condition("$field_name.end_value", $last_ran->format($field_date_format), '>='); + } + $end_query->condition($condition_group); + + // Merge the start query ids with the end query ids. + $entity_ids = array_merge($start_query->execute(), $end_query->execute()); + + $tags = []; // If no entity ids were found, no tags should be invalidated. - if ($entity_ids = $query->execute()) { + if (!empty($entity_ids)) { $entities = $entity_storage->loadMultiple($entity_ids); foreach ($entities as $entity) { $tags = array_merge($tags, $entity->getCacheTagsToInvalidate()); diff --git a/stanford_fields.module b/stanford_fields.module index 86b468a..1cbab46 100755 --- a/stanford_fields.module +++ b/stanford_fields.module @@ -41,5 +41,4 @@ function stanford_fields_field_storage_add_validate(&$form, FormStateInterface $ */ function stanford_fields_cron() { \Drupal::service('stanford_fields.field_cache')->invalidateDateFieldsCache(); - \Drupal::state()->set('stanford_fields.dates_cleared', time() - 5); } diff --git a/tests/src/Kernel/Service/FieldCacheTest.php b/tests/src/Kernel/Service/FieldCacheTest.php index 10accae..29ed11b 100644 --- a/tests/src/Kernel/Service/FieldCacheTest.php +++ b/tests/src/Kernel/Service/FieldCacheTest.php @@ -26,6 +26,7 @@ class FieldCacheTest extends KernelTestBase { 'node', 'user', 'datetime', + 'datetime_range', 'field', ]; @@ -68,6 +69,16 @@ protected function setUp(): void { 'bundle' => 'page', 'field_name' => 'field_date', ])->save(); + FieldStorageConfig::create([ + 'entity_type' => 'node', + 'type' => 'daterange', + 'field_name' => 'field_daterange', + ])->save(); + FieldConfig::create([ + 'entity_type' => 'node', + 'bundle' => 'page', + 'field_name' => 'field_daterange', + ])->save(); \Drupal::getContainer()->set('cache_tags.invalidator', $cache_invalidator); } @@ -91,12 +102,29 @@ public function testDateInvalidation() { ->invalidateDateFieldsCache(); $this->assertEmpty($this->invalidatedTags); + \Drupal::state() + ->set('stanford_fields.dates_cleared', time() - 60 * 60 * 24 * 4); $node->set('field_date', date($this->dateFieldFormat, time() - 60 * 60 * 24 * 3)) ->save(); $this->invalidatedTags = []; \Drupal::service('stanford_fields.field_cache') ->invalidateDateFieldsCache(); $this->assertTrue(in_array('node:' . $node->id(), $this->invalidatedTags)); + + \Drupal::state() + ->set('stanford_fields.dates_cleared', time() - 60 * 60 * 24 * 4); + $daterange = [ + 'value' => date($this->dateFieldFormat, time() - 60 * 60 * 24 * 10), + 'end_value' => date($this->dateFieldFormat, time() - 60 * 60 * 24), + ]; + $node->set('field_date', []) + ->set('field_daterange', $daterange) + ->save(); + + $this->invalidatedTags = []; + \Drupal::service('stanford_fields.field_cache') + ->invalidateDateFieldsCache(); + $this->assertTrue(in_array('node:' . $node->id(), $this->invalidatedTags)); } /** @@ -117,4 +145,4 @@ public function invalidateTagsCallback($tags) { $this->invalidatedTags = $tags; } -} \ No newline at end of file +} From 465df6371bb5688667ddb154bd15a2ff0b573ec5 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Fri, 8 Oct 2021 10:35:34 -0700 Subject: [PATCH 3/3] 8.1.7 --- CHANGELOG.md | 7 +++++++ stanford_fields.info.yml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9caa62c..682a615 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Stanford Fields + +8.x-1.7 +-------------------------------------------------------------------------------- +_Release Date: 2021-10-08_ + +- D8CORE-4693 Invalidate events whose end dates have recently passed (#19) + 8.x-1.5 -------------------------------------------------------------------------------- _Release Date: 2021-05-07_ diff --git a/stanford_fields.info.yml b/stanford_fields.info.yml index 4cfd096..5c714a7 100755 --- a/stanford_fields.info.yml +++ b/stanford_fields.info.yml @@ -3,6 +3,6 @@ type: module description: 'Field types, widgets and formatters to enhance Drupal and Contrib.' core_version_requirement: ^8 || ^9 package: Stanford -version: 8.x-1.7-dev +version: 8.x-1.7 dependencies: - drupal:field