[EventCalendar] Repeating Events

Chris Janton face at CentosPrime.COM
Wed Jun 6 16:15:28 UTC 2007


Good day.

I didn't look too far back in the archives to see what prior work may  
be been done (1 month actually)
so my apologies if I have wandered off track.

I have a number (about 60) repeating events that I would like to keep  
current in my schedule.

I am willing to run a "cron" job on a daily basis to maintain the  
repeating events in my schedule.

I would like it if my schedule "kept track" of past events. If I use  
the event calendar to see the previous month it would be good if I  
could see the repeating events. I do not need to provide "previous"  
events further back than 12 months.

The net effect is that I can scroll my calendar backwards or forwards  
and see the repeating events.

The above can be accomplished with a bit of SQL (MySQL 4.0+) and the  
use of some conventional indicators in the RPT column of the schedule.

-- wp_ec3_schedule-maintenance.sql
-- 2007-06-06 - version 0.9
--
-- Step 1 - move all "expired" repeating events to their next  
scheduled date

UPDATE wp_ec3_schedule SET
start = date_add(start, interval 1 year)
, end = date_add(end, interval 1 year)
WHERE
rpt = '1'
and date_add(end, interval 0 day) < curdate()
;

-- Step 2 - remove all of our "previous" entries

DELETE FROM wp_ec3_schedule WHERE rpt = '2';

-- Step 3 - create "previous" entries

INSERT INTO wp_ec3_schedule(post_id, start, end, allday, rpt)
SELECT
   post_id
   , date_add(start, interval -1 year)
   , date_add(end, interval -1 year)
   , allday
   , '2'
FROM
   wp_ec3_schedule
WHERE
   rpt = '1'
   and (end between
        date_add(now(), interval 1 day)
        and date_add(now(), interval 1 year)
       )
   ORDER BY start
;
-- end wp_ec3_schedule-maintenance.sql

If I bundle up the SQL and execute it once a day I get exactly what I  
want with minimal replication and run time.
For my current 56 events I wind up with 111 rows in the schedule. It  
takes less than 1 second to do the update.

Comments? Suggestions?

P.S. I manually set the contents of RPT to '1' before I started all  
of this.

8)
----------------------------------
Chris Janton  - face at CentosPrime dot COM
Netminder for Opus1.COM





More information about the EventCalendar mailing list