Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Search

 
Advanced search

8043 Posts in 1856 Topics- by 2099 Members - Latest Member: roi
Calendar Script CommunityCustomizationPlugins (Moderators: scott, DanO, Marty)EmailNotify2 and DeleteOld plugin
Pages: [1]   Go Down
Print
Author Topic: EmailNotify2 and DeleteOld plugin  (Read 369 times)
0 Members and 1 Guest are viewing this topic.
k9barry
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« on: December 17, 2003, 02:55:00 PM »

Trying to get the DeleteOld plugin to work with EmailNotify2 now that I have it working.  I can delete the events from the DeleteOld plugin but I get no notification from EmaiNotify2 that the events were deleted.  I tried to modify the command_delete_old.pl file to this see below but no luck.

sub command_delete_old
{
   foreach (keys %in)
   {
      if ($_ =~ /^DELETE_(.*)$/)
      {
         #if anything fails, somebody is trying to hack your calendar.
         &checkPermissions($1, "EDIT_EVENTS");
      }
   }
   
   my $deldate = $in{DELETEDATE};
   $deldate =~ /^(\d\d\d\d)(\d\d)(\d\d)$/;
   
   $deldate = Time::Local::timegm(0,0,0,$3,$2-1,$1-1900);
   
   foreach (keys %in)
   {
      if ($_ =~ /^DELETE_(.*)$/)
      {
         my $key = $1;
         my $name = $in{$_};   #I saved the calendar name in the value to save looking it up.
         
         my $edb = new DBFile($BASE_DIR . "calendars/" . $key . "/events");
         my $sdb = new DBFile($BASE_DIR . "calendars/" . $key . "/schedule");
         
         my $deadsched = $sdb->getRecords({'end' => "=<$deldate"});   #save records about to delete
         
         my (%goodids, %deadids);
         foreach (@$deadsched)
         {
            if ($_->{start} && $_->{end})   #don't delete unbounded recurring events.
            {
               $sdb->deleteRecords( {'id'=>$_->{id}} );
               $deadids{$_->{event_id}} = 1;
            }
         }
            
         my $schedleft = $sdb->getRecords( {} );      #get all events left in schedule db
         foreach (@$schedleft)   #save the good ids that are left in schedule db
         { $goodids{$_->{event_id}} = 1; }
         
         my $count = 0;
         foreach (keys %deadids)
         {
            unless ($goodids{$_})   #if it's not still in the schedule database
            {
               $edb->deleteRecords( { 'id' => $_ } );   #remove it from the events database
#Added to include event deleted with Email Notify 2
               $in{'EVENT_id'} = $id;
               &handleCustomFunction("before_delete_event");
#/Added to include event deleted with Email Notify 2
               $count++;
            }               
         }
         
         if ($count == 0)
         {   &addUserMessage("No events to delete from $name."); }
         else
         {   &addUserMessage("Deleted $count event".($count > 1 ? "s" : "") ." from $name."); }
         
         #we have to do all that in case we deleted the first few occurences of an event but not
         #the last ones.  We don't want to delete an event from the events database that still
         #has entries in the schedule database.
         
         #I know this is slow (O(n^2) where it could be O(n)), but it shouldn't cause a problem,
         #since this not run often.  Let me know if it gets to be a problem.
      }
   }
   
}

1;

When I figure this one out I will work on a similar change to the MoveEvents plug-in that has the same problem.

Thanks for any help.

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #1 on: December 17, 2003, 07:09:00 PM »

 
quote:
#Added to include event deleted with Email Notify 2
$in{'EVENT_id'} = $id;
&handleCustomFunction("before_delete_event");
#/Added to include event deleted with Email Notify 2
I see you using the variable $id but is it even defined in the command_delete_old.pl file?

Dan O.

------------------

Logged
Pages: [1]   Go Up
Print
Jump to: