Esempio n. 1
0
 /**
  * method to execute the query
  * it's called automatically by the api main controller
  */
 public function execute()
 {
     Billrun_Factory::log()->log("Execute api query billrun", Zend_Log::INFO);
     $request = $this->getRequest()->getRequest();
     // supports GET / POST requests
     Billrun_Factory::log()->log("Input: " . print_R($request, 1), Zend_Log::INFO);
     if (!isset($request['aid'])) {
         $this->setError('Require to supply aid or sid', $request);
         return true;
     }
     $find = array();
     $max_list = 1000;
     if (isset($request['aid'])) {
         $aids = Billrun_Util::verify_array($request['aid'], 'int');
         if (count($aids) > $max_list) {
             $this->setError('Maximum of aid is ' . $max_list, $request);
             return true;
         }
         $find['aid'] = array('$in' => $aids);
     }
     if (isset($request['billrun'])) {
         $find['billrun_key'] = $this->getBillrunQuery($request['billrun']);
     }
     $options = array('sort' => array('aid', 'billrun_key'));
     $cacheParams = array('fetchParams' => array('options' => $options, 'find' => $find));
     $this->setCacheLifeTime(604800);
     // 1 week
     $results = $this->cache($cacheParams);
     Billrun_Factory::log()->log("query success", Zend_Log::INFO);
     $ret = array(array('status' => 1, 'desc' => 'success', 'input' => $request, 'details' => $results));
     $this->getController()->setOutput($ret);
 }
Esempio n. 2
0
 /**
  * method to send
  * 
  * @param type $message
  * @param type $recipients
  * @return \Billrun_Sms|boolean
  */
 public function send($message, $recipients)
 {
     if (empty($message) || empty($recipients)) {
         Billrun_Factory::log()->log("can not send the sms, there are missing params - txt: " . $this->data['message'] . " recipients: " . print_r($this->data['recipients'], TRUE) . " from: " . $this->data['from'], Zend_Log::WARN);
         return false;
     }
     $unicode_text = $this->sms_unicode($message);
     if (!empty($message) && empty($unicode_text)) {
         $language = '1';
     } else {
         $language = '2';
     }
     // Temporary - make sure is not 23 chars long
     $text = str_pad($message, 24, '+');
     $period = 120;
     foreach ($recipients as $recipient) {
         $send_params = array('message' => $text, 'to' => $recipient, 'from' => $this->data['from'], 'language' => $language, 'username' => $this->data['user'], 'password' => $this->data['pwd'], 'acknowledge' => "false", 'period' => $period, 'channel' => "SRV");
         $url = $this->data['provisioning'] . "?" . http_build_query($send_params);
         $sms_result = Billrun_Util::sendRequest($url);
         $exploded = explode(',', $sms_result);
         $response = array('error-code' => empty($exploded[0]) ? 'error' : 'success', 'cause-code' => $exploded[1], 'error-description' => $exploded[2], 'tid' => $exploded[3]);
         Billrun_Factory::log()->log("phone: " . $recipient . " encoded_text: " . $message . " url: " . $url . " result" . print_R($response, 1), Zend_Log::INFO);
     }
     return $response['error-code'] == 'success' ? true : false;
 }
Esempio n. 3
0
 public function execute()
 {
     Billrun_Factory::log()->log("Execute reset", Zend_Log::INFO);
     $request = $this->getRequest()->getRequest();
     // supports GET / POST requests
     if (empty($request['sid'])) {
         return $this->setError('Please supply at least one sid', $request);
     }
     // remove the aids from current balance cache - on next current balance it will be recalculated and avoid to take it from cache
     if (isset($request['aid'])) {
         $this->cleanAccountCache($request['aid']);
     }
     $billrun_key = Billrun_Util::getBillrunKey(time());
     // Warning: will convert half numeric strings / floats to integers
     $sids = array_unique(array_diff(Billrun_Util::verify_array($request['sid'], 'int'), array(0)));
     if ($sids) {
         try {
             $rebalance_queue = Billrun_Factory::db()->rebalance_queueCollection();
             foreach ($sids as $sid) {
                 $rebalance_queue->insert(array('sid' => $sid, 'billrun_key' => $billrun_key, 'creation_date' => new MongoDate()));
             }
         } catch (Exception $exc) {
             Billrun_Util::logFailedResetLines($sids, $billrun_key);
             return FALSE;
         }
     } else {
         return $this->setError('Illegal sid', $request);
     }
     $this->getController()->setOutput(array(array('status' => 1, 'desc' => 'success', 'input' => $request)));
     return TRUE;
 }
