Quantcast
Channel: Active questions tagged feeds - Drupal Answers
Viewing all articles
Browse latest Browse all 188

How to prevent sitewide alert from ingesting duplicates?

$
0
0

I'm using:Drupal: 10.2.4feeds: 3.0-rc2feeds_tamper: 2.x-devsitewide_alert: 2.x-dev

Processor Settings is set for the feed to Update existing sitewide alerts.Feeds Tamper is set to create a GUID (the feed doesn't contain one) as

Channel 1-<title>-<timestamp>

so

Channel 1-My Title - 10/17/24-1729208414

where the "My Title - 10/17/24" is from the item's title, then prepended and appended values as I defined.

I hook my_module_sitewide_alert_presave and set the schedule start and end date values.

If I run the import twice, I get two of the same alerts, as follows:

sitewide_alert__feeds_item    ----------------------+----------------------------------+    | bundle         | deleted | entity_id | revision_id | langcode | delta | feeds_item_target_id | feeds_item_imported | feeds_item_url | feeds_item_guid                           | feeds_item_hash                  |+----------------+---------+-----------+-------------+----------+-------+----------------------+---------------------+----------------+-------------------------------------------+----------------------------------+    | sitewide_alert |       0 |        32 |          32 | en       |     0 |                    2 |          1729631534 | NULL           | Channel 1-Alert - 10/17/24-1729208414 | 67d043159b6e9847df5e7868a1813cff |    | sitewide_alert |       0 |        33 |          33 | en       |     0 |                    2 |          1729631587 | NULL           | Channel 1-Alert - 10/17/24-1729208414 | 67d043159b6e9847df5e7868a1813cff |sitewide_alert_field_data| id | vid | langcode | status | user_id | name             | style   | dismissible | dismissible_ignore_before_time | limit_to_pages | limit_to_pages_negate | message__value                       | message__format | scheduled_alert | scheduled_date__value | scheduled_date__end_value | created    | changed    | revision_translation_affected | default_langcode |+----+-----+----------+--------+---------+------------------+---------+-------------+--------------------------------+----------------+-----------------------+--------------------------------------+-----------------------+---------------+---------------------------+------------+------------+-------------------------------+------------------+| 52 |  52 | en       |      1 |       1 | Alert - 10/17/24 | primary |           1 |                              0 | NULL           |                     0 | The main elevator is out of service. | plain_text      |               0 | NULL                  | NULL                      | 1729675408 | 1729675408 |                             1 |                1 || 53 |  53 | en       |      1 |       1 | Alert - 10/17/24 | primary |           1 |                              0 | NULL           |                     0 | The main elevator is out of service. | plain_text      |               0 | NULL                  | NULL                      | 1729675446 | 1729675446 |                             1 |                1 |

The feed type definition:

SETTINGSFetcher: downloaded from URLParser: RSS/AtomDownloaded: Every 1 hourFETCHERNothing selectedPROCESSORInsert New Sitewide AlertsUpdate Existing Sitewide AlertsPreviously Imported Items: KeepExpire Sitewide Alerts: NeverOwner: admin (1)

Feed log settings all enabled as shown in the screen capture, and the db has entries for feeds_import_log_entry, but no log files are actually created and no errors (permissions, etc.) thrown.

The timestamp in the tamper is the token provided, which is the timestamp at which the source feed item was created, which is identical each time, of course, since it's the same source item.

Here is the presave hook:

function my_module_sitewide_alert_presave(EntityInterface $entity) {  if ($entity->get('scheduled_alert') == NULL) {    $entity->set('scheduled_alert', TRUE);  }  if ($entity->get('scheduled_date') == NULL) {    $date_time_input = date('Y-m-d H:i:s');    $date_time_input_next = date('Y-m-d H:i:s', strtotime('+24 Hour'));    $start_date = new DrupalDateTime($date_time_input); // Adjust the start date and time as needed.    $end_date = new DrupalDateTime($date_time_input_next);    $entity->set('scheduled_date', ['value' => $start_date->format('Y-m-d\TH:i:s'),'end_value' => $end_date->format('Y-m-d\TH:i:s'),    ]);  }}

Why is the duplicate (in terms of the GUID) being added? Is it not recognizing that the items are identical, or is it inserting when they are instead of updating?


Viewing all articles
Browse latest Browse all 188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>