Exemplo n.º 1
0
 /**
  * @param $formData
  * @return Question|bool
  */
 public function save($formData)
 {
     $tags = [];
     if (isset($formData['tag'])) {
         $tags = $this->tag->createOrGet($formData['tag']);
     }
     $this->database->beginTransaction();
     try {
         $question = $this->question->save($formData);
         if (!$question) {
             return false;
         }
         $this->saveAnswers($formData, $question);
         $this->saveSubQuestions($formData, $question);
         $question->tags()->sync($tags);
         $this->database->commit();
         return $question;
     } catch (\Exception $e) {
         $this->logger->error($e);
         $this->database->rollback();
         return false;
     }
     $this->database->rollback();
     return false;
 }
 /**
  * update Recipient Country
  * @param array    $input
  * @param Activity $activity
  * @return bool
  */
 public function update(array $input, Activity $activity)
 {
     try {
         $this->recipientCountryRepo->update($input, $activity);
         $this->log->info('Recipient Country  Updated!', ['for ' => $activity->recipient_country]);
         $this->log->activity("activity.recipient_country_updated", ['activity_id' => $activity->id, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
         return true;
     } catch (Exception $exception) {
         $this->log->error($exception, ['RecipientCountry' => $input]);
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * updates Activity Sector
  * @param array    $activityDetails
  * @param Activity $activity
  * @return bool
  */
 public function update(array $activityDetails, Activity $activity)
 {
     try {
         $this->sectorRepo->update($activityDetails, $activity);
         $this->logger->info('Activity Sector updated!', ['for' => $activity->sector]);
         $this->logger->activity("activity.sector_updated", ['activity_id' => $activity->id, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
         return true;
     } catch (Exception $exception) {
         $this->logger->error($exception, ['sector' => $activityDetails]);
     }
     return false;
 }
 /**
  * @param array            $input
  * @param OrganizationData $organization
  * @return bool
  */
 public function update(array $input, OrganizationData $organization)
 {
     try {
         $this->repo->update($input, $organization);
         $this->log->info('Organization Recipient Country Budget  Updated', ['for ' => $organization['recipient_organization_budget']]);
         $this->log->activity("organization.recipient_organization_budget_updated", ['name' => $this->auth->user()->organization->name]);
         return true;
     } catch (Exception $exception) {
         $this->log->error($exception, ['OrganizationRecipientOrganizationBudget' => $input]);
     }
     return false;
 }
 /**
  * @param $input
  * @param $organization
  * @return bool
  */
 public function update(array $input, OrganizationData $organization)
 {
     try {
         $this->repo->update($input, $organization);
         $this->log->info('Document Link Updated', ['for' => $organization->document_link]);
         $this->log->activity("organization.document_link_updated", ['name' => $this->auth->user()->organization->name]);
         return true;
     } catch (Exception $exception) {
         $this->log->error($exception, ['OrganizationDocumentLink' => $input]);
     }
     return false;
 }
 /**
  * @param array    $input
  * @param Activity $activity
  * @return bool
  * @internal param $organization
  */
 public function update(array $input, Activity $activity)
 {
     try {
         $this->iatiIdentifierRepo->update($input, $activity);
         $this->log->info('Activity Iati Identifier updates', ['for ' => $activity['activity_identifier']]);
         $this->log->activity("activity.iati_identifier_updated", ['identifier' => $input['activity_identifier'], 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
         return true;
     } catch (Exception $exception) {
         $this->log->error($exception, ['IatiIdentifier' => $input]);
     }
     return false;
 }
Exemplo n.º 7
0
 /**
  * update activity Status
  * @param array    $input
  * @param Activity $activity
  * @return bool
  */
 public function update(array $input, Activity $activity)
 {
     try {
         $this->activityStatusRepo->update($input, $activity);
         $this->log->info('Activity Status  Updated!', ['for ' => $activity['activity_status']]);
         $this->log->activity("activity.activity_status_updated", ['activity_id' => $activity->id, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
         return true;
     } catch (Exception $exception) {
         $this->log->error($exception, ['ActivityStatus' => $input]);
     }
     return false;
 }
Exemplo n.º 8
0
 /**
  * updates Activity Title
  * @param array    $activityDetails
  * @param Activity $activity
  * @return bool
  */
 public function update(array $activityDetails, Activity $activity)
 {
     try {
         $this->iatiTitleRepo->update($activityDetails, $activity);
         $this->log->info('Activity Title Updated!', ['for ' => $activity['narrative']]);
         $this->log->activity("activity.title_updated", ['activity_id' => $activity->id, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
         return true;
     } catch (Exception $exception) {
         $this->log->error($exception, ['Title' => $activityDetails]);
     }
     return false;
 }
 /**
  * updates Activity Contact Info
  * @param array    $activityDetails
  * @param Activity $activity
  * @return bool
  */
 public function update(array $activityDetails, Activity $activity)
 {
     try {
         $this->contactInfoRepo->update($activityDetails, $activity);
         $this->log->info('Activity Contact Info Updated!', ['for ' => $activity['contact_info']]);
         $this->log->activity("activity.contact_info_updated", ['activity_id' => $activity->id, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
         return true;
     } catch (Exception $exception) {
         $this->log->error($exception, ['ContactInfo' => $activityDetails]);
     }
     return false;
 }
 /**
  * updates Activity recipient region
  * @param array    $activityDetails
  * @param Activity $activity
  * @return bool
  */
 public function update(array $activityDetails, Activity $activity)
 {
     try {
         $this->recipientRegionRepo->update($activityDetails, $activity);
         $this->log->info('Activity Recipient Region Updated!', ['for ' => $activity->recipient_region]);
         $this->log->activity("activity.recipient_region_updated", ['activity_id' => $activity->id, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
         return true;
     } catch (Exception $exception) {
         $this->log->error($exception, ['recipientRegion' => $activityDetails]);
     }
     return false;
 }
 /**
  * updates Activity Participating Organization
  * @param array    $activityDetails
  * @param Activity $activity
  * @return bool
  */
 public function update(array $activityDetails, Activity $activity)
 {
     try {
         $this->participatingOrgRepo->update($activityDetails, $activity);
         $this->log->info('Activity Participating Organization updated!', ['for' => $activity->participating_organization]);
         $this->log->activity("activity.participating_organization", ['activity_id' => $activity->id, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
         return true;
     } catch (Exception $exception) {
         $this->log->error($exception, ['ParticipatingOrganization' => $activityDetails]);
     }
     return false;
 }
 /**
  * @param $input
  * @param $organization
  * @return bool
  */
 public function update(array $input, OrganizationData $organization)
 {
     try {
         $this->repo->update($input, $organization);
         $this->log->info('Organization Total Budget Updated', ['for ' => $organization['total_budget']]);
         $this->log->activity("organization.total_budget_updated", ['name' => $organization->organization->name]);
         return true;
     } catch (Exception $exception) {
         $this->log->error($exception, ['OrganizationTotalBudget' => $input]);
     }
     return false;
 }
Exemplo n.º 13
0
 /**
  * Save Page Text
  * @param      $contractID
  * @param      $page_no
  * @param      $text
  * @param bool $log
  * @return bool
  */
 public function saveText($contractID, $page_no, $text, $log = true)
 {
     $page_detail = ['contract_id' => $contractID, 'page_no' => $page_no, 'text' => $text];
     try {
         $this->pages->updateOrCreate($page_detail);
         if ($log) {
             $this->logger->activity('contract.log.save_page', ['page' => $page_no], $contractID);
         }
         $this->logger->info("Page text updated", ['Contract id' => $contractID, 'Page id ' => $page_no]);
         return true;
     } catch (Exception $e) {
         $this->logger->error($e->getMessage());
         return false;
     }
 }
 /**
  * updates Activity Country Budget Items
  * @param array    $activityDetails
  * @param Activity $activity
  * @return bool
  */
 public function update(array $activityDetails, Activity $activity)
 {
     try {
         $this->database->beginTransaction();
         $this->CountryBudgetItemRepo->update($activityDetails, $activity);
         $this->database->commit();
         $this->logger->info('Activity Country Budget Items updated!', ['for' => $activity->country_budget_items]);
         $this->logger->activity("activity.country_budget_items", ['activity_id' => $activity->id, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
         return true;
     } catch (Exception $exception) {
         $this->database->rollback();
         $this->logger->error($exception, ['countryBudgetItems' => $activityDetails]);
     }
     return false;
 }
Exemplo n.º 15
0
 /**
  * Reset HIT
  *
  * @param $contract_id
  * @param $id
  * @return bool
  */
 public function resetHIT($contract_id, $task_id)
 {
     $contract = $this->contract->find($contract_id);
     try {
         $task = $this->task->getTask($contract_id, $task_id);
     } catch (Exception $e) {
         $this->logger->error($e->getMessage(), ['Contract id' => $contract_id, 'Task' => $task_id]);
         return false;
     }
     try {
         $this->turk->deleteHIT($task->hit_id);
     } catch (Exception $e) {
         $this->logger->error($e->getMessage(), ['Contract id' => $contract_id, 'hit id' => $task->hit_id, 'Task' => $task_id]);
         return false;
     }
     $title = sprintf('%s page-%s', $contract->title, $task->page_no);
     $url = $this->task_url . $task->pdf_url;
     $description = 'Some description goes here';
     try {
         $ret = $this->turk->createHIT($title, $description, $url);
     } catch (Exception $e) {
         $this->logger->error($e->getMessage(), ['Contract id' => $contract_id, 'Task' => $task_id]);
         return false;
     }
     $update = ['hit_id' => $ret->hit_id, 'assignments' => null, 'status' => 0, 'approved' => 0, 'hit_type_id' => $ret->hit_type_id];
     if ($ret) {
         $this->task->update($task->contract_id, $task->page_no, $update);
         $this->logger->info('HIT successfully reset', ['Contract id' => $contract_id, 'Task' => $task_id]);
         $this->logger->mTurkActivity('mturk.log.reset', null, $task->contract_id, $task_id);
         return true;
     }
     $this->logger->error('Error in MTurk', ['Contract id' => $contract_id, 'Task' => $task_id]);
     return false;
 }
 /**
  * Get Post by ID
  *
  * @param $post_id
  * @return Post
  */
 public function find($post_id)
 {
     try {
         return $this->post->find($post_id);
     } catch (\Exception $e) {
         $this->logger->error('Post->find: ' . $e->getMessage());
         return null;
     }
 }
 /**
  * Get Contract Text from AWS S3
  *
  * @param $contract_id
  * @param $file
  * @return null|string
  */
 public function getTextFromS3($contract_id, $file)
 {
     list($filename, $ext) = explode('.', $file);
     try {
         return $this->storage->disk('s3')->get($contract_id . '/' . $filename . '.txt');
     } catch (Exception $e) {
         $this->logger->error('File not found:' . $e->getMessage());
         return null;
     }
 }
 /**
  * Register any error handlers.
  *
  * @param  Handler  $handler
  * @param  Log  $log
  * @return void
  */
 public function boot(Handler $handler, Log $log)
 {
     // Here you may handle any errors that occur in your application, including
     // logging them or displaying custom views for specific errors. You may
     // even register several error handlers to handle different types of
     // exceptions. If nothing is returned, the default error view is
     // shown, which includes a detailed stack trace during debug.
     $handler->error(function (Exception $e) use($log) {
         $log->error($e);
     });
 }
Exemplo n.º 19
0
 /**
  * Send message to WebSocket server
  * If server offline - attempt to reconnect
  * @param $message
  * @throws \WebSocket\BadOpcodeException
  */
 private function sendWSMessage($message)
 {
     if (is_array($message) || is_object($message)) {
         $message = json_encode($message);
     }
     try {
         $this->wsClient->send($message);
     } catch (\Exception $e) {
         $this->logger->error(__METHOD__ . ' | ' . 'WebSocket client error. Reason: ' . $e->getMessage() . '.');
     }
 }
 /**
  * deletes element which has been clicked.
  * @param $organization
  * @param $element
  * @return bool
  */
 public function deleteElement($organization, $element)
 {
     try {
         $this->repo->deleteELement($organization, $element);
         $this->logger->info(sprintf('Organization element %s has been deleted.', $element), ['for ' => $organization->id]);
         $this->logger->activity("organization.organization_element_deleted", ['element' => $element, 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]);
         return true;
     } catch (Exception $exception) {
         $this->logger->error($exception);
     }
     return false;
 }
Exemplo n.º 21
0
 /**
  * Remove all the sector details from every transactions of the activity.
  * @param $activityId
  * @return bool
  */
 public function removeTransactionSector($activityId)
 {
     try {
         $transactions = $this->transactionRepo->getTransactionData($activityId);
         $this->activityRepo->removeTransactionSector($transactions);
         $this->logger->info('Sector has been removed from Transaction level', ['for ' => $activityId]);
         $this->logger->activity("activity.transaction_sector_removed");
         return true;
     } catch (Exception $exception) {
         $this->logger->error($exception);
     }
     return false;
 }
 /**
  * Get Contract Json
  *
  * @param      $key
  * @param bool $contractOnly
  * @return object|null
  */
 public function getJsonData($key, $contractOnly = true)
 {
     try {
         $filename = $key . '.json';
         $data = $this->filesystem->get($this->getFilePath($key, $filename));
         $data = json_decode($data);
         if ($contractOnly) {
             return $data->contracts;
         }
         return $data;
     } catch (\Exception $e) {
         $this->logger->error($e->getMessage());
         return null;
     }
 }
Exemplo n.º 23
0
 /**
  * @param $likesData
  *
  * @return array|bool
  */
 function sync($likesData)
 {
     $ids = $this->postIdsExistsCheck($likesData);
     try {
         foreach ($likesData as $data) {
             if (in_array($data['id'], $ids['success'])) {
                 $this->SyncLikeData($data);
             }
         }
     } catch (\Exception $e) {
         $this->logger->error($e);
         return false;
     }
     return $ids;
 }
Exemplo n.º 24
0
 /**
  * @param $id
  *
  * @return Category
  */
 public function detail($id)
 {
     try {
         $root = $this->category->find($id);
         $categoryArray = [];
         foreach ($root->getImmediateDescendants()->sortBy('position') as $category) {
             $categoryArray[] = $this->buildCategory($category);
         }
         $response = $this->buildCategory($root);
         $response['sub_categories'] = $categoryArray;
         return $response;
     } catch (\Exception $e) {
         $this->logger->error($e->getMessage());
         return false;
     }
 }
 /**
  * @param $contractId
  * @param $message
  * @param $type
  * @param $annotationStatus
  * @return bool
  */
 public function comment($contractId, $message, $annotationStatus)
 {
     $this->database->beginTransaction();
     $status = $this->updateStatus($annotationStatus, $contractId);
     if ($status) {
         try {
             $this->comment->save($contractId, $message, "annotation", $annotationStatus);
             $this->logger->info('Comment successfully added.', ['Contract id' => $contractId, 'type' => 'annotation', 'status' => $status]);
             $this->database->commit();
             return true;
         } catch (Exception $e) {
             $this->database->rollback();
             $this->logger->error($e->getMessage());
         }
     }
     return false;
 }
Exemplo n.º 26
0
 /**
  * import selected activities
  * @param array $activities
  * @return bool
  */
 public function importActivities(array $activities)
 {
     $database = app(DatabaseManager::class);
     try {
         $database->beginTransaction();
         $organization = $this->orgManager->getOrganization(session('org_id'));
         $this->template ?: $this->setTemplate(json_decode($activities[0], true));
         $this->importedActivities = $this->template->save($activities);
         $database->commit();
         $this->logger->activity("activity.activity_uploaded", ['organization' => $organization->name, 'organization_id' => $organization->id]);
         return true;
     } catch (Exception $exception) {
         $database->rollback();
         $this->logger->error($exception, ['activities' => $activities]);
     }
     return false;
 }
 /**
  * @param $contract
  * @return array
  * @throws \Exception
  */
 public function setup($contract)
 {
     $this->logger->info('Download started...', ['file' => $contract->file]);
     $pdfFile = '';
     try {
         $pdfFile = $this->storage->disk('s3')->get($contract->file);
     } catch (\Exception $e) {
         $this->logger->error($e->getMessage(), ['contract id' => $contract->id, 'file' => $contract->file]);
     }
     $this->storage->disk('local')->put($contract->file, $pdfFile);
     $this->logger->info('Download completed...', ['file' => $pdfFile]);
     if (!$this->fileSystem->isDirectory($this->getContractDirectory($contract->id))) {
         $this->addDirectory($contract->id, $this->getWriteDirectory());
     }
     $writeFolderPath = $this->getContractDirectory($contract->id);
     $readFilePath = sprintf('%s/app/%s', storage_path(), $contract->file);
     return [$writeFolderPath, $readFilePath];
 }
 /**
  * @param string $eventName
  * @param string $subject
  * @param string $message
  * @param string $type
  */
 protected function sendNotification($eventName, $subject, $message, $type)
 {
     $senderNames = config("server-monitor.notifications.events.{$eventName}");
     collect($senderNames)->map(function ($senderName) {
         $className = $senderName;
         if (file_exists(__DIR__ . '/Senders/' . ucfirst($senderName) . '.php')) {
             $className = '\\EricMakesStuff\\ServerMonitor\\Notifications\\Senders\\' . ucfirst($senderName);
         }
         return app($className);
     })->each(function (SendsNotifications $sender) use($subject, $message, $type) {
         try {
             $sender->setSubject($subject)->setMessage($message)->setType($type)->send();
         } catch (Exception $exception) {
             $errorMessage = "Server Monitor notifier failed because {$exception->getMessage()}" . PHP_EOL . $exception->getTraceAsString();
             $this->log->error($errorMessage);
             monitorConsoleOutput()->error($errorMessage);
         }
     });
 }
Exemplo n.º 29
0
 /**
  * Attempts to update Composer.
  *
  * Returns true if Composer was updated, false if not.
  *
  * @return bool
  * @throws ComposerException
  */
 public function selfUpdate()
 {
     $beforeVersion = $this->getVersion();
     $process = $this->getProcess();
     $processCommand = trim($this->findComposer() . ' self-update');
     $process->setCommandLine($processCommand);
     $this->log->info('Running Composer command', ['command' => $processCommand]);
     $process->run();
     if ($process->isSuccessful() == false) {
         $composerError = remove_ansi($process->getErrorOutput());
         $this->log->error('Composer self update process failure', ['composer' => $composerError]);
         throw new ComposerException('There was an error updating Composer');
     }
     $afterVersion = $this->getVersion();
     if ($beforeVersion == $afterVersion) {
         return false;
     }
     return true;
 }
 /**
  * Get permission name
  *
  * @param string $ability
  *
  * @return string
  * @throws \Exception
  */
 protected function getPermissionName($ability)
 {
     $permissionMappings = $this->getPermissionMappings();
     // if we have full mapping for ability, we will use it
     if (isset($permissionMappings[$ability])) {
         return $permissionMappings[$ability];
     }
     // otherwise we will use default schema with group
     // we need to have group name defined in policy
     if ($this->group === null) {
         $this->log->error('You need to set group property in ' . __CLASS__);
         throw new \Exception('No group policy defined');
     }
     // we verify whether we have ability name mapping defined - if yes, we
     // will use it
     $abilityMappings = $this->getAbilityMappings();
     $ability = isset($abilityMappings[$ability]) ? $abilityMappings[$ability] : $ability;
     return $this->group . '.' . $ability;
 }