Esempio n. 4
0
 /**
  * General function to receive
  *
  * @return array list of files received
  */
 public function receive()
 {
     Billrun_Factory::dispatcher()->trigger('beforeInlineFilesReceive', array($this));
     $type = static::$type;
     if (empty($this->file_content)) {
         Billrun_Factory::log()->log("NOTICE : SKIPPING {$this->filename} !!! It is empty!!!", Zend_Log::NOTICE);
         return FALSE;
     }
     $ret = array();
     Billrun_Factory::log()->log("Billrun_Receiver_Inline::receive - handle file {$this->filename}", Zend_Log::DEBUG);
     $this->lockFileForReceive($this->filename, $type);
     $path = $this->handleFile();
     if (!$path) {
         Billrun_Factory::log()->log("NOTICE : Couldn't write file {$this->filename}.", Zend_Log::NOTICE);
         return FALSE;
     } else {
         $fileData = $this->getFileLogData($this->filename, $type);
         $fileData['path'] = $path;
         if (!empty($this->backupPaths)) {
             $backedTo = $this->backup($fileData['path'], $file->filename, $this->backupPaths, FALSE, FALSE);
             Billrun_Factory::dispatcher()->trigger('beforeReceiverBackup', array($this, &$fileData['path']));
             $fileData['backed_to'] = $backedTo;
             Billrun_Factory::dispatcher()->trigger('afterReceiverBackup', array($this, &$fileData['path']));
         }
         $this->logDB($fileData);
         $ret[] = $fileData['path'];
     }
     Billrun_Factory::dispatcher()->trigger('afterInlineFilesReceive', array($this, $ret));
     return $ret;
 }
Esempio n. 5
0
 public function calc()
 {
     Billrun_Factory::log()->log("Execute reset", Zend_Log::INFO);
     $rebalance_queue = Billrun_Factory::db()->rebalance_queueCollection();
     $limit = Billrun_Config::getInstance()->getConfigValue('resetlines.limit', 10);
     $offset = Billrun_Config::getInstance()->getConfigValue('resetlines.offset', '1 hour');
     $query = array('creation_date' => array('$lt' => new MongoDate(strtotime($offset . ' ago'))));
     $sort = array('creation_date' => 1);
     $results = $rebalance_queue->find($query)->sort($sort)->limit($limit);
     $billruns = array();
     $all_sids = array();
     foreach ($results as $result) {
         $billruns[$result['billrun_key']][] = $result['sid'];
         $all_sids[] = $result['sid'];
     }
     foreach ($billruns as $billrun_key => $sids) {
         $model = new ResetLinesModel($sids, $billrun_key);
         try {
             $ret = $model->reset();
             if (isset($ret['err']) && !is_null($ret['err'])) {
                 return FALSE;
             }
             $rebalance_queue->remove(array('sid' => array('$in' => $sids)));
         } catch (Exception $exc) {
             Billrun_Factory::log()->log('Error resetting sids ' . implode(',', $sids) . ' of billrun ' . $billrun_key . '. Error was ' . $exc->getTraceAsString(), Zend_Log::ALERT);
             return $this->setError($exc->getTraceAsString(), array('sids' => $sids, 'billrun_key' => $billrun_key));
         }
     }
     Billrun_Factory::log()->log("Success resetting sids " . implode(',', $all_sids), Zend_Log::INFO);
     return true;
 }
 /**
  * Check the  received files sequence.
  * @param type $receiver
  * @param type $filepaths
  * @param type $hostname
  * @return type
  * @throws Exception
  */
 protected function checkFilesSeq($filepaths, $hostname)
 {
     if (!isset($this->hostSequenceCheckers[$hostname])) {
         throw new Exception('Couldn`t find hostname in sequence checker might be a problem with the program flow.');
     }
     $mailMsg = FALSE;
     if ($filepaths) {
         foreach ($filepaths as $path) {
             $ret = $this->hostSequenceCheckers[$hostname]->addFileToSequence(basename($path));
             if ($ret) {
                 $mailMsg .= $ret . "\n";
             }
         }
         $ret = $this->hostSequenceCheckers[$hostname]->hasSequenceMissing();
         if ($ret) {
             $mailMsg .= $this->getName() . " Reciever : Received a file out of sequence from host : {$hostname} - for the following files : \n";
             foreach ($ret as $file) {
                 $mailMsg .= $file . "\n";
             }
         }
     } else {
         if ($this->hostSequenceCheckers[$hostname]->lastLogFile) {
             $timediff = time() - strtotime($this->hostSequenceCheckers[$hostname]->lastLogFile['received_time']);
             if ($timediff > Billrun_Factory::config()->getConfigValue($this->getName() . '.receiver.max_missing_file_wait', 3600)) {
                 $mailMsg = 'Didn`t received any new ' . $this->getName() . ' files form host ' . $hostname . ' for more then ' . $timediff . ' Seconds';
             }
         }
     }
     //If there were any errors log them as high issues
     if ($mailMsg) {
         Billrun_Factory::log()->log($mailMsg, Zend_Log::ALERT);
     }
 }
