/** * @param Application\Model\OrgModelAbstract $org * @return Application\Model\OrgModelAbstract */ public function create(ModelAbstract $org) { if ($org instanceof OrgMasterModel) { $org->setParentId(\App::config("orgSuperId")); } // Force initial status to Activated $org->setStatus(OrgModelAbstract::ORG_STATUS_ACTIVATED); return parent::create($org); }
protected function _fakeWatcherAuditLog($model) { $params = $model->params; $params = array_intersect_key($params, array_fill_keys(AuditLogFilterFields::getWhiteList(), 1)); $filterList = AuditLogService::getInstance()->buildFilterList($params); $watcher = $this->getMapper()->constructWatcherToTransaction(); $watcher->entityType = 'report'; $txId = uniqid('report-'); $watcher->entityIds = array($txId); $watcher->params->reportType = "audit_log"; $watcher->params->params = $params; $watcher->params->fileName = "report-audit.csv"; $watcher->remove = strtotime(\App::config('reports.autoremove', "+1 year")); $this->createWatcher($watcher); $event = $this->getMapper()->constructEventToTransaction(); $event->entityType = 'report'; $event->entityId = $txId; WatcherService::getInstance()->publishEvent($event); return $watcher->reload(); }
public function createCorrelationReport() { $report = $this->getMapper()->getCorrelationReport(); $watcher = $this->getMapper()->constructWatcherToTransaction(); $watcher->entityType = 'report'; $txId = uniqid('report-'); $watcher->entityIds = array($txId); $watcher->params->reportType = ReportModel::CORRELATION; $watcher->remove = strtotime(\App::config('reports.correlation.autoremove', "+6 months")); $reportSrv = DownloadReportService::getInstance(); $reportSrv->createWatcher($watcher); $hiddenData = $this->_hideFilesOnCorrelationReportModel($report); $watcherSrv = WatcherService::getInstance(); $event = $this->getMapper()->constructEventToTransaction(); $event->entityType = 'report'; $event->entityId = $txId; $event->eventData = array('hasFailures' => false, 'reportData' => $report->exportData()); $event->hiddenData = $hiddenData; $watcherSrv->publishEvent($event); return $watcher; }
/** * * @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 _sendActivationMail($tpl, UserModel $user, $token, $password = null) { $mail = $this->_createMail($user); $mail->setViewScript($tpl); $view = $mail->getView(); $view->activationLink = array('href' => "/" . \App::config('userMail.linkActivationUrl.path', ''), 'arguments' => \App::config('userMail.linkActivationUrl.arguments', array()), 'anchor' => \App::config('userMail.linkActivationUrl.anchor', '/activate'), 'anchorArguments' => \App::config('userMail.linkActivationUrl.anchorArguments', array())); $params = array('userName' => $user->getUserName(), 'token' => $token, 'lang' => $user->language); if (\App::config('userMail.linkActivationUrl.useParamsAsAnchorArgs', true)) { $view->activationLink['anchorArguments'] = $params + $view->activationLink['anchorArguments']; } else { $view->activationLink['arguments'] = $params + $view->activationLink['arguments']; } if ($password !== null) { $view->password = $password; } // Sending the email. try { $mail->send(); } catch (\Exception $e) { \App::log()->CRIT($e); } }