public function testPublishAsync()
 {
     $this->_watcherService->create($this->_watcher);
     $this->_watcherService->publishEventAsync($this->_event);
     sleep(1);
     $this->_watcher->reload();
     $this->assertEquals(WatcherModel::STATUS_FINISHED, $this->_watcher->status);
 }
 public function setUp()
 {
     $this->_watcherService = WatcherService::getInstance();
     $this->_txId = uniqid('test-', true);
     $user = \App::getUserLogged();
     $this->_watcher = new WatcherModel();
     $this->_watcher->scope = 'user';
     $this->_watcher->scopeId = $user->id;
     $this->_watcher->owner = $user->id;
     $this->_watcher->namespace = 'connectivity';
     $this->_watcher->entityType = 'transaction';
     $this->_watcher->entityIds = array($this->_txId);
     $this->_watcher->transport = 'popbox';
     $this->_watcher->priority = WatcherModel::PRIORITY_LOW;
     $this->_watcher->status = WatcherModel::STATUS_ACTIVE;
     $this->_watcher->expire = strtotime(\App::config('watchers.expire', "+1 day"));
     $this->_watcher->remove = strtotime(\App::config('watchers.autoremove', "+6 months"));
     $this->_watcher->tags = array('context_' . $user->getOrganizationId());
     $this->_watcher->maxEvents = 1;
     $this->_watcher->maxEventStackSize = 1;
     $this->_watcher->params = new StructConfigModel();
     $this->_watcher->hiddenParams = new StructConfigModel();
     $this->_event = new EventModel();
     $this->_event->namespace = 'connectivity';
     $this->_event->entityType = 'transaction';
     $this->_event->entityId = $this->_txId;
     $this->_event->created = time();
     $this->_event->modified = time();
     $this->_event->pushEventData = true;
 }
 protected function _sendEvent($action, $model)
 {
     try {
         $event = $this->_createModelActionEvent($action, $model);
         WatcherService::getInstance()->publishEvent($event);
     } catch (\Exception $ex) {
         \App::log()->warn($ex);
     }
 }
 public function delete($idOrModel)
 {
     if ($idOrModel instanceof ModelAbstract) {
         $model = $idOrModel;
     } else {
         $model = $this->load($idOrModel);
     }
     $id = $model->getId();
     if (!$model || !isset($id)) {
         throw new InvalidArgumentException('Invalid Id');
     }
     $entityIds = $model->entityIds;
     $txId = array_shift($entityIds);
     ReportAsyncService::getInstance()->delete($txId);
     return parent::delete($model);
 }
