public function testgetUpdateUser()
 {
     $aopCaseUpdates = new AOP_Case_Updates();
     //execute the method and verify that it returns an instance of User
     $result = $aopCaseUpdates->getUpdateUser();
     $this->assertInstanceOf('User', $result);
 }
 public function sendCaseUpdate(AOP_Case_Updates $caseUpdate)
 {
     global $current_user, $sugar_config;
     $email_template = new EmailTemplate();
     if ($_REQUEST['module'] == 'Import') {
         //Don't send email on import
         return;
     }
     if (!isAOPEnabled()) {
         return;
     }
     if ($caseUpdate->internal) {
         return;
     }
     $signature = array();
     $addDelimiter = true;
     $aop_config = $sugar_config['aop'];
     if ($caseUpdate->assigned_user_id) {
         if ($aop_config['contact_email_template_id']) {
             $email_template = $email_template->retrieve($aop_config['contact_email_template_id']);
             $signature = $current_user->getDefaultSignature();
         }
         if ($email_template) {
             foreach ($caseUpdate->getContacts() as $contact) {
                 $GLOBALS['log']->info("AOPCaseUpdates: Calling send email");
                 $emails = array();
                 $emails[] = $contact->emailAddress->getPrimaryAddress($contact);
                 $res = $caseUpdate->sendEmail($emails, $email_template, $signature, $caseUpdate->case_id, $addDelimiter, $contact->id);
             }
         }
     } else {
         $emails = $caseUpdate->getEmailForUser();
         if ($aop_config['user_email_template_id']) {
             $email_template = $email_template->retrieve($aop_config['user_email_template_id']);
         }
         $addDelimiter = false;
         if ($emails && $email_template) {
             $GLOBALS['log']->info("AOPCaseUpdates: Calling send email");
             $res = $caseUpdate->sendEmail($emails, $email_template, $signature, $caseUpdate->case_id, $addDelimiter, $caseUpdate->contact_id);
         }
     }
 }
Beispiel #3
0
 /**
  * Called when saving a new email and adds the case update to the case.
  * @param $bean
  * @param $event
  * @param $arguments
  */
 public function saveEmailUpdate($bean, $event, $arguments)
 {
     global $mod_strings;
     if ($bean->intent != "createcase" || $bean->parent_type != "Cases") {
         $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate: Not a create case or wrong parent type");
         return;
     }
     if (!$bean->parent_id) {
         $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate No parent id");
         return;
     }
     if ($bean->cases) {
         $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate cases already set");
         return;
     }
     if ($bean->fetched_row['parent_id']) {
         //Will have been processed already
         return;
     }
     $contact = BeanFactory::getBean("Contact");
     $ea = new SugarEmailAddress();
     $beans = $ea->getBeansByEmailAddress($bean->from_addr);
     $contact_id = null;
     foreach ($beans as $emailBean) {
         if ($emailBean->module_name == "Contacts") {
             $contact_id = $emailBean->id;
             $this->linkAccountAndCase($bean->parent_id, $emailBean->account_id);
         }
     }
     $case_update = new AOP_Case_Updates();
     $case_update->name = $bean->name;
     $case_update->contact_id = $contact_id;
     $updateText = $this->unquoteEmail($bean->description_html ? $bean->description_html : $bean->description);
     $case_update->description = $updateText;
     $case_update->internal = false;
     $case_update->case_id = $bean->parent_id;
     $case_update->save();
 }
Beispiel #4
0
 /**
  * Called when saving a new email and adds the case update to the case.
  * @param $bean
  * @param $event
  * @param $arguments
  */
 public function saveEmailUpdate($bean, $event, $arguments)
 {
     global $mod_strings;
     if ($bean->intent != "createcase" || $bean->parent_type != "Cases") {
         $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate: Not a create case or wrong parent type");
         return;
     }
     if (!isAOPEnabled()) {
         return;
     }
     if (!$bean->parent_id) {
         $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate No parent id");
         return;
     }
     if ($bean->cases) {
         $GLOBALS['log']->warn("CaseUpdatesHook: saveEmailUpdate cases already set");
         return;
     }
     if ($bean->fetched_row['parent_id']) {
         //Will have been processed already
         return;
     }
     $contact = BeanFactory::getBean("Contact");
     $ea = new SugarEmailAddress();
     $beans = $ea->getBeansByEmailAddress($bean->from_addr);
     $contact_id = null;
     foreach ($beans as $emailBean) {
         if ($emailBean->module_name == "Contacts" && !empty($emailBean->id)) {
             $contact_id = $emailBean->id;
             $this->linkAccountAndCase($bean->parent_id, $emailBean->account_id);
         }
     }
     $case_update = new AOP_Case_Updates();
     $case_update->name = $bean->name;
     $case_update->contact_id = $contact_id;
     $updateText = $this->unquoteEmail($bean->description_html ? $bean->description_html : $bean->description);
     $case_update->description = $updateText;
     $case_update->internal = false;
     $case_update->case_id = $bean->parent_id;
     $case_update->save();
     $notes = $bean->get_linked_beans('notes', 'Notes');
     foreach ($notes as $note) {
         //Link notes to case update also
         $newNote = BeanFactory::newBean('Notes');
         $newNote->name = $note->name;
         $newNote->file_mime_type = $note->file_mime_type;
         $newNote->filename = $note->filename;
         $newNote->parent_type = 'AOP_Case_Updates';
         $newNote->parent_id = $case_update->id;
         $newNote->save();
         $srcFile = "upload://{$note->id}";
         $destFile = "upload://{$newNote->id}";
         copy($srcFile, $destFile);
     }
     $this->updateCaseStatus($case_update->case_id);
 }