public function testsave() { error_reporting(E_ERROR | E_PARSE); $aopCaseUpdates = new AOP_Case_Updates(); $aopCaseUpdates->name = 'test name'; $aopCaseUpdates->description = 'test description'; $aopCaseUpdates->case_id = 'test case id'; $aopCaseUpdates->contact_id = 'test id'; $aopCaseUpdates->internal = 1; $aopCaseUpdates->save(); //test for record ID to verify that record is saved $this->assertEquals(36, strlen($aopCaseUpdates->id)); //mark the record as deleted for cleanup $aopCaseUpdates->mark_deleted($aopCaseUpdates->id); }
/** * 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); }
/** * 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(); }