Esempio n. 7
0
 /**
  * method to execute remove of billing lines (only credit and active)
  * it's called automatically by the api main controller
  */
 public function execute()
 {
     Billrun_Factory::log()->log("Execute api remove", Zend_Log::INFO);
     $request = $this->getRequest()->getRequest();
     // supports GET / POST requests
     Billrun_Factory::log()->log("Input: " . print_R($request, 1), Zend_Log::INFO);
     $stamps = array();
     foreach ($request['stamps'] as $line_stamp) {
         $clear_stamp = Billrun_Util::filter_var($line_stamp, FILTER_SANITIZE_STRING, FILTER_FLAG_ALLOW_HEX);
         if (!empty($clear_stamp)) {
             $stamps[] = $clear_stamp;
         }
     }
     if (empty($stamps)) {
         Billrun_Factory::log()->log("remove action failed; no correct stamps", Zend_Log::INFO);
         $this->getController()->setOutput(array(array('status' => false, 'desc' => 'failed - invalid stamps input', 'input' => $request)));
         return true;
     }
     $model = new LinesModel();
     $query = array('source' => 'api', 'stamp' => array('$in' => $stamps), '$or' => array(array('billrun' => array('$gte' => Billrun_Billrun::getActiveBillrun())), array('billrun' => array('$exists' => false))));
     $ret = $model->remove($query);
     if (!isset($ret['ok']) || !$ret['ok'] || !isset($ret['n'])) {
         Billrun_Factory::log()->log("remove action failed pr miscomplete", Zend_Log::INFO);
         $this->getController()->setOutput(array(array('status' => false, 'desc' => 'remove failed', 'input' => $request)));
         return true;
     }
     Billrun_Factory::log()->log("remove success", Zend_Log::INFO);
     $this->getController()->setOutput(array(array('status' => $ret['n'], 'desc' => 'success', 'input' => $request)));
 }