Esempio n. 5
0
 /**
  *
  * @param string $filename
  */
 public function uploadBulk($filename)
 {
     // Open file
     if (!stat($filename)) {
         throw new \Application\Exceptions\UnexpectedException("Error opening file {$filename}");
     }
     $fd = fopen($filename, 'r');
     $sep = \App_Parser_CsvParser::getCsvSeparator($fd);
     // Request
     $sims = array();
     $validator = new SimBulkValidate();
     $validHeaders = $this->getUploadBulkHeaders();
     $filter = \Zend_Controller_Action_HelperBroker::getStaticHelper('FilterNotAllowedFields');
     // CSV
     $header = fgetcsv($fd, 0, $sep);
     // Header
     $prows = 0;
     // Packet rows
     $irows = 1;
     // Iteration rows
     $nrows = 1;
     // Total rows
     $ncols = count($header);
     // Total columns
     $validH = false;
     foreach ($header as $h) {
         if (isset($validHeaders[$h])) {
             $validH = true;
             break;
         }
     }
     // Check lines readed
     if (!$validH) {
         \App::log()->debug("[UpdateBulk] No valid headers");
         throw new ValidateException("No valid headers", ValidationCodes::FILE_NO_VALID_HEADERS);
     }
     if (in_array('locationManual_latitude', $header) && !in_array('locationManual_longitude', $header) || in_array('locationManual_longitude', $header) && !in_array('locationManual_latitude', $header)) {
         \App::log()->debug("[UpdateBulk] No valid headers: location requires latitude and longitude");
         throw new ValidateException("No valid headers: location requires latitude and longitude", ValidationCodes::FILE_NO_VALID_HEADERS_LOCATION);
     }
     $bulkCount = \App::config('ericssonserviceCallItemCount', self::BULK_UPDATE_DEFAULT);
     // I'm not sure... I don't like it.
     set_time_limit(0);
     $watcher = $this->getMapper()->createFileWatcher();
     $txId = uniqid("bulk");
     $watcher->entityIds = array($txId);
     $watcher->params->action = "bulkSimUpdate";
     WatcherService::getInstance()->create($watcher);
     $errors = array();
     $warnings = array();
     $ntxs = 0;
     // Rows
     while (($line = fgetcsv($fd, 0, $sep)) !== false) {
         // Next line has been readed
         $nrows++;
         // Check columns
         if (count($line) !== $ncols) {
             $errors[] = new Model\ErrorModel(array('line' => $nrows, 'description' => "Incorrect format (number of columns)", 'level' => Model\ErrorModel::ERROR_LEVEL_ERROR, 'code' => ValidationCodes::FILE_READING_ERR));
             continue;
         }
         // Create sim
         $data = array();
         foreach ($header as $key => $name) {
             // \App::log()->debug("[UpdateBulk] $name : $key");
             if (!isset($validHeaders[$name])) {
                 // Ignore invalid columns
                 //                     \App::log()->warn("[UpdateBulk] Ignoring $name column");
                 continue;
             }
             $value = $line[$key];
             if (preg_match('/^=\\"(?P<value>.*)\\"$/', $value, $matches)) {
                 $value = $matches['value'];
             }
             // GLOBALPORTAL-28668
             // if (!empty($value)) {
             // \App::log()->debug("[UpdateBulk] $name : $value");
             if (isset($value) && (!empty($value) || is_numeric($value))) {
                 // \App::log()->debug("[UpdateBulk] TRUE $name : $value");
                 // Remove field?
                 // See SimBaseMapper _mapModelToEricssonModel method,
                 // SimValidate and App_Validate_ReferenceIndex to understand it
                 if ($value === '-' && $name !== 'staticIpApnIndex') {
                     $value = '';
                 }
                 // Process field
                 if (strpos($name, 'apn_') !== false) {
                     // In order to remove the current value of a SIM´s field,
                     // the character - must be indicated
                     $index = (int) substr($name, strlen('apn_apn')) - 1;
                     $data['apns'][$index] = $value;
                 } else {
                     if (strpos($name, 'locationManual_') !== false) {
                         $value = str_replace(',', '.', $value);
                         if (!is_numeric($value)) {
                             $warnings[] = new Model\ErrorModel(array('line' => $nrows, 'column' => $name, 'description' => "Invalid value", 'level' => Model\ErrorModel::ERROR_LEVEL_WARN, 'code' => ValidationCodes::INVALID_VALUE));
                         } else {
                             $subname = substr($name, strlen('locationManual_'));
                             $value = floatval(str_replace(',', '.', $value));
                             $data['locationManual'][$subname] = (int) round($value * pow(10, 6));
                         }
                     } else {
                         if ($name == 'LTE_status') {
                             if ($value != SimModel::LTE_ACTIVE && $value != SimModel::LTE_INACTIVE) {
                                 $warnings[] = new Model\ErrorModel(array('line' => $nrows, 'column' => $name, 'description' => "Invalid value", 'level' => Model\ErrorModel::ERROR_LEVEL_WARN, 'code' => ValidationCodes::INVALID_VALUE));
                             } else {
                                 $data['lteEnabled'] = $value == SimModel::LTE_ACTIVE ? true : false;
                             }
                         } else {
                             $data[$name] = $value;
                         }
                     }
                 }
             }
         }
         // Create and validate sim
         $sim = new SimModel($data);
         $v = $this->validate($sim, false, $validator);
         if ($v === true) {
             // Backup id
             $ids = $sim->getIds();
             $type = key($ids);
             $value = current($ids);
             //Inject organization
             $org = \App::getOrgUserLogged();
             switch ($org->getType()) {
                 case OrgMasterModel::ORG_TYPE:
                     $sim->setMaster($org);
                     break;
                 case OrgServiceProviderModel::ORG_TYPE:
                     $sim->setServiceProviderCommercial($org);
                     $sim->setServiceProviderEnabler($org);
                     break;
                 case OrgCustomerModel::ORG_TYPE:
                     $sim->setCustomer($org);
                     break;
                 case OrgAggregatorModel::ORG_TYPE:
                     $sim->setAggregator($org);
                     break;
                 case OrgEndUserModel::ORG_TYPE:
                     $sim->setEndUser($org);
                     break;
             }
             // Filter by permissions
             $filter->direct('update_field', $sim);
             // Recover id and add sim to request
             $sim->{$type} = $value;
             $sims[] = $sim;
             $prows++;
         } else {
             \App::log()->warn("[UpdateBulk] Ignoring invalid sim: " . json_encode($v));
             // Sending first validation error ONLY?
             foreach ($validator->getValidationCodes() as $field => $code) {
                 $errors[] = new Model\ErrorModel(array('line' => $nrows, 'description' => $field, 'level' => Model\ErrorModel::ERROR_LEVEL_WARN, 'code' => $code ?: ValidationCodes::MODEL_SIM));
             }
         }
         // Wait until packet is full
         if ($prows == $bulkCount) {
             // Send to Ericsson
             $this->_uploadBulk($sims, $errors, $irows, $nrows, $watcher);
             $ntxs++;
             // Reset packet list
             $sims = array();
             $prows = 0;
             // Update CSV line position
             $irows = $nrows + 1;
         }
     }
     // Ensure all sims have been sent (last packet)
     if (!empty($sims)) {
         // Send to Ericsson
         $this->_uploadBulk($sims, $errors, $irows, $nrows, $watcher);
         $ntxs++;
         // Reset packet list (memory propouses)
         $sims = array();
     }
     // Check lines readed
     if ($nrows < 2) {
         \App::log()->debug("[UpdateBulk] Ignoring empty file");
         $watcher->delete();
         throw new ValidateException("Missing file rows");
     }
     $event = $this->getMapper()->constructEventToTransaction();
     $event->entityId = $txId;
     // Add error code suffix
     if (isset($errors) && is_array($errors)) {
         foreach ($errors as $errMess) {
             require_once APPLICATION_PATH . '/modules/default/controllers/ErrorController.php';
             $errMess->code = \ErrorController::finishErrorCode($errMess->code);
         }
     }
     $eventData = array('simParsed' => $nrows - 1);
     if (!empty($errors) || !empty($warnings)) {
         $eventData['hasFailures'] = true;
         if (!empty($errors)) {
             $eventData['message']['failed'] = $errors;
         }
         if (!empty($warnings)) {
             $eventData['message']['warnings'] = $warnings;
         }
     } else {
         $eventData['hasFailures'] = false;
     }
     $event->eventData = $eventData;
     $compressor = new ErrorModelCompressEvent();
     $compressor->compress($event);
     WatcherService::getInstance()->publishEvent($event);
     $nerr = count($errors);
     \App::audit("Bulk update ({$nrows} sims in {$ntxs} requests with {$nerr} errors)", null);
     return $watcher->reload();
 }
 protected function _internalCreateWatcher($watcher)
 {
     return WatcherService::getInstance()->create($watcher);
 }
 public function deleteAll(\App_ListFilter $filterList = NULL)
 {
     $filters = array();
     if ($filterList !== null) {
         $filters['filterList'] = $filterList;
     }
     $mapper = StockMapper::getInstance();
     try {
         $result = $mapper->deleteAll($filters);
     } catch (EricssonException $e) {
         if (!($result = $e->getErrorMessages())) {
             throw $e;
         }
     }
     \App::audit('Deleting all sims from handler ' . $filterList->getCursor(), null);
     $watcher = $mapper->constructWatcherToTransaction();
     $watcher->params->action = 'stockDelete';
     $watcher->params->count = $filterList ? $filterList->getOldCount() : null;
     $txId = uniqid('stockdelete');
     $watcher->entityIds = array($txId);
     WatcherService::getInstance()->create($watcher);
     $event = $mapper->constructEventToTransaction();
     $event->entityId = $txId;
     $eventData = array('hasFailures' => false, 'message' => array());
     if ($result !== true && !empty($result)) {
         $eventData['hasFailures'] = true;
         $eventData['message']['failed'] = $result;
     }
     $event->eventData = $eventData;
     WatcherService::getInstance()->publishEvent($event);
     return $watcher;
 }
 public function filesAction()
 {
     if (!$this->getRequest()->isPost()) {
         throw new AppEx\ForbiddenException("Files action must be a post request.");
     }
     $front = Zend_Controller_Front::getInstance();
     $front->registerPlugin(new \Tid_Zend_Controller_Plugin_UploadMax());
     try {
         $upload = new Zend_File_Transfer('App_File_Transfer_Adapter_HttpMultipartMixed', false, array('ignoreNoFile' => true));
     } catch (Zend_File_Transfer_Exception $e) {
         throw new AppEx\InvalidArgumentException($e->getMessage());
     }
     $upload->addValidator('Count', true, array('min' => 1, 'max' => 1))->addValidator('Extension', true, array('xml', 'csv', 'txt'))->addValidator('MimeType', true, array('application/xml', 'text/plain', 'headerCheck' => true));
     if ($upload->isValid()) {
         if ($upload->receive()) {
             try {
                 $fileinfo = current($upload->getFileInfo());
                 $filename = $fileinfo['tmp_name'];
                 // Attempt to parse data from file
                 $parseResult = $this->_stockSrv->getData($filename, $upload->getMimeType());
                 $data = $parseResult['data'];
                 $errors = $parseResult['errors'];
                 if (!empty($errors) && is_array($errors)) {
                     foreach ($errors as $errMess) {
                         require_once APPLICATION_PATH . '/modules/default/controllers/ErrorController.php';
                         $errMess->code = ErrorController::finishErrorCode($errMess->code);
                     }
                 }
                 $method = 'create' . ucfirst($data['_type']);
                 if (!empty($data['_type']) && is_callable(array($this->_stockSrv, $method))) {
                     // Check permissions according to the data type
                     $dumbSim = new Application\Model\SimModel();
                     $this->_helper->allowed($data['_perm'], $dumbSim);
                     try {
                         $watcher = $this->_stockSrv->{$method}($parseResult);
                     } catch (AppEx\GlobalServiceException $ex) {
                         $ex->addErrorMessages($errors);
                         throw $ex;
                     }
                     $txId = uniqid('parser');
                     WatcherService::getInstance()->pushEntityId($watcher, $txId);
                     $event = new EventModel();
                     $event->entityId = $txId;
                     $event->entityType = 'transaction';
                     $event->namespace = 'connectivity';
                     $event->eventData = $errors;
                     $event->created = time();
                     $event->forceFinish = true;
                     WatcherService::getInstance()->publishEvent($event);
                     //                         WatcherService::getInstance()->setStatus($watcher->id, WatcherModel::STATUS_FINISHED);
                     $errors_ex = $this->_loadErrorsFromWatcher($watcher);
                     if (!empty($errors_ex)) {
                         $errors = Zend_Json::encode($errors_ex);
                         App::log()->warn("Error on file upload in stock:\n" . $errors);
                         throw new AppEx\StockParserException("Some errors uploading file to stock.", array('errorMessages' => $errors_ex));
                     }
                 } else {
                     throw new AppEx\UnexpectedException('Unknown data type (' . $data['_type'] . ')');
                 }
             } catch (PermissionException $e) {
                 throw $e;
             } catch (StockParserException $e) {
                 throw $e;
             } catch (GlobalServiceException $e) {
                 $txId = uniqid('parser');
                 if (!isset($watcher)) {
                     $watcher = $this->_stockSrv->createFileWatcher();
                     $watcher->entityIds = array($txId);
                     $watcher->params->type = 'sim';
                     $watcher->params->action = 'stockUpload';
                     $watcher->save();
                 } else {
                     WatcherService::getInstance()->pushEntityId($watcher, $txId);
                 }
                 $event = new EventModel();
                 $event->entityId = $txId;
                 $event->entityType = 'transaction';
                 $event->namespace = 'connectivity';
                 $event->created = time();
                 $event->modified = time();
                 $event->pushEventData = true;
                 $eventData = array();
                 $errors = $e->getErrorMessages();
                 $eventData['hasFailures'] = true;
                 if (!empty($errors) && is_array($errors)) {
                     require_once APPLICATION_PATH . '/modules/default/controllers/ErrorController.php';
                     foreach ($errors as $errMess) {
                         if ($errMess instanceof ErrorModel) {
                             $errMess->code = ErrorController::finishErrorCode($errMess->code);
                         }
                     }
                     $eventData['message'] = array('failed' => $errors);
                 }
                 $event->eventData = $eventData;
                 $event->forceFinish = true;
                 $compressor = new ErrorModelCompressEvent();
                 $compressor->compress($event);
                 WatcherService::getInstance()->publishEvent($event);
                 //                     WatcherService::getInstance()->setStatus($watcher->id, WatcherModel::STATUS_FINISHED);
                 $errors = $this->_loadErrorsFromWatcher($watcher);
                 if (!empty($errors)) {
                     App::log()->warn("Error on file upload in stock:\n" . Zend_Json::encode($errors));
                     throw new AppEx\StockParserException("Some errors uploading file to stock.", array('errorMessages' => $errors));
                 }
             }
         } else {
             throw new AppEx\InvalidArgumentException('Could not receive file');
         }
     } else {
         throw new AppEx\InvalidArgumentException('Invalid file: ' . implode(', ', $upload->getMessages()));
     }
 }
 public function uploadLegacyAction()
 {
     $upload = $this->_helper->uploadFile();
     try {
         // Attempt to parse data from file
         $parseResult = $this->_stockSrv->getDataLegacy($upload->getFileName(), $upload->getMimeType());
         $data = $parseResult['data'];
         $errors = $parseResult['errors'];
         $method = 'create' . ucfirst($data['_type']);
         if (empty($data['_type']) || !is_callable(array($this->_stockSrv, $method))) {
             throw new AppEx\UnexpectedException('Unknown data type (' . $data['_type'] . ')');
         }
         // Check permissions according to the data type
         $dumbSim = new Application\Model\SimModel();
         $this->_helper->allowed($data['_perm'], $dumbSim);
         if (!empty($errors) && is_array($errors)) {
             require_once APPLICATION_PATH . '/modules/default/controllers/ErrorController.php';
             foreach ($errors as $errMess) {
                 $errMess->code = ErrorController::finishErrorCode($errMess->code);
             }
         }
         $watcher = $this->_stockSrv->{'create' . ucfirst($data['_type'])}($parseResult);
         $txId = uniqid('bulk');
         WatcherService::getInstance()->pushEntityId($watcher, $txId);
         $this->_sendBulkEvent($txId, $errors);
     } catch (PermissionException $e) {
         throw $e;
     } catch (StockParserException $e) {
         throw $e;
     } catch (GlobalServiceException $e) {
         $watcher = $this->_fakeWatcherOnParseError($e, $watcher, 'legacy', 'stockUploadLegacy', $errors);
     }
     $watcher->reload();
     $this->_helper->filterNotAllowedFields('read_field', $watcher);
     // ExtJS requires the response to be { success: true }
     $this->view->success = true;
     $this->view->watcher = $watcher;
 }
 /**
  * Handle 3party async response
  *
  * @param
  *            $methodName
  * @param
  *            $proto
  * @param
  *            $ids
  * @return mixed
  */
 protected function _sendAsyncRequestFake($methodName, $proto, $ids = array(), $customTags = array(), WatcherModel $watcher = null)
 {
     if (!$watcher || !$watcher->id) {
         $watcher = $this->_watcherToTransactionId($proto->accounting->transaction_id, $ids, $customTags, $watcher);
         $owned = true;
     } else {
         WatcherService::getInstance()->pushEntityId($watcher, $proto->accounting->transaction_id);
         $owned = false;
     }
     $event = $this->constructEventToTransaction();
     $event->entityType = $watcher->entityType;
     $event->entityId = $proto->accounting->transaction_id;
     $event->eventData = array('hasFailures' => false);
     try {
         // Send async request
         $resp = $this->_sendRequest($methodName, array('protoMessage' => $proto));
         $ok = $this->_checkResponse($resp);
     } catch (EricssonException $e) {
         if ($e->getErrorMessages()) {
             $event->eventData = $event->eventData = array('hasFailures' => true, 'message' => array('failed' => $e->getErrorMessages()));
             $compressor = new AsyncResponseCompressorEvent();
             $compressor->compress($event);
         } else {
             if ($owned) {
                 WatcherService::getInstance()->delete($watcher);
                 throw $e;
             } else {
                 $event->eventData = array('hasFailures' => true, 'exceptionMessage' => $e->getMessage(), 'exceptionCode' => $e->getCode());
             }
         }
     }
     WatcherService::getInstance()->publishEvent($event);
     $watcher->reload();
     return $watcher;
 }
