Changeset 4497

Show
Ignore:
Timestamp:
10/27/06 14:57:20 (2 years ago)
Author:
rambo
Message:

version bump, bulletproofing to notifications handling, ical dump of event attached to notifications

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/org.openpsa.calendar/calendar_midcomdba.php

    r4085 r4497  
    508508        $this->_get_em('old_'); 
    509509 
     510        /* 
    510511        debug_add("this->participants\n===\n" .  sprint_r($this->participants) . "===\n"); 
    511512        debug_add("this->old_participants\n===\n" .  sprint_r($this->old_participants) . "===\n"); 
    512513        debug_add("this->_carried_participants_obj\n===\n" .  sprint_r($this->_carried_participants_obj) . "===\n"); 
     514        */ 
    513515 
    514516        $this->_update_em($repeat_handler); 
     
    520522    function _on_updated() 
    521523    { 
     524        debug_push_class(__CLASS__, __FUNCTION__); 
     525 
     526        debug_add("this->participants\n===\n" .  sprint_r($this->participants) . "===\n"); 
     527        debug_add("this->old_participants\n===\n" .  sprint_r($this->old_participants) . "===\n"); 
     528        debug_add("this->_carried_participants_obj\n===\n" .  sprint_r($this->_carried_participants_obj) . "===\n"); 
     529 
    522530        foreach ($this->_carried_participants_obj as $resObj) 
    523531        { 
     532            debug_add("Notifying participant #{$resObj->id}"); 
    524533            if ($this->notify_force_add) 
    525534            { 
     
    533542        foreach ($this->_carried_resources_obj as $resObj) 
    534543        { 
     544            debug_add("Notifying resource #{$resObj->id}"); 
    535545            if ($this->notify_force_add) 
    536546            { 
     
    568578        $this->get_suspected_task_links(); 
    569579        $this->get_suspected_sales_links(); 
     580        debug_pop(); 
    570581        return true; 
    571582    } 
     
    573584    function _get_member_by_personid($id, $type='participant') 
    574585    { 
     586        debug_push_class(__CLASS__, __FUNCTION__); 
    575587        switch ($type) 
    576588        { 
     
    582594            default: 
    583595                //Other values are disallowed 
     596                debug_add("Type '{$type}' is invalid, aborting", MIDCOM_LOG_ERROR); 
     597                debug_pop(); 
    584598                return false; 
    585599            break; 
    586600        } 
    587         $className = 'org_openpsa_calendar_event' . $type; 
    588          
    589         //Find the correct eventmember by person ID 
    590         $finder = new org_openpsa_eventmember(); 
    591         $finder->eid = $this->id; 
    592         $finder->uid = $id; 
    593         $finder->find(); 
    594         if ($finder->N > 0) 
    595         { 
    596             //There should be only one match in any case 
    597             $finder->fetch(); 
    598             $resObj = new $className($finder->id); 
    599             return $resObj; 
    600         } 
     601        $class = 'org_openpsa_calendar_event' . $type; 
     602        if (!class_exists($class)) 
     603        { 
     604            // For the weirdest reason we don't have the class 
     605            debug_add("Class '{$class}' does not exist, aborting", MIDCOM_LOG_ERROR); 
     606            debug_pop(); 
     607            return false; 
     608        } 
     609 
     610        $qb = call_user_func(array($class, 'new_query_builder')); 
     611        $qb->add_constraint('eid', '=', $this->id); 
     612        $qb->add_constraint('uid', '=', $id); 
     613        $results = $qb->execute_unchecked(); 
     614        debug_add("qb returned:\n===\n" . sprint_r($results) . "===\n"); 
     615        if (empty($results)) 
     616        { 
     617            debug_pop(); 
     618            return false; 
     619        } 
     620        debug_pop(); 
     621        return $results[0]; 
    601622    } 
    602623     
     
    872893    { 
    873894        debug_push_class(__CLASS__, __FUNCTION__); 
    874         //We need sudo to see busys in events we normally don't see and to rob resources from tentative events 
    875         $_MIDCOM->auth->request_sudo(); 
    876         //If this event is tentative always disallow robbing resources from other tentative events 
    877         if ($this->tentative) 
    878         { 
    879             $rob_tentative=false; 
    880         } 
    881895        //If we're not busy it's not worth checking 
    882896        if (!$this->busy) { 
     
    885899            return false; 
    886900        } 
     901        //If this event is tentative always disallow robbing resources from other tentative events 
     902        if ($this->tentative) 
     903        { 
     904            $rob_tentative = false; 
     905        } 
     906        //We need sudo to see busys in events we normally don't see and to rob resources from tentative events 
     907        $_MIDCOM->auth->request_sudo(); 
    887908         
    888909        //Storage for events that have been modified due the course of this method 
     
    11331154     * Creates/removes eventmembers based on $this->resources and $this->participants 
    11341155     */ 
    1135     function _update_em($repeat_handler='this') 
     1156    function _update_em($repeat_handler = 'this') 
    11361157    { 
    11371158        debug_push_class(__CLASS__, __FUNCTION__); 
    11381159        //There is probably a better way... 
    1139         if ($repeat_handler!='this') 
    1140         { 
    1141             $this->send_notify=false; 
    1142         } 
    1143          
     1160        if ($repeat_handler != 'this') 
     1161        { 
     1162            $this->send_notify = false; 
     1163        } 
     1164 
    11441165        $ret = array(); 
    11451166        $ret['resources'] = array(); 
     
    11651186            $this->old_participants = array(); 
    11661187        } 
    1167          
     1188 
    11681189        // ** Start with resources 
    11691190        $added_resources = $this->resource_diff($this->resources, $this->old_resources); 
     
    11761197            $resObj->uid = $resourceId; 
    11771198            $resObj->eid = $this->id; 
     1199            $resObj->orgOpenpsaObtype = ORG_OPENPSA_OBTYPE_EVENTRESOURCE; 
    11781200            $ret['resources']['added'][$resObj->uid] = $resObj->create($this->send_notify, &$this); 
    11791201        } 
    1180          
     1202 
    11811203        foreach ($removed_resources as $resourceId => $bool) 
    11821204        { 
     
    11851207            { 
    11861208                $ret['resources']['removed'][$resObj->uid] = $resObj->delete($this->send_notify, &$this); 
    1187                 // TODO: Remove ACL permissions from removed members                 
    1188             } 
    1189         } 
    1190          
     1209                // TODO: Remove ACL permissions from removed members 
     1210            } 
     1211        } 
     1212 
     1213        // Make sure we can read the carried objects 
     1214        $_MIDCOM->auth->request_sudo(); 
    11911215        foreach ($carried_resources as $resourceId => $bool) 
    11921216        { 
    11931217            //Find the correct eventmember by person ID 
    11941218            $resObj = $this->_get_member_by_personid($resourceId, 'resource'); 
    1195             if (is_object($resObj)) 
    1196             { 
    1197                 $this->_carried_resources_obj[] = $resObj; 
    1198             } 
    1199         } 
     1219            if (!is_object($resObj)) 
     1220            { 
     1221                debug_add("Failed to get resource object for  #{$resourceId}, errstr: " . mgd_errstr(), MIDCOM_LOG_ERROR); 
     1222                continue; 
     1223            } 
     1224            $this->_carried_resources_obj[] = $resObj; 
     1225        } 
     1226        $_MIDCOM->auth->drop_sudo(); 
    12001227        // ** Done with resources 
    1201          
     1228 
    12021229        // ** Start with participants         
    12031230        $added_participants = $this->resource_diff($this->participants, $this->old_participants); 
     
    12101237            $resObj->uid = $participantId; 
    12111238            $resObj->eid = $this->id; 
     1239            $resObj->orgOpenpsaObtype = ORG_OPENPSA_OBTYPE_EVENTPARTICIPANT; 
    12121240            $ret['participants']['added'][$resObj->uid] = $resObj->create($this->send_notify, &$this); 
    12131241        } 
    1214          
     1242 
    12151243        foreach ($removed_participants as $participantId => $bool) 
    12161244        { 
    12171245            $resObj = $this->_get_member_by_personid($participantId, 'participant'); 
    1218             if (is_object($resObj)) 
    1219             { 
    1220                 $ret['participants']['removed'][$resObj->uid] = $resObj->delete($this->send_notify, &$this); 
    1221             } 
    1222         } 
    1223          
     1246            if (!is_object($resObj)) 
     1247            { 
     1248                debug_add("Failed to get participant object for person #{$participantId}, errstr: " . mgd_errstr(), MIDCOM_LOG_ERROR); 
     1249                continue; 
     1250            } 
     1251            $ret['participants']['removed'][$resObj->uid] = $resObj->delete($this->send_notify, &$this); 
     1252        } 
     1253 
     1254        // Make sure we can read the carried objects 
     1255        $_MIDCOM->auth->request_sudo(); 
    12241256        foreach ($carried_participants as $participantId => $bool) 
    12251257        { 
    12261258            $partObj = $this->_get_member_by_personid($participantId, 'participant'); 
    1227             if (is_object($partObj)) 
    1228             { 
    1229                 $this->_carried_participants_obj[] = $partObj; 
    1230             } 
    1231         } 
     1259            if (!is_object($partObj)) 
     1260            { 
     1261                debug_add("Failed to get participant object for person #{$participantId}, errstr: " . mgd_errstr(), MIDCOM_LOG_ERROR); 
     1262                continue; 
     1263            } 
     1264            $this->_carried_participants_obj[] = $partObj; 
     1265        } 
     1266        $_MIDCOM->auth->drop_sudo(); 
    12321267        // ** Done with participants 
    12331268        /* 
    12341269        debug_add("added_participants\n===\n" .  sprint_r($added_participants) . "===\n"); 
    12351270        debug_add("removed_participants\n===\n" .  sprint_r($removed_participants) . "===\n"); 
    1236         debug_add("carried_participants\n===\n" .  sprint_r($carried_participants) . "===\n"); 
    12371271        debug_add("this->participants\n===\n" .  sprint_r($this->participants) . "===\n"); 
    12381272        debug_add("this->old_participants\n===\n" .  sprint_r($this->old_participants) . "===\n"); 
     1273        debug_add("carried_participants\n===\n" .  sprint_r($carried_participants) . "===\n"); 
    12391274        debug_add("this->_carried_participants_obj\n===\n" .  sprint_r($this->_carried_participants_obj) . "===\n"); 
    12401275        */ 
    1241          
    1242         debug_add("returning:\n===\n".sprint_r($ret)."===\n"); 
    1243         debug_pop();     
    1244         return $ret;         
     1276 
     1277        debug_add("returning:\n===\n" . sprint_r($ret) . "===\n"); 
     1278        debug_pop(); 
     1279        return $ret; 
    12451280    } 
    12461281 
     
    13321367        return $str; 
    13331368    } 
    1334  
    1335  
    13361369 
    13371370    /** 
  • trunk/src/org.openpsa.calendar/config/manifest.inc

    r4301 r4497  
    66), 
    77'class_definitions' => Array('midcom_dba_classes.inc'), 
    8 'version' => '2.0.9', 
     8'version' => '2.0.10', 
    99'state' => 'stable', 
    1010'package.xml' => Array( 
  • trunk/src/org.openpsa.calendar/documentation/CHANGES

    r4301 r4497  
    66  which might even break existing functionality.  
    77- All items marked with "+" represent completly new features. 
     8 
     92006-10-27 rambo 
     10  - bulletproofing in notifications handling 
     11  + iCal files attached to notifications 
     12  - version bump 
    813 
    9142006-10-05 rambo 
  • trunk/src/org.openpsa.calendar/participant_midcomdba.php

    r4259 r4497  
    6767    function notify($repeat_handler='this', $event=false) 
    6868    { 
     69        debug_push_class(__CLASS__, __FUNCTION__); 
     70        debug_add('This method must be overridden in a subclass', MIDCOM_LOG_ERROR); 
     71        debug_pop(); 
    6972        return false; 
    7073    } 
     
    128131    } 
    129132 
     133    function _on_loaded() 
     134    { 
     135        // Make sure we have correct class 
     136        switch($this->orgOpenpsaObtype) 
     137        { 
     138            case ORG_OPENPSA_OBTYPE_EVENTRESOURCE: 
     139                $this = new org_openpsa_calendar_eventresource($this->id); 
     140                break; 
     141            default: 
     142            case ORG_OPENPSA_OBTYPE_EVENTPARTICIPANT: 
     143                $this = new org_openpsa_calendar_eventparticipant($this->id); 
     144                break; 
     145        } 
     146        return true; 
     147    } 
    130148} 
    131149 
     
    157175    var $participant; 
    158176     
    159     function org_openpsa_calendar_eventparticipant($identifier=NULL) { 
     177    function org_openpsa_calendar_eventparticipant($identifier=NULL) 
     178    { 
    160179        if (parent::_constructor($identifier)) 
    161180        { 
     
    171190        return false; 
    172191    } 
    173      
    174          
     192 
     193    function _on_loaded() 
     194    { 
     195        return true; 
     196    } 
     197 
    175198    //TODO: Rewrite 
    176     function notify($type = 'update', $event = false, $nl = "\n") { 
     199    function notify($type = 'update', $event = false, $nl = "\n") 
     200    { 
    177201        debug_push_class(__CLASS__, __FUNCTION__); 
     202        debug_add("called with options: '{$type}', '{$event}', '{$nl}'"); 
    178203        $l10n =& $_MIDCOM->i18n->get_l10n('org.openpsa.calendar'); 
    179204        $recipient =& $this->get_person_obj(); 
     
    195220        { 
    196221            //Do not send notification to current user 
    197             debug_add('event->send_notify_me is false and recipient is current user, aborting'); 
     222            debug_add('event->send_notify_me is false and recipient is current user, aborting notify'); 
    198223            debug_pop(); 
    199224            return false; 
     
    232257                $message['content'] = sprintf($l10n->get('event "%s" (%s) was cancelled.'), $event->title, $event->format_timeframe()); 
    233258            break; 
    234         } 
    235          
    236         //TODO: attach vcal when we have working dumps 
    237  
     259            default: 
     260                debug_add("action '{$type}' is invalid, aborting notification", MIDCOM_LOG_ERROR); 
     261                debug_pop(); 
     262                return false; 
     263        } 
     264         
     265        if (   $type == 'cancel' 
     266            || $type == 'remove') 
     267        { 
     268            // TODO: Create iCal export with correct delete commands 
     269        } 
     270        else 
     271        { 
     272            $vcal_data = $event->vcal_headers(); 
     273            $vcal_data .= $event->vcal_export();  
     274            $vcal_data .= $event->vcal_footers(); 
     275            $message['attachments'] = array 
     276            ( 
     277                array 
     278                ( 
     279                    'name' => midcom_generate_urlname_from_string(sprintf('%s on %s', $event->title, date('Ymd_Hi', $event->start))) . '.ics', 
     280                    'mimetype' => 'text/calendar', 
     281                    'content' => $vcal_data, 
     282                ), 
     283            ); 
     284        } 
     285 
     286        debug_pop(); 
    238287        return org_openpsa_notifications::notify($action, $recipient->guid, $message); 
    239288    } 
     
    245294 * Wrapper class for eventmembers as resources to an event. 
    246295 */ 
    247 class org_openpsa_calendar_eventresource extends org_openpsa_calendar_eventmember { 
     296class org_openpsa_calendar_eventresource extends org_openpsa_calendar_eventmember 
     297
    248298    //More meaningfull aliases for some fields 
    249299    var $resource; 
     
    251301    var $notes; 
    252302       
    253     function org_openpsa_calendar_eventresource($identifier=NULL) { 
     303    function org_openpsa_calendar_eventresource($identifier=NULL) 
     304    { 
    254305        if (parent::_constructor($identifier)) 
    255306        { 
     
    266317    } 
    267318 
     319    function _on_loaded() 
     320    { 
     321        return true; 
     322    } 
     323 
    268324    function update($notify=true, $event=false) 
    269325    {