Esempio n. 8
0
 /**
  * method that outputs account, subscribers and usage of requested accounts and requested date usage
  * it's called automatically by the api main controller
  */
 public function execute()
 {
     Billrun_Factory::log()->log("Execute data triggers", Zend_Log::INFO);
     $request = $this->getRequest()->getRequest();
     // supports GET / POST requests
     $params = array('plan', 'data_usage', 'from_account_id', 'to_account_id', 'billrun');
     foreach ($params as $param) {
         if (!isset($request[$param])) {
             $msg = 'Missing required parameter: ' . $param;
             Billrun_Factory::log()->log($msg, Zend_Log::ERR);
             $this->getController()->setOutput(array(array('status' => 0, 'desc' => 'failed', 'output' => $msg)));
             return;
         }
     }
     Billrun_Factory::log()->log("Request params Received: plan-" . $request['plan'] . ", data_usage-" . $request['data_usage'] . ", from_account_id-" . $request['from_account_id'] . ", to_account_id-" . $request['to_account_id'] . ", billrun-" . $request['billrun'], Zend_Log::INFO);
     $balances = new BalancesModel(array('size' => Billrun_Factory::config()->getConfigValue('balances.accounts.limit', 50000)));
     $results = $balances->getBalancesVolume($request['plan'], $request['data_usage'], $request['from_account_id'], $request['to_account_id'], $request['billrun']);
     if (empty($results)) {
         Billrun_Factory::log()->log('Some error happen, no result, received parameters: ' . print_r($request, true), Zend_Log::ERR);
         return;
     }
     $counter = 0;
     $accounts = array();
     foreach ($results as $result) {
         $accounts['aid'][$result['aid']]['subs'][$result['sid']] = Billrun_Util::byteFormat($result['balance']['totals']['data']['usagev'], 'MB', 2, false, '.', '');
         $counter++;
     }
     $this->getController()->setOutput(array(array('status' => 1, 'desc' => 'success', 'subscribers_count' => $counter, 'output' => $accounts)));
     return true;
 }
Esempio n. 9
0
 /**
  * load the container the need to be generate
  */
 public function load()
 {
     $this->data = $this->collection->aggregate($this->aggregation_array);
     //TODO how to perform it on the secondaries?
     Billrun_Factory::log()->log("generator entities loaded: " . count($this->data), Zend_Log::INFO);
     Billrun_Factory::dispatcher()->trigger('afterGeneratorLoadData', array('generator' => $this));
 }
Esempio n. 10
0
 /**
  * General function to receive
  *
  * @return array list of files received
  */
 public function receive()
 {
     Billrun_Factory::dispatcher()->trigger('beforeLocalFilesReceive', array($this));
     $type = static::$type;
     if (!file_exists($this->srcPath)) {
         Billrun_Factory::log()->log("NOTICE : SKIPPING {$type} !!! directory " . $this->srcPath . " not found!!", Zend_Log::NOTICE);
         return array();
     }
     $files = $this->getFiles($this->srcPath, $this->sort, $this->order);
     $ret = array();
     $receivedCount = 0;
     foreach ($files as $file) {
         $path = $this->srcPath . DIRECTORY_SEPARATOR . $file;
         if (!$this->isFileValid($file, $path) || $this->isFileReceived($file, $type) || is_dir($path)) {
             Billrun_Factory::log('File ' . $file . ' is not valid or received already', Zend_Log::INFO);
             continue;
         }
         Billrun_Factory::log()->log("Billrun_Receiver_Base_LocalFiles::receive - handle file {$file}", Zend_Log::DEBUG);
         $path = $this->handleFile($path, $file);
         if (!$path) {
             Billrun_Factory::log()->log("NOTICE : Couldn't relocate file from  {$path}.", Zend_Log::NOTICE);
             continue;
         }
         if ($this->logDB($path) !== FALSE) {
             $ret[] = $path;
             if (++$receivedCount >= $this->limit) {
                 break;
             }
         }
     }
     Billrun_Factory::dispatcher()->trigger('afterLocalFilesReceived', array($this, $ret));
     return $ret;
 }
Esempio n. 11
0
 /**
  * @see Billrun_Processor::parse()
  */
 protected function parse()
 {
     if (!is_resource($this->fileHandler)) {
         Billrun_Factory::log()->log('Resource is not configured well', Zend_Log::ERR);
         return FALSE;
     }
     return Billrun_Factory::chain()->trigger('processData', array($this->getType(), $this->fileHandler, &$this));
 }
Esempio n. 12
0
 /**
  * @see Billrun_Processor::parse()
  */
 protected function parse()
 {
     if (!is_resource($this->fileHandler)) {
         Billrun_Factory::log()->log('Resource is not configured well', Zend_Log::ERR);
         return FALSE;
     }
     $this->data['data'] = json_decode(stream_get_contents($this->fileHandler), true);
     return $this->processData();
 }
Esempio n. 13
0
 protected function respondAFile($responseFilePath, $fileName, $logLine)
 {
     Billrun_Factory::log()->log("Responding on : {$fileName}", Zend_Log::DEBUG);
     $data = $logLine->getRawData();
     $data['response_time'] = time();
     $logLine->setRawData($data);
     $logLine->save();
     return $responseFilePath;
 }