<?php 
use Core\Service\WatcherService;
use Core\Model\EventModel;
use Application\Exceptions\InvalidArgumentException;
require_once realpath(dirname(__FILE__) . '/lib/Cli.php');
define("DEFAULT_ACL_BASEPATH", realpath(APPLICATION_PATH . '/../data/acl'));
/**
 * Script
 */
$cli = new Cli(array('file|f-s' => "Json file for event.", 'cacheId|c-s' => "CacheId of event."));
try {
    if ($file = $cli->getOption('f')) {
        if (!file_exists($file)) {
            throw new InvalidArgumentException("File doesn't exist");
        }
        $json = file_get_contents($file);
        unlink($file);
        $data = Zend_Json::decode($json);
        $event = new EventModel($data);
    } else {
        if (!($cacheId = $cli->getOption('c')) || !($event = \App::cache()->load($cacheId))) {
            throw new InvalidArgumentException("File or cacheId valid is required");
        }
    }
    WatcherService::getInstance()->publishEventInternal($event);
    //create JSON file from acl_portal collection
} catch (Exception $e) {
    echo "Error:\n";
    echo get_class($e) . ": " . $e->getMessage() . "\n";
    echo $e->getTraceAsString();
}
Esempio n. 12
0
 /**
  * @param  string $id
  * @return void
  */
 public function delete($idOrModel)
 {
     if ($idOrModel instanceof UserModel) {
         $user = $idOrModel;
     } else {
         $user = $this->load($idOrModel);
     }
     parent::delete($user);
     try {
         $filterList = DownloadReportService::getInstance()->buildFilterList(array());
         DownloadReportService::getInstance()->deleteAll($filterList, array('overrideDefaultFilter' => array('owner' => $user->id)));
     } catch (\Exception $e) {
         \App::log()->warn($e);
         // Nothing to do
     }
     WatcherService::getInstance()->removeByScope('user', $user->id);
     try {
         $this->sendEmailRemove($user);
     } catch (\Exception $e) {
         \App::log()->ERR('[mailto:' . $user->getEmail() . '] ' . $e->getMessage());
     }
     return true;
 }
