public function testGetCaseIdFromCaseNumber() { $this->case->save(); $id = $this->case->id; $this->case->disable_row_level_security = true; $this->case->retrieve($id); $number = $this->case->case_number; $ie = new InboundEmail(); $subject = '[CASE:' . $number . ']'; $actual_id = $ie->getCaseIdFromCaseNumber($subject, $this->case); $this->assertEquals($id, $actual_id); }
/** * Create test user * */ public function setUp() { $this->markTestIncomplete('Skipping for now while investigating'); //setup test portal user $this->_setupTestUser(); $this->_soapClient = new nusoapclient($GLOBALS['sugar_config']['site_url'] . '/soap.php', false, false, false, false, false, 600, 600); $this->_login(); //setup test account $account = new Account(); $account->name = 'test account for bug 39855'; $account->assigned_user_id = 'SugarUser'; $account->save(); $this->_acc = $account; //setup test cases $case1 = new aCase(); $case1->name = 'test case for bug 39855 ASDF'; $case1->account_id = $this->_acc->id; $case1->status = 'New'; $case1->save(); $this->_case1 = $case1; $case2 = new aCase(); //$account->id = 'a_'.$unid; $case2->name = 'test case for bug 39855 QWER'; $case2->account_id = $this->_acc->id; $case2->status = 'Rejected'; $case2->save(); $this->_case2 = $case2; }
public function testGetRelatedBean() { $team_id = 1; $case = new aCase(); $case->name = 'testBug47949'; $case->team_id = $team_id; $case->team_set_id = 1; $case->save(); $beans = $case->get_linked_beans('teams', 'Team'); // teams is based on Link (not Link2), should still work $this->assertEquals(1, count($beans), 'should have one and only one team'); $this->assertEquals($team_id, $beans[0]->id, 'incorrect team id, should be ' . $team_id); // cleanup $GLOBALS['db']->query("delete from cases where id= '{$case->id}'"); }
function handleCreateCase($email, $userId) { global $current_user, $mod_strings, $current_language; $mod_strings = return_module_language($current_language, "Emails"); $GLOBALS['log']->debug('In handleCreateCase'); $c = new aCase(); $this->getCaseIdFromCaseNumber($email->name, $c); if (!$this->handleCaseAssignment($email) && $this->isMailBoxTypeCreateCase()) { // create a case $GLOBALS['log']->debug('retrieveing email'); $email->retrieve($email->id); $c = new aCase(); $c->description = $email->description; $c->assigned_user_id = $userId; $c->name = $email->name; $c->status = 'New'; $c->priority = 'P1'; if (!empty($email->reply_to_email)) { $contactAddr = $email->reply_to_email; } else { $contactAddr = $email->from_addr; } $GLOBALS['log']->debug('finding related accounts with address ' . $contactAddr); if ($accountIds = $this->getRelatedId($contactAddr, 'accounts')) { if (sizeof($accountIds) == 1) { $c->account_id = $accountIds[0]; $acct = new Account(); $acct->retrieve($c->account_id); $c->account_name = $acct->name; } // if } // if $c->save(true); $caseId = $c->id; $c = new aCase(); $c->retrieve($caseId); if ($c->load_relationship('emails')) { $c->emails->add($email->id); } // if if ($contactIds = $this->getRelatedId($contactAddr, 'contacts')) { if (!empty($contactIds) && $c->load_relationship('contacts')) { $c->contacts->add($contactIds); } // if } // if $c->email_id = $email->id; $email->parent_type = "Cases"; $email->parent_id = $caseId; // assign the email to the case owner $email->assigned_user_id = $c->assigned_user_id; $email->name = str_replace('%1', $c->case_number, $c->getEmailSubjectMacro()) . " " . $email->name; $email->save(); $GLOBALS['log']->debug('InboundEmail created one case with number: ' . $c->case_number); $createCaseTemplateId = $this->get_stored_options('create_case_email_template', ""); if (!empty($this->stored_options)) { $storedOptions = unserialize(base64_decode($this->stored_options)); } if (!empty($createCaseTemplateId)) { $fromName = ""; $fromAddress = ""; if (!empty($this->stored_options)) { $fromAddress = $storedOptions['from_addr']; $fromName = from_html($storedOptions['from_name']); $replyToName = !empty($storedOptions['reply_to_name']) ? from_html($storedOptions['reply_to_name']) : $fromName; $replyToAddr = !empty($storedOptions['reply_to_addr']) ? $storedOptions['reply_to_addr'] : $fromAddress; } // if $defaults = $current_user->getPreferredEmail(); $fromAddress = !empty($fromAddress) ? $fromAddress : $defaults['email']; $fromName = !empty($fromName) ? $fromName : $defaults['name']; $to[0]['email'] = $contactAddr; // handle to name: address, prefer reply-to if (!empty($email->reply_to_name)) { $to[0]['display'] = $email->reply_to_name; } elseif (!empty($email->from_name)) { $to[0]['display'] = $email->from_name; } $et = new EmailTemplate(); $et->retrieve($createCaseTemplateId); if (empty($et->subject)) { $et->subject = ''; } if (empty($et->body)) { $et->body = ''; } if (empty($et->body_html)) { $et->body_html = ''; } $et->subject = "Re:" . " " . str_replace('%1', $c->case_number, $c->getEmailSubjectMacro() . " " . $c->name); $html = trim($email->description_html); $plain = trim($email->description); $email->email2init(); $email->from_addr = $email->from_addr_name; $email->to_addrs = $email->to_addrs_names; $email->cc_addrs = $email->cc_addrs_names; $email->bcc_addrs = $email->bcc_addrs_names; $email->from_name = $email->from_addr; $email = $email->et->handleReplyType($email, "reply"); $ret = $email->et->displayComposeEmail($email); $ret['description'] = empty($email->description_html) ? str_replace("\n", "\n<BR/>", $email->description) : $email->description_html; $reply = new Email(); $reply->type = 'out'; $reply->to_addrs = $to[0]['email']; $reply->to_addrs_arr = $to; $reply->cc_addrs_arr = array(); $reply->bcc_addrs_arr = array(); $reply->from_name = $fromName; $reply->from_addr = $fromAddress; $reply->reply_to_name = $replyToName; $reply->reply_to_addr = $replyToAddr; $reply->name = $et->subject; $reply->description = $et->body . "<div><hr /></div>" . $email->description; if (!$et->text_only) { $reply->description_html = $et->body_html . "<div><hr /></div>" . $email->description; } $GLOBALS['log']->debug('saving and sending auto-reply email'); //$reply->save(); // don't save the actual email. $reply->send(); } // if } else { if (!empty($email->reply_to_email)) { $contactAddr = $email->reply_to_email; } else { $contactAddr = $email->from_addr; } $this->handleAutoresponse($email, $contactAddr); } }
function create_case($user_name, $password, $name) { if (!validate_user($user_name, $password)) { return 0; } //todo make the activity body not be html encoded $seed_user = new User(); $user_id = $seed_user->retrieve_user_id($user_name); $case = new aCase(); if (!$case->ACLAccess('Save')) { return -1; } $case->assigned_user_id = $user_id; $case->assigned_user_name = $user_name; $case->name = $name; return $case->save(); }
$account->shipping_address_country = $account->billing_address_country; $key = array_rand($app_list_strings['industry_dom']); $account->industry = $app_list_strings['industry_dom'][$key]; $account->account_type = "Customer"; $account->save(); $account_ids[] = $account->id; $accounts[] = $account; // Create a case for the account $case = new aCase(); $case->account_id = $account->id; $case->priority = $casePriority[mt_rand(0, 2)]; $case->status = $caseStatus[mt_rand(0, 4)]; $case->name = $case_seed_names[mt_rand(0, 4)]; $case->assigned_user_id = $account->assigned_user_id; $case->assigned_user_name = $account->assigned_user_name; $case->save(); $note = new Note(); $note->parent_type = 'Accounts'; $note->parent_id = $account->id; $seed_data_index = mt_rand(0, 3); $note->name = $note_seed_names_and_Descriptions[$seed_data_index][0]; $note->description = $note_seed_names_and_Descriptions[$seed_data_index][1]; $note->assigned_user_id = $account->assigned_user_id; $note->assigned_user_name = $account->assigned_user_name; $note->save(); $call = new Call(); $call->parent_type = 'Accounts'; $call->parent_id = $account->id; $call->name = $call_seed_data_names[mt_rand(0, 3)]; $call->assigned_user_id = $account->assigned_user_id; $call->assigned_user_name = $account->assigned_user_name;
public function testSetAutoIncrementStart() { $case = new aCase(); $case->name = "foo"; $case->save(); $case->retrieve($case->id); $lastAuto = $case->case_number; $case->deleted = true; $case->save(); $newAuto = $lastAuto + 5; $this->_helper->setAutoIncrementStart("cases", "case_number", $newAuto); $case2 = new aCase(); $case2->name = "foo2"; $case2->save(); $case2->retrieve($case2->id); $case_number = $case2->case_number; $GLOBALS['db']->query("DELETE FROM cases WHERE id= '{$case->id}'"); $GLOBALS['db']->query("DELETE FROM cases WHERE id= '{$case2->id}'"); $this->assertEquals($newAuto, $case_number); }
function syncticket($session, $data) { $GLOBALS['log']->error("syncticket"); if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', 'Cases', 'write', 'no_access', new SoapError())) { echo "No access"; return; } $admin = new Administration(); $admin->retrieveSettings('system'); $ticket = new SimpleXMLElement(str_replace('!AMP!', '&', $data)); $GLOBALS['log']->error("find or create case"); $case = new aCase(); $nice_id = (int) $ticket->{'nice-id'}; if ($case = $case->retrieve_by_string_fields(array('zendesk_ticket_id_c' => $nice_id))) { $GLOBALS['log']->error("found case " . $case->id); } else { $GLOBALS['log']->error("creating new case"); $case = new aCase(); } $case->zendesk_ticket_id_c = $nice_id; $case->name = $ticket->subject; if ($admin->settings['system_zendesk_status_map']) { $mapped_to = $admin->settings['system_zendesk_status_map']; $mapped_field = 'system_zendesk_status_map_' . $ticket->{'status-id'}; $case->{$mapped_to} = $admin->settings[$mapped_field]; } if ($admin->settings['system_zendesk_priority_map']) { $mapped_to = $admin->settings['system_zendesk_priority_map']; $mapped_field = 'system_zendesk_priority_map_' . $ticket->{'priority-id'}; $case->{$mapped_to} = $admin->settings[$mapped_field]; } if ($admin->settings['system_zendesk_type_map']) { $mapped_to = $admin->settings['system_zendesk_type_map']; $mapped_field = 'system_zendesk_type_map_' . $ticket->{'ticket-type-id'}; $case->{$mapped_to} = $admin->settings[$mapped_field]; } $requester = $ticket->requester; if ($requester->organization) { $account = new Account(); if ($account = $account->retrieve_by_string_fields(array('name' => $requester->organization->name))) { $GLOBALS['log']->error("found account " . $account->id); } else { $account = new Account(); $account->name = $requester->organization->name; $account->save(); $GLOBALS['log']->error("created account " . $account->id); } $case->account_id = $account->id; } $GLOBALS['log']->error("save case with zendesk_ticket_id_c " . $case->zendesk_ticket_id_c); $case->save(); $GLOBALS['log']->error("associate contacts"); if ($case->load_relationship('contacts')) { $ea = new EmailAddress(); $ids = $ea->getRelatedId($requester->email, 'contacts'); if (!empty($ids)) { $case->contacts->add($ids); } else { $contact = new Contact(); $contact->email1 = $requester->email; $names = split(' ', $requester->name); $contact->last_name = $names[count($names) - 1]; $contact->first_name = join(' ', array_slice($names, 0, -1)); $contact->save(); $case->contacts->add(array($contact->id)); } } $GLOBALS['log']->error("syncticket done"); echo "OK " . $case->id; }
public function testsave() { $aCase = new aCase(); $aCase->name = 'test'; $aCase->priority = 'P1'; $aCase->save(); //test for record ID to verify that record is saved $this->assertTrue(isset($aCase->id)); $this->assertEquals(36, strlen($aCase->id)); //mark the record as deleted and verify that this record cannot be retrieved anymore. $aCase->mark_deleted($aCase->id); $result = $aCase->retrieve($aCase->id); $this->assertEquals(null, $result); }