Esempio n. 14
0
 protected function insertToQueue($entity)
 {
     $queue = Billrun_Factory::db()->queueCollection();
     if (!is_object($queue)) {
         Billrun_Factory::log()->log('Queue collection is not defined', Zend_Log::ALERT);
         return false;
     } else {
         return $queue->insert(array('stamp' => $entity['stamp'], 'type' => $entity['type'], 'urt' => $entity['urt'], 'calc_name' => false, 'calc_time' => false), array('w' => 1));
     }
 }
Esempio n. 15
0
 /**
  * method to execute the query
  * it's called automatically by the api main controller
  */
 public function execute()
 {
     Billrun_Factory::log()->log("Execute api query aggregate", Zend_Log::INFO);
     $request = $this->getRequest()->getRequest();
     // supports GET / POST requests
     Billrun_Factory::log()->log("Input: " . print_R($request, 1), Zend_Log::DEBUG);
     if (!isset($request['aid']) && !isset($request['sid'])) {
         $this->setError('Require to supply aid or sid', $request);
         return true;
     }
     $find = array();
     $max_list = 1000;
     if (isset($request['aid'])) {
         $aids = Billrun_Util::verify_array($request['aid'], 'int');
         if (count($aids) > $max_list) {
             $this->setError('Maximum of aid is ' . $max_list, $request);
             return true;
         }
         $find['aid'] = array('$in' => $aids);
     }
     if (isset($request['sid'])) {
         $sids = Billrun_Util::verify_array($request['sid'], 'int');
         if (count($sids) > $max_list) {
             $this->setError('Maximum of sid is ' . $max_list, $request);
             return true;
         }
         $find['sid'] = array('$in' => $sids);
     }
     if (isset($request['billrun'])) {
         $find['billrun'] = $this->getBillrunQuery($request['billrun']);
     }
     if (isset($request['query'])) {
         $query = $this->getArrayParam($request['query']);
         $find = array_merge($find, (array) $query);
     }
     if (isset($request['groupby'])) {
         $groupby = array('_id' => $this->getArrayParam($request['groupby']));
     } else {
         $groupby = array('_id' => null);
     }
     if (isset($request['aggregate'])) {
         $aggregate = $this->getArrayParam($request['aggregate']);
     } else {
         $aggregate = array('count' => array('$sum' => 1));
     }
     $group = array_merge($groupby, $aggregate);
     $options = array('sort' => array('urt'), 'page' => isset($request['page']) && $request['page'] > 0 ? (int) $request['page'] : 0, 'size' => isset($request['size']) && $request['size'] > 0 ? (int) $request['size'] : 1000);
     $cacheParams = array('fetchParams' => array('options' => $options, 'find' => $find, 'group' => $group, 'groupby' => $groupby));
     $this->setCacheLifeTime(604800);
     // 1 week
     $results = $this->cache($cacheParams);
     Billrun_Factory::log()->log("Aggregate query success", Zend_Log::INFO);
     $ret = array(array('status' => 1, 'desc' => 'success', 'input' => $request, 'details' => $results));
     $this->getController()->setOutput($ret);
 }
Esempio n. 16
0
 public function beforeUpdateSubscriberBalance($balance, $row, $rate, $calculator)
 {
     if ($row['type'] == 'tap3') {
         if (isset($row['basicCallInformation']['CallEventStartTimeStamp']['localTimeStamp'])) {
             $this->line_type = $row['type'];
             $this->line_time = $row['basicCallInformation']['CallEventStartTimeStamp']['localTimeStamp'];
         } else {
             Billrun_Factory::log()->log('localTimeStamp wasn\'t found for line ' . $row['stamp'] . '.', Zend_Log::ALERT);
         }
     }
 }
Esempio n. 17
0
 /**
  * @see Billrun_Calculator_Rate::getLineRate
  */
 protected function getLineRate($row, $usage_type)
 {
     $line_time = $row['urt'];
     foreach ($this->rates as $rate) {
         if (preg_match($rate['params']['sgsn_addresses'], $row['sgsn_address']) && $rate['from'] <= $line_time && $line_time <= $rate['to']) {
             return $rate;
         }
     }
     Billrun_Factory::log()->log("Couldn't find rate for row : " . print_r($row['stamp'], 1), Zend_Log::DEBUG);
     return FALSE;
 }
