function setCustomerAccountNumberAction() { $db = DevblocksPlatform::getDatabaseService(); @($account_number = DevblocksPlatform::importGPC($_REQUEST['acc_num'], 'string', '')); @($m_id = DevblocksPlatform::importGPC($_REQUEST['m_id'], 'string', '')); // Now Confirm the account exists and is active $account = array_shift(DAO_CustomerAccount::getWhere(sprintf("%s = %d AND %s = '0' ", DAO_CustomerAccount::ACCOUNT_NUMBER, $account_number, DAO_CustomerAccount::IS_DISABLED))); if (!isset($account)) { return; } $message_obj = DAO_Message::get($m_id); if (!isset($message_obj)) { return; } $fields = get_object_vars($message_obj); $fields[DAO_Message::ACCOUNT_ID] = $account->id; $fields[DAO_Message::IMPORT_STATUS] = 0; // Requeue $m_status = DAO_Message::update($m_id, $fields); // Give plugins a chance to note a message is assigned $eventMgr = DevblocksPlatform::getEventService(); $eventMgr->trigger(new Model_DevblocksEvent('message.account.assign', array('account_id' => $account->id, 'message_id' => $m_id))); echo json_encode($fields); }
function _parseFile($full_filename, Model_ImportSource $import_source) { $logger = DevblocksPlatform::getConsoleLog(); $db = DevblocksPlatform::getDatabaseService(); $fail = false; $fail_reason = ""; $fileparts = pathinfo($full_filename); $logger->info("[Parser] Reading " . $fileparts['basename'] . "..."); $fp = fopen($full_filename, "r"); $data = fread($fp, filesize($full_filename)); fclose($fp); // Convert all message to Unix style line ending by stripping any \r $data = str_replace("\r\n", "\n", $data); $data = str_replace("\r", "\n", $data); $message_arr = explode("\n", $data); switch ($import_source->type) { case 0: $first_line = $message_arr[0]; $last_line_count = count($message_arr); do { $last_line = $message_arr[--$last_line_count]; } while ("" == $last_line); if (preg_match('/=====\\w+=====/i', $first_line, $acc_top_id)) { $match = sprintf('/=====%s=====/i', substr($acc_top_id[0], 5, -5)); if (preg_match($match, $last_line, $acc_id)) { $account_name = substr($acc_id[0], 5, -5); $logger->info("[Parser] acc_id = " . $account_name . "..."); } else { $account_name = substr($acc_top_id[0], 5, -5); $logger->info("[Parser] acc_id = " . $account_name . "..."); $fail = true; $fail_reason = "Message Not in the correct format"; $logger->info("[Parser] Message Not in the correct format"); } } else { if (preg_match('/=====\\w+=====/i', $data, $acc_id)) { $account_name = substr($acc_id[0], 5, -5); $logger->info("[Parser] acc_id = " . $account_name . "..."); } $fail = true; $fail_reason = "Message Not in the correct format"; $logger->info("[Parser] Message Not in the correct format"); } break; case 1: if (preg_match('/FMDS\\w+/i', $data, $acc_id)) { $account_name = substr($acc_id[0], 4); $logger->info("[Parser] acc_id = " . $account_name . "..."); } else { $fail = true; $logger->info("[Parser] Not in the correct format"); $fail_reason = "Message Not in the correct format"; } break; case 2: $account_name = substr($fileparts['basename'], 0, -4); $logger->info("[Parser] account_name = " . $account_name . "..."); break; default: break; } // Store the filename and Interperted account Name and source into a Json array incase account doesn't match $json = json_encode(array('is_fail' => $fail, 'fail_reason' => $fail_reason, 'import_source' => $import_source->id, 'account_name' => $account_name, 'file_name' => $fileparts['basename'])); // Now Confirm the account exists and is active if ($fail == false) { $account = array_shift(DAO_CustomerAccount::getWhere(sprintf("%s = %d AND %s = %d AND %s = '0'", DAO_CustomerAccount::ACCOUNT_NUMBER, $account_name, DAO_CustomerAccount::IMPORT_SOURCE, $import_source->id, DAO_CustomerAccount::IS_DISABLED))); if (isset($account)) { $account_id = $account->id; } else { $account_id = 0; } } else { $account_id = 0; } if ($this->_createMessage($account_id, $db->qstr($data), $json, $fail)) { @unlink($full_filename); } else { $logger->error("[Parser] Failed to create message " . $account_name . "..."); // Move to failed } }