/** * method to execute the process process * it's called automatically by the cli main controller */ public function execute() { $possibleOptions = array('type' => false, 'parser' => false, 'path' => true, 'backup' => true); if (($options = $this->getController()->getInstanceOptions($possibleOptions)) === FALSE) { return; } $this->_controller->addOutput("Parser selected: " . $options['parser']); //$options['parser'] = Billrun_Parser::getInstance(array('type' => $options['parser'])); $this->_controller->addOutput("Loading processor"); $processor = Billrun_Processor::getInstance($options); $this->_controller->addOutput("Processor loaded"); if ($processor) { $this->_controller->addOutput("Starting to process. This action can take a while..."); // buffer all action output ob_start(); if (isset($options['path']) && $options['path']) { $linesProcessedCount = $processor->process(); } else { $linesProcessedCount = $processor->process_files(); } // write the buffer into log and output $this->_controller->addOutput("processed " . $linesProcessedCount . " lines"); $this->_controller->addOutput(ob_get_contents()); ob_end_clean(); } else { $this->_controller->addOutput("Processor cannot be loaded"); } }
public function __construct($options) { parent::__construct($options); if (isset($options['time_offset'])) { $this->defTimeOffset = $options['time_offset']; } else { $this->defTimeOffset = date('P'); } }
/** * back up retrived files that were processed to a third patry path. * @param \Billrun_Processor $processor the processor instace contain the current processed file data. */ public function afterProcessorStore(\Billrun_Processor $processor) { $type = $processor->getType(); if ($type != 'smsc' && $type != "smpp" && $type != "mmsc") { return; } $path = Billrun_Factory::config()->getConfigValue($type . '.thirdparty.backup_path', false, 'string'); Billrun_Factory::log($path); if (!$path) { return; } if ($processor->retrievedHostname) { $path = $path . DIRECTORY_SEPARATOR . $processor->retrievedHostname; } Billrun_Factory::log()->log("Saving file to third party at : {$path}", Zend_Log::DEBUG); if (!$processor->backupToPath($path, true)) { Billrun_Factory::log()->log("Couldn't save file to third patry path at : {$path}", Zend_Log::ERR); } }
public function indexAction() { die; // don't enter this by mistake $parser = Billrun_Parser::getInstance(array('type' => 'separator', 'separator' => ",")); $parser->setSeparator(","); $import = Billrun_Processor::getInstance(array('type' => 'importzones', 'parser' => $parser, 'path' => '/home/shani/Documents/S.D.O.C/BillRun/backups/zone.csv')); if ($import === FALSE) { exit('cannot load import processor'); } $import->setBackupPath(array()); // no backup $importData = $import->process(); $merge = Billrun_Processor::getInstance(array('type' => 'mergerates', 'parser' => $parser, 'path' => '/home/shani/Documents/S.D.O.C/BillRun/backups/tariff_v2_filtered.csv')); if ($merge === FALSE) { exit('cannot load merge processor'); } $merge->setBackupPath(array()); // no backup $mergeData = $merge->process(); $mergePackage = Billrun_Processor::getInstance(array('type' => 'mergezonepackage', 'parser' => $parser, 'path' => '/home/shani/Documents/S.D.O.C/BillRun/backups/zone_group_element.csv')); if ($mergePackage === FALSE) { exit('cannot load merge processor'); } $mergePackage->setBackupPath(array()); // no backup $mergePackageData = $mergePackage->process(); $merge_intl_networks = Billrun_Processor::getInstance(array('type' => 'mergeintlnetworks', 'parser' => $parser, 'path' => '/home/shani/Documents/S.D.O.C/BillRun/backups/mobile_network.csv')); if ($merge_intl_networks === FALSE) { exit('cannot load import processor'); } $merge_intl_networks->setBackupPath(array()); // no backup $importMapData = $merge_intl_networks->process(); $wholesale = Billrun_Processor::getInstance(array('type' => 'wholesaleoutrates', 'parser' => $parser, 'path' => '/home/shani/Documents/S.D.O.C/BillRun/backups/wholesale/wsalein_tariff_out_v2.csv')); if ($wholesale === FALSE) { exit('cannot load import processor' . PHP_EOL); } $wholesale->setBackupPath(array()); // no backup $importWholesaleZones = $wholesale->process(); $wholesalein = Billrun_Processor::getInstance(array('type' => 'wholesaleinrates', 'parser' => $parser, 'path' => '/home/shani/Documents/S.D.O.C/BillRun/backups/wholesale/wsalein_tariff_in_v2.csv')); if ($wholesalein === FALSE) { exit('cannot load import processor' . PHP_EOL); } $wholesalein->setBackupPath(array()); // no backup $importWholesaleIn = $wholesalein->process(); $this->getView()->title = "BillRun | The best open source billing system"; $this->getView()->content = "Data import count: " . count($importWholesaleZones) . "<br />" . PHP_EOL . "Data merge count: " . count($mergeData) . "<br />" . "Data merge package count: " . count($mergePackageData) . "<br />" . "Data merge package count: " . count($mergePackageData) . "<br />" . "Merge intl. networks count: " . $importMapData . "<br />" . PHP_EOL; }
/** * 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); }
/** * @see Billrun_Plugin_Interface_IProcessor::processData */ public function processData($type, $fileHandle, \Billrun_Processor &$processor) { if ($type != $this->getName()) { return FALSE; } $bytes = null; $headerData = fread($fileHandle, self::HEADER_LENGTH); $header = $processor->getParser()->parseHeader($headerData); if (isset($header['data_length_in_block']) && !feof($fileHandle)) { $bytes = fread($fileHandle, $header['data_length_in_block'] - self::HEADER_LENGTH); } do { $row = $processor->buildDataRow($bytes); if ($row) { $processor->addDataRow($row); } $bytes = substr($bytes, $processor->getParser()->getLastParseLength()); } while (isset($bytes[self::TRAILER_LENGTH + 1])); $trailer = $processor->getParser()->parseTrailer($bytes); //align the readhead if (self::RECORD_ALIGNMENT - $header['data_length_in_block'] > 0) { fread($fileHandle, self::RECORD_ALIGNMENT - $header['data_length_in_block']); } //add trailer data $processorData =& $processor->getData(); $processorData['trailer'] = $this->updateBlockData($trailer, $header, $processorData['trailer']); return true; }
/** * TODO * @param \Billrun_Processor $processor * @return type */ public function afterProcessorStore($processor) { if ($processor->getType() != "ggsn") { return; } Billrun_Factory::log('Plugin fraud afterProcessorStore', Zend_Log::INFO); $runAsync = Billrun_Factory::config()->getConfigValue('fraud.runAsync', 1); if (function_exists("pcntl_fork") && $runAsync && -1 !== ($pid = pcntl_fork())) { if ($pid == 0) { Billrun_Util::resetForkProcess(); Billrun_Factory::log('Plugin fraud::afterProcessorStore run it in async mode', Zend_Log::INFO); $this->insertRoamingGgsn($processor->getData()['data']); Billrun_Factory::log('Plugin fraud::afterProcessorStore async mode done.', Zend_Log::INFO); exit; // exit from child process after finish } } else { Billrun_Factory::log('Plugin fraud::afterProcessorStore runing in sync mode', Zend_Log::INFO); $this->insertRoamingGgsn($processor->getData()['data']); } Billrun_Factory::log('Plugin fraud afterProcessorStore was ended', Zend_Log::INFO); }
/** * @see Billrun_Plugin_Interface_IProcessor::processData */ public function processData($type, $fileHandle, \Billrun_Processor &$processor) { if ($this->getName() != $type) { return FALSE; } $processorData =& $processor->getData(); $bytes = ''; do { $bytes .= fread($fileHandle, self::FILE_READ_AHEAD_LENGTH); } while (!feof($fileHandle)); $parsedData = Asn_Base::parseASNString($bytes); $processorData['header'] = $processor->buildHeader($parsedData); //$bytes = substr($bytes, $processor->getParser()->getLastParseLength()); if (!isset($this->tap3Config[$this->fileVersion])) { Billrun_Factory::log("Processing tap3 file {$processor->filename} with non supported version : {$this->fileVersion}", Zend_log::NOTICE); throw new Exception("Processing tap3 file {$processor->filename} with non supported version : {$this->fileVersion}"); } $trailer = $processor->buildTrailer($parsedData); $this->initExchangeRates($trailer); if (empty($this->currentFileHeader['notification']) || !empty($this->currentFileHeader['header'])) { foreach ($parsedData->getData() as $record) { if (in_array($record->getType(), $this->tap3Config['config']['data_records'])) { foreach ($record->getData() as $key => $data) { $row = $processor->buildDataRow($data); if ($row) { $row['file_rec_num'] = $key + 1; $processorData['data'][] = $row; } } } else { if (!isset($this->tap3Config['header'][$record->getType()]) && !isset($this->tap3Config['trailer'][$record->getType()])) { Billrun_Factory::log()->log('No config for type : ' . $record->getType(), Zend_Log::DEBUG); } } } } else { Billrun_Factory::log()->log('Got notification/empty file : ' . $processor->filename . ' , moving on...', Zend_Log::INFO); } $processorData['trailer'] = $trailer; return true; }
/** * @see Billrun_Plugin_Interface_IProcessor::processData */ public function processData($type, $fileHandle, \Billrun_Processor &$processor) { if ($this->getName() != $type) { return FALSE; } $processedData =& $processor->getData(); $processedData['header'] = $processor->buildHeader(fread($fileHandle, self::HEADER_LENGTH)); $bytes = null; while (true) { if (!feof($fileHandle) && !isset($bytes[self::MAX_CHUNKLENGTH_LENGTH])) { $bytes .= fread($fileHandle, self::FILE_READ_AHEAD_LENGTH); } if (!isset($bytes[self::HEADER_LENGTH])) { break; } $row = $processor->buildDataRow($bytes); if ($row) { $row['stamp'] = md5($bytes); $processedData['data'][] = $row; } //Billrun_Factory::log()->log( $processor->getParser()->getLastParseLength(), Zend_Log::DEBUG); $advance = $processor->getParser()->getLastParseLength(); $bytes = substr($bytes, $advance <= 0 ? 1 : $advance); } $processedData['trailer'] = $processor->buildTrailer($bytes); return true; }
/** * move zip files to backup path after the processing was done * @param Billrun_Processor $processor the proce * @param string $file_path the path of the current processing file. */ public function afterProcessorBackup($processor, &$file_path) { if ($processor->getType() != $this->getName()) { return; } $path = Billrun_Factory::config()->getConfigValue($this->getName() . '.processor.zip_move_path', false, 'string'); if (!$path) { return; } if ($processor->retrievedHostname) { $path = $path . DIRECTORY_SEPARATOR . $processor->retrievedHostname; } $path .= DIRECTORY_SEPARATOR . date("Ym"); if (!file_exists($path)) { Billrun_Factory::log()->log("Creating Directory : {$path}", Zend_Log::DEBUG); mkdir($path, 0777, true); } $srcPath = $file_path . ".zip"; if (file_exists($srcPath)) { Billrun_Factory::log()->log("Saving zip file to : {$path}", Zend_Log::DEBUG); if (!rename($srcPath, $path . DIRECTORY_SEPARATOR . basename($srcPath))) { Billrun_Factory::log()->log(" Failed when trying to save file : " . basename($srcPath) . " to third party path : {$path}", Zend_Log::ERR); } } }
public function __construct($options) { parent::__construct($options); }
/** * @see Billrun_Plugin_Interface_IProcessor::processData */ public function processData($type, $fileHandle, \Billrun_Processor &$processor) { if ($type != $this->getName()) { return FALSE; } $bytes = null; $headerData = fread($fileHandle, self::HEADER_LENGTH); $header = $processor->getParser()->parseHeader($headerData); if (isset($header['data_length_in_block']) && !feof($fileHandle)) { $bytes = fread($fileHandle, $header['data_length_in_block'] - self::HEADER_LENGTH); } if (in_array($header['format_version'], $this->nsnConfig['block_config']['supported_versions'])) { do { $row = $processor->buildDataRow($bytes); if ($row) { $processor->addDataRow($row); } $bytes = substr($bytes, $processor->getParser()->getLastParseLength()); } while (isset($bytes[self::TRAILER_LENGTH + 1])); } else { Billrun_Factory::log()->log("Got NSN block with unsupported version : {$header['format_version']} , block header data : " . print_r($header, 1), Zend_log::CRIT); } $trailer = $processor->getParser()->parseTrailer($bytes); //align the readhead $alignment = self::RECORD_ALIGNMENT * max(1, $header['charging_block_size']); if ($alignment - $header['data_length_in_block'] > 0) { fread($fileHandle, $alignment - $header['data_length_in_block']); } //add trailer data $processorData =& $processor->getData(); $processorData['trailer'] = $this->updateBlockData($trailer, $header, $processorData['trailer']); return true; }
/** * @see Billrun_Plugin_Interface_IProcessor::processData */ public function processData($type, $fileHandle, \Billrun_Processor &$processor) { if ($this->getName() != $type) { return FALSE; } $processorData =& $processor->getData(); $bytes = ''; do { $bytes .= fread($fileHandle, self::FILE_READ_AHEAD_LENGTH); } while (!feof($fileHandle)); $parsedData = Asn_Base::parseASNString($bytes); $processorData['header'] = $processor->buildHeader($parsedData); //$bytes = substr($bytes, $processor->getParser()->getLastParseLength()); foreach ($parsedData->getData() as $record) { if (in_array($record->getType(), $this->nsnConfig['config']['data_records'])) { foreach ($record->getData() as $key => $data) { $row = $processor->buildDataRow($data); if ($row) { $row['file_rec_num'] = $key; $processorData['data'][] = $row; } } } else { //Billrun_Factory::log()->log(print_r($record,1) , Zend_Log::DEBUG); } } $processorData['trailer'] = $processor->buildTrailer($parsedData); return true; }