Esempio n. 18
0
 /**
  * load the data to run the calculator for
  * 
  * @param boolean $initData reset the data in the calculator before loading
  * 
  */
 public function load($initData = true)
 {
     if ($initData) {
         $this->data = array();
     }
     $resource = $this->getLines();
     foreach ($resource as $entity) {
         $this->data[] = $entity;
     }
     Billrun_Factory::log()->log("entities loaded: " . count($this->data), Zend_Log::INFO);
     Billrun_Factory::dispatcher()->trigger('afterCalculatorLoadData', array('calculator' => $this));
 }
Esempio n. 19
0
 /**
  * @see Billrun_Processor::parse()
  */
 protected function parse()
 {
     if (!is_resource($this->fileHandler)) {
         Billrun_Factory::log()->log('Resource is not configured well', Zend_Log::ERR);
         return FALSE;
     }
     try {
         return Billrun_Factory::chain()->trigger('processData', array($this->getType(), $this->fileHandler, &$this));
     } catch (Exception $e) {
         Billrun_Factory::log("Got exception :" . $e->getMessage() . " while processing file {$this->filePath}", Zend_Log::ERR);
         return FALSE;
     }
 }
Esempio n. 20
0
 public function afterCalculatorUpdateRow($row, $calculator)
 {
     if ($calculator->getCalculatorQueueType() == 'rate' && $row['type'] == 'nsn' && in_array($row['record_type'], $this->record_types) && isset($row[$this->ild_prefix_field_name])) {
         $result = $this->createRow($row);
         if (!empty($result)) {
             if (!$this->createTreatedFile($result)) {
                 Billrun_Factory::log()->log('Failed inserting 016 one way line with stamp: ' . $row['stamp'] . ' , time: ' . time(), Zend_Log::ERR);
             } else {
                 Billrun_Factory::log()->log('line stamp: ' . $row['stamp'] . ' file: ' . $row['file'] . ' was inserted to 016 one way process', Zend_Log::INFO);
             }
         }
     }
 }
Esempio n. 21
0
 public function parse()
 {
     $keyedRecord = $this->buildKeyedRecord($this->line);
     $retRecord = array();
     foreach ($keyedRecord as $key => $value) {
         if (isset($this->structure[$key])) {
             $retRecord[$this->structure[$key]] = $value;
         } else {
             Billrun_Factory::log()->log("couldn't find {$key} in configuration", Zend_Log::DEBUG);
         }
     }
     $retRecord['stamp'] = md5(serialize($retRecord));
     return $retRecord;
 }
Esempio n. 22
0
 public function execute()
 {
     Billrun_Factory::log()->log("Execute plans api call", Zend_Log::INFO);
     $request = $this->getRequest();
     $requestedQuery = $request->get('query', array());
     $query = $this->processQuery($requestedQuery);
     $strip = $this->getCompundParam($request->get('strip', false), false);
     $filter = !empty($strip) ? $strip : array('name');
     $cacheParams = array('fetchParams' => array('query' => $query, 'filter' => $filter, 'strip' => $strip), 'stampParams' => array($requestedQuery, $filter, $strip));
     $this->setCacheLifeTime(86400);
     // 1 day
     $results = $this->cache($cacheParams);
     $this->getController()->setOutput(array(array('status' => 1, 'desc' => 'success', 'details' => $results, 'input' => $request->getRequest())));
 }