Esempio n. 13
0
 public function delete($orgOrId)
 {
     if (!isset($orgOrId) && !strlen($orgOrId)) {
         throw new InvalidArgumentException('function param cannot be null');
     }
     if (!$orgOrId instanceof \Application\Model\OrgModelAbstract) {
         $org = $this->load($orgOrId);
     } else {
         $org = $orgOrId;
     }
     $validator = new \Application\Model\Validate\Organization\CustomerIsErasable();
     if (!$validator->isValid($org)) {
         throw new ValidateException("customer {$orgOrId} is not erasable", array('validationErrors' => $validator->getMessages()));
     }
     $type = $this->getChildrenTypeByOrg($org);
     $filterListOrgService = $this->buildFilterList(array('type' => $type, \Application\Model\Filter\OrgFilterFields::PARENT_ID => $org->getId()));
     if ($org->getType() != OrgAggregatorModel::ORG_TYPE) {
         $list = $this->listAll($type, array('filterList' => $filterListOrgService));
         $items = $list->getItems();
         if (count($items) > 0) {
             throw new InvalidArgumentException('The organization has ChildOrgs and can not be deleted');
         }
     }
     $templateService = TemplateService::getInstance();
     $userService = UserService::getInstance();
     $APPIdService = APIIdService::getInstance();
     $this->deleteOrgElements($org, $templateService);
     $this->deleteOrgElements($org, $userService);
     $this->deleteOrgElements($org, $APPIdService);
     $mapper = $this->getMapperByType($this->getTypeById($org->getId()));
     $result = $mapper->delete($org->getId());
     WatcherService::getInstance()->removeByScope('organization', $org->id);
     \App::audit('The organization with Id ' . $org->getId() . "has been deleted", $org);
     $this->_sendEvent('delete', $org);
     return $result;
 }
 public function tearDown()
 {
     if ($this->_itemId) {
         WatcherService::getInstance()->delete($this->_itemId);
     }
 }
 public function createSupervisionReport($params, $type)
 {
     $reportPath = $this->getSupervisionReport($params, $type);
     if (!$reportPath) {
         return;
     }
     $watcher = $this->getMapper()->constructWatcherToTransaction();
     $watcher->entityType = 'report';
     $txId = uniqid('report-');
     $watcher->entityIds = array($txId);
     $watcher->params->reportType = $type;
     $watcher->params->params = $params;
     $watcher->params->fileName = $watcher->entityType . '-' . $params['fileType'] . ".csv";
     $reportSrv = DownloadReportService::getInstance();
     $reportSrv->createWatcher($watcher);
     $watcherSrv = WatcherService::getInstance();
     $event = $this->getMapper()->constructEventToTransaction();
     $event->entityType = 'report';
     $event->entityId = $txId;
     $event->hiddenData = array('path' => $reportPath);
     $watcherSrv->publishEvent($event);
     return $watcher;
 }
 /**
  * @expectedException Application\Exceptions\InvalidArgumentException
  */
 public function testPushEntityIdFail()
 {
     $this->_service->pushEntityId('34234234234234', null);
 }
 public function init()
 {
     $this->_service = \Core\Service\WatcherService::getInstance();
 }
Esempio n. 18
0
 protected function _processBusinessRuleEvent(EventModel $event)
 {
     try {
         $event->pushEventData = false;
         $watcher = new WatcherModel();
         $watcher->namespace = 'connectivity';
         $watcher->owner = $event->eventData['organizationId'];
         $watcher->scope = 'organization';
         $watcher->scopeId = $event->eventData['organizationId'];
         $watcher->transport = 'popbox';
         $watcher->priority = WatcherModel::PRIORITY_LOW;
         $watcher->status = WatcherModel::STATUS_ACTIVE;
         $watcher->tags = array();
         $watcher->entityType = 'businessRule';
         $watcher->entityIds = array($event->entityId);
         $watcher->maxEvents = 1;
         $watcher->maxEventStackSize = 1;
         $watcher->expire = strtotime(\App::config('watchers.expire', "+1 day"));
         $watcher->remove = strtotime(\App::config('watchers.autoremove', "+6 months"));
         WatcherService::getInstance()->create($watcher);
     } catch (\Exception $e) {
         \App::log()->warn($e);
     }
 }