Jan/093
Disable “discard items” in drupal feed aggregator
I’m using the Drupal CMS in version 6.8 on one of my homepages. I use the delivered plugin Aggregator for parsing a news feed. It works as it should with one exception: The Aggregator deletes some objects when they are older than the configured time. This feature is called “discard old items”. You can configure the time-range in admin interface of Aggregator.
I found it not good to have some pre computed values in a drop-down field. I would better like to add an individual time-range myself.
Additional I like to disable this feature for my feed. Additionally it would be nice to be able to change the “discard” criteria to something other – You’ll find some ideas at the end of this post.
<
p>The most important thing on my list: Disable deletion of old posts by timerange. I patched two files to reach this.
<
p>
At first I modified the file modules/aggregator/aggregator.admin.inc and added an option 0 to the time-range. Selecting this option will disable the deletion.
:> diff aggregator.admin.inc.orig aggregator.admin.inc 225c225 < $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'); --- > $period = drupal_map_assoc(array(0, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
Secondly I patched the code of the Aggregator module file in modules/aggregator/aggregator.module. I added a check whether the aggregator_clear option is zero. Nothing will be deleted when 0 is selected.
:> diff aggregator.module.orig aggregator.module 806,817c806,820 < $age = time() - variable_get('aggregator_clear', 9676800); < $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age); < < $items = array(); < $num_rows = FALSE; < while ($item = db_fetch_object($result)) { < $items[] = $item->iid; < $num_rows = TRUE; < } < if ($num_rows) { < db_query('DELETE FROM {aggregator_category_item} WHERE iid IN ('. implode(', ', $items) .')'); < db_query('DELETE FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age); --- > $now = time(); > $age = $now - variable_get('aggregator_clear', 9676800); > if($age < $now) { > $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age); > > $items = array(); > $num_rows = FALSE; > while ($item = db_fetch_object($result)) { > $items[] = $item->iid; > $num_rows = TRUE; > } > if ($num_rows) { > db_query('DELETE FROM {aggregator_category_item} WHERE iid IN ('. implode(', ', $items) .')'); > db_query('DELETE FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age); > }
After the changes I set the “discard items” to zero in aggregator configuration. After the first sync of the feed there were no more posts added. I assume the feed was not refreshed cause the aggregator detected that the feed did not change since last check. So I decided to delete the current feed and re-add it.
While playing around I found an annoying bug: When deleting a feed, in my case with ID 1, in aggregator the URL aggregator/sources/1 gets invalid. When adding a new feed it gets the ID 2 (auto_increment). Ok, no problem. But: I had an alias home which was linked to the aggregator/sources/1 url. Now that the url is not valid anymore the alias seems to be invisible to me. I can not add a new one which pints to aggregator/sources/2 and I even can’t delete this old entry. Bad thing. I did not really try to solve that problem in Admin GUI. I solved this by connecting to the database and changing the alias by hand:
UPDATE url_alias SET src='aggregator/sources/2' WHERE dst='home';
After that I update the feed by triggering the cron manually. All posts which would have been deleted without the patch are there now. Great!
The next step could be adding another filter criteria like the number of posts. Or another filter: Remove all posts which are not in the feed anymore.




























06:26 on January 21st, 2009
Thank you so much! this patch does exactly what I needed in order for my older post to show up.
02:51 on April 11th, 2010
Awesome – this should be a part of the core release
11:36 on January 18th, 2011
Thanks so much for sharing this info, was very useful. However, my feeds are not updated as of now, I deleted the old feed and created a new one, hopefully it will be updated in some time.