Esempio n. 23
0
 /**
  * method to execute the query
  * it's called automatically by the api main controller
  */
 public function execute()
 {
     Billrun_Factory::log()->log("Execute api query", Zend_Log::INFO);
     $request = $this->getRequest()->getRequest();
     // supports GET / POST requests
     Billrun_Factory::log()->log("Input: " . print_R($request, 1), Zend_Log::INFO);
     if (!isset($request['aid']) && !isset($request['sid'])) {
         $this->setError('Require to supply aid or sid', $request);
         return true;
     }
     $find = array();
     $max_list = 1000;
     if (isset($request['aid'])) {
         $aids = Billrun_Util::verify_array($request['aid'], 'int');
         if (count($aids) > $max_list) {
             $this->setError('Maximum of aid is ' . $max_list, $request);
             return true;
         }
         $find['aid'] = array('$in' => $aids);
     }
     if (isset($request['sid'])) {
         $sids = Billrun_Util::verify_array($request['sid'], 'int');
         if (count($sids) > $max_list) {
             $this->setError('Maximum of sid is ' . $max_list, $request);
             return true;
         }
         $find['sid'] = array('$in' => $sids);
     }
     if (isset($request['billrun'])) {
         $find['billrun'] = $this->getBillrunQuery($request['billrun']);
     }
     if (isset($request['query'])) {
         $query = $this->getArrayParam($request['query']);
         $find = array_merge($find, (array) $query);
     }
     $options = array('sort' => array('urt'), 'page' => isset($request['page']) && $request['page'] > 0 ? (int) $request['page'] : 0, 'size' => isset($request['size']) && $request['size'] > 0 ? (int) $request['size'] : 1000);
     $model = new LinesModel($options);
     if (isset($request['distinct'])) {
         $lines = $model->getDistinctField((string) $request['distinct'], $find);
     } else {
         $lines = $model->getData($find);
         foreach ($lines as &$line) {
             $line = $line->getRawData();
         }
     }
     Billrun_Factory::log()->log("query success", Zend_Log::INFO);
     $ret = array(array('status' => 1, 'desc' => 'success', 'input' => $request, 'details' => $lines));
     $this->getController()->setOutput($ret);
 }
Esempio n. 24
0
 public function loadDbConfig()
 {
     try {
         $configColl = Billrun_Factory::db()->configCollection();
         if ($configColl) {
             $dbConfig = $configColl->query()->cursor()->sort(array('_id' => -1))->limit(1)->current()->getRawData();
             unset($dbConfig['_id']);
             $iniConfig = $this->config->toArray();
             $this->config = new Yaf_Config_Simple(array_merge($iniConfig, $dbConfig));
         }
     } catch (Exception $e) {
         Billrun_Factory::log('Cannot load database config', Zend_Log::CRIT);
         return false;
     }
 }
Esempio n. 25
0
 /**
  * Process an ILD file
  * @param $filePath  Path to the filethat needs processing.
  * @param $type  the type of the ILD.
  */
 private function processType($type)
 {
     $options = array('type' => $type, 'parser' => 'fixed');
     $processor = Billrun_Processor::getInstance($options);
     if ($processor) {
         $processor->process_files();
     } else {
         Billrun_Factory::log()->log("error with loading processor", Zend_log::ERR);
         return false;
     }
     $data = $processor->getData();
     Billrun_Factory::log()->log("Process type: " . $type, Zend_log::INFO);
     //	Billrun_Factory::log()->log("file path: " . $filePath, Zend_log::INFO);
     Billrun_Factory::log()->log(isset($data['data']) ? "import lines: " . count($data['data']) : "no data received", Zend_log::INFO);
 }
Esempio n. 26
0
 protected function respondAFile($responseFilePath, $fileName, $logLine)
 {
     //move file to export folder
     $exportDir = $this->exportFromConfig ? $this->exportDir . DIRECTORY_SEPARATOR . self::$type : $this->exportDir;
     if (!file_exists($exportDir)) {
         mkdir($exportDir);
     }
     $exportPath = $exportDir . DIRECTORY_SEPARATOR . $fileName;
     $result = rename($responseFilePath, $exportPath);
     if (!$result) {
         return FALSE;
     }
     parent::respondAFile($responseFilePath, $fileName, $logLine);
     Billrun_Factory::log()->log("Placed response at : {$exportPath}", Zend_Log::DEBUG);
     return $exportPath;
 }
 /**
  * Check that the received files are in the proper order.
  * @param $filename the recieve filename.
  */
 public function addFileToSequence($filename)
 {
     $msg = FALSE;
     if (!$this->getFileSequenceDataCallable) {
         throw new Exception('getFileSequenceData Function wasn`t set on construction!');
     }
     if (!($sequenceData = call_user_func($this->getFileSequenceDataCallable, $filename))) {
         $msg = "GGSN Reciever : Couldnt parse received file : {$filename} !!!!";
         Billrun_Factory::log()->log($msg, Zend_Log::ALERT);
         return $msg;
     }
     if (!isset($this->sequencers[$sequenceData['date'] . $sequenceData['zone']])) {
         $this->sequencers[$sequenceData['date'] . $sequenceData['zone']] = new Billrun_Common_SequenceChecker();
     }
     $this->sequencers[$sequenceData['date'] . $sequenceData['zone']]->addSequence($sequenceData['seq'], $filename);
     return $msg;
 }
Esempio n. 28
0
 public function execute()
 {
     Billrun_Factory::log()->log("Execute VLR api call", Zend_Log::INFO);
     $request = $this->getRequest();
     $vlr = $request->get('vlr', NULL);
     if (empty($vlr)) {
         return $this->setError('VLR number is empty', $request->getRequest());
     }
     if (strlen($vlr) > 5) {
         $vlr = substr($vlr, 0, 5);
     }
     $cacheParams = array('fetchParams' => array('vlr' => $vlr));
     $this->setCacheLifeTime(604800);
     // 1 week
     $rate = $this->cache($cacheParams);
     $this->getController()->setOutput(array(array('status' => 1, 'desc' => 'success', 'details' => $rate, 'input' => $request->getRequest())));
 }
Esempio n. 29
0
 /**
  * method to collect data which need to be handle by event
  */
 public function handlerCollect($options)
 {
     if ($this->getName() != $options['type']) {
         return FALSE;
     }
     Billrun_Factory::log()->log("ILDS fraud collect handler triggered", Zend_Log::DEBUG);
     $lines = Billrun_Factory::db()->linesCollection();
     $charge_time = Billrun_Util::getLastChargeTime(true, Billrun_Factory::config()->getConfigValue('ilds.billrun.charging_day', 20));
     $base_match = array('$match' => array('source' => 'ilds'));
     $where = array('$match' => array('event_stamp' => array('$exists' => false), 'deposit_stamp' => array('$exists' => false), 'urt' => array('$gte' => new MongoDate($charge_time)), 'aprice' => array('$exists' => true), 'billrun' => array('$exists' => false)));
     $group = array('$group' => array("_id" => '$caller_phone_no', 'msisdn' => array('$first' => '$caller_phone_no'), "total" => array('$sum' => '$aprice'), 'lines_stamps' => array('$addToSet' => '$stamp')));
     $project = array('$project' => array('caller_phone_no' => '$_id', '_id' => 0, 'msidsn' => 1, 'total' => 1, 'lines_stamps' => 1));
     $having = array('$match' => array('total' => array('$gte' => floatval(Billrun_Factory::config()->getConfigValue('ilds.threshold', 100)))));
     $ret = $lines->aggregate($base_match, $where, $group, $project, $having);
     Billrun_Factory::log()->log("ILDS fraud plugin found " . count($ret) . " items", Zend_Log::DEBUG);
     return $ret;
 }
Esempio n. 30
0
 /**
  * load the data to aggregate
  */
 public function load()
 {
     $billrun_key = $this->getStamp();
     $subscriber = Billrun_Factory::subscriber();
     $filename = $billrun_key . '_leftover_aggregator_input';
     Billrun_Factory::log()->log("Loading file " . $filename, Zend_Log::INFO);
     $billrun_end_time = Billrun_Util::getEndTime($billrun_key);
     $this->data = $subscriber->getListFromFile('files/' . $filename, $billrun_end_time);
     if (!count($this->data)) {
         Billrun_Factory::log()->log("No accounts were found for leftover aggregator", Zend_Log::ALERT);
     }
     if (is_array($this->data)) {
         $this->data = array_slice($this->data, $this->page * $this->size, $this->size, TRUE);
     }
     Billrun_Factory::log()->log("aggregator entities loaded: " . count($this->data), Zend_Log::INFO);
     Billrun_Factory::dispatcher()->trigger('afterAggregatorLoadData', array('aggregator' => $this));
 }