/** * updates Activity Document Link * @param array $documentLink * @param ActivityDocumentLink $activityDocumentLink * @return bool */ public function update(array $documentLink, ActivityDocumentLink $activityDocumentLink) { try { $this->database->beginTransaction(); $documentLinkExists = $activityDocumentLink->exists; $activityId = $activityDocumentLink->activity_id; $documentManager = app(DocumentManager::class); if ($documentLinkExists) { $url = $activityDocumentLink->document_link['url']; $document = $documentManager->getDocument(session('org_id'), $url); $activities = (array) $document->activities; unset($activities[$activityId]); $document->activities = $activities; $documentManager->update($document); } $url = $documentLink[0]['url']; $document = $documentManager->getDocument(session('org_id'), $url); $activities = (array) $document->activities; $identifier = $activityDocumentLink->activity->identifier['activity_identifier']; $activities[$activityId] = $identifier; $document->activities = $activities; $documentManager->update($document); $this->DocumentLinkRepo->update($documentLink, $activityDocumentLink); $this->database->commit(); $this->logger->info(sprintf('Activity Document Link %s!', $documentLinkExists ? 'updated' : 'saved'), ['for' => $documentLink]); $this->dbLogger->activity(sprintf("activity.document_link_%s", $documentLinkExists ? 'updated' : 'saved'), ['activity_id' => $activityDocumentLink->activity_id, 'document_link_id' => $activityDocumentLink->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, ['documentLink' => $documentLink]); } return false; }
/** * upload activity form csv * @param $activityCsv * @param $organization * @param $defaultFieldValues * @return bool */ public function save($activityCsv, $organization, $defaultFieldValues) { try { $excel = $this->version->getExcel(); $activitiesRows = $excel->load($activityCsv)->get(); $activityDetails = []; foreach ($activitiesRows as $activityRow) { $activityDetails[] = $this->uploadActivityRepo->formatFromExcelRow($activityRow, $organization->id); } $identifiers = $this->uploadActivityRepo->getIdentifiers($organization->id); $this->database->beginTransaction(); $data = []; foreach ($activityDetails as $activityDetail) { $activityIdentifier = $activityDetail['identifier']['activity_identifier']; isset($identifiers[$activityIdentifier]) ? $data[$identifiers[$activityIdentifier]] = $activityDetail : $this->uploadActivityRepo->upload($activityDetail, $organization, $defaultFieldValues); $this->database->commit(); } if (count($data) > 0) { return view('Activity.confirmUpdate')->withData($data); } $this->logger->info("Activities Uploaded for organization with id:" . $organization->id); $this->dbLogger->activity("activity.activity_uploaded", ['organization_id' => $organization->id]); return true; } catch (Exception $exception) { $this->database->rollback(); $this->logger->error($exception, ['activity' => $activityDetails]); } return false; }
/** * Save multiple notifications sent * at once. * * @param array $notifications * @return mixed */ public function storeMultiple(array $notifications) { $this->db->beginTransaction(); $stackId = $this->db->table($this->notification->getTable())->max('stack_id') + 1; foreach ($notifications as $key => $notification) { $notifications[$key]['stack_id'] = $stackId; } $insert = $this->db->table($this->notification->getTable())->insert($notifications); $this->db->commit(); return $insert; }
/** * updates Activity Default values * @param array $activityDefaults * @param Activity $activity * @return bool */ public function update(array $activityDefaults, Activity $activity) { try { $this->database->beginTransaction(); $this->changeActivityDefaultRepo->update($activityDefaults, $activity); $this->database->commit(); $this->logger->info('Activity Default Values updated!', ['for' => $activityDefaults]); $this->dbLogger->activity("activity.activity_default_values", ['organization_id' => $this->auth->user()->organization->id, 'activity_id' => $activity->id]); return true; } catch (Exception $exception) { $this->database->rollback(); $this->logger->error($exception, ['activityDefaultValues' => $activityDefaults]); } return false; }
/** * updates title and description of an activity * @param array $activityDetails * @param Activity $activity * @return bool */ public function update(array $activityDetails, Activity $activity) { try { $this->database->beginTransaction(); $this->stepTwoRepo->update($activityDetails, $activity); $this->database->commit(); $this->logger->info('Step Two Completed!', ['for' => [$activity->title, $activity->description]]); $this->logger->activity("activity.step_two_completed", ['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, ['stepTwo' => $activityDetails]); } return false; }
/** * update organization total expenditure * @param array $totalExpenditure * @param OrganizationData $organizationData * @return bool */ public function update(array $totalExpenditure, OrganizationData $organizationData) { try { $this->database->beginTransaction(); $this->totalExpenditureRepo->update($totalExpenditure, $organizationData); $this->database->commit(); $this->logger->info('Organization Total Expenditure Updated', ['for' => $organizationData->total_expenditure]); $this->dbLogger->activity("organization.total_expenditure_updated", ['name' => $this->auth->user()->organization->name]); return true; } catch (Exception $exception) { $this->database->rollback(); $this->logger->error($exception, ['TotalExpenditure' => $totalExpenditure]); } return false; }
/** * upgrade data version wise * @param $orgId * @param $version * @return bool */ public function upgrade($orgId, $version) { try { $this->database->beginTransaction(); $this->repo->upgrade($orgId, $version); $this->database->commit(); $this->logger->info(sprintf('Version Upgraded to %s for Organization %s!', $version, $this->auth->user()->organization->name), ['for' => $orgId]); $this->dbLogger->activity("activity.version_upgraded", ['organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id, 'version' => $version]); return true; } catch (Exception $exception) { $this->database->rollback(); $this->logger->error($exception, ['version' => $version]); } return false; }
/** * updates Activity Capital Spend * @param array $activityDetails * @param Activity $activity * @return bool */ public function update(array $activityDetails, Activity $activity) { try { $this->database->beginTransaction(); $this->capitalSpendRepo->update($activityDetails, $activity); $this->database->commit(); $this->logger->info('Activity Capital Spend updated!', ['for' => $activity->capital_spend]); $this->dbLogger->activity("activity.capital_spend", ['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, ['capitalSpend' => $activityDetails]); } 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; }
/** * update organization total expenditure * @param array $humanitarianScope * @param Activity $activity * @return bool */ public function update(array $humanitarianScope, Activity $activity) { try { $this->database->beginTransaction(); $this->humanitarianScopeRepo->update($humanitarianScope, $activity); $this->database->commit(); $this->logger->info('Activity Humanitarian Scope Updated', ['for' => $activity->humanitarian_scope]); $this->dbLogger->activity("activity.humanitarian_scope_updated", ['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, ['HumanitarianScope' => $humanitarianScope]); } return false; }
/** * update recipient region budget * @param array $input * @param OrganizationData $organization * @return bool */ public function update(array $input, OrganizationData $organization) { try { $this->database->beginTransaction(); $this->repo->update($input, $organization); $this->database->commit(); $this->logger->info('Organization Recipient Region Budget Updated', ['for' => $organization->recipient_region_budget]); $this->dbLogger->activity("organization.recipient_region_budget_updated", ['name' => $this->auth->user()->organization->name]); return true; } catch (Exception $exception) { $this->database->rollback(); $this->logger->error($exception, ['OrganizationRecipientRegionBudget' => $input]); } return false; }
/** * Wrap a command execution in a database transaction. * * @param object $command * @param callable $next * @return mixed * * @throws Exception * @throws Throwable */ public function execute($command, callable $next) { $this->database->beginTransaction(); try { $returnValue = $next($command); $this->database->commit(); } catch (Exception $exception) { $this->database->rollBack(); throw $exception; } catch (Throwable $exception) { $this->database->rollBack(); throw $exception; } return $returnValue; }
/** * updates Activity Default Aid Type * @param array $activityDetails * @param Activity $activity * @return bool */ public function update(array $activityDetails, Activity $activity) { try { $this->database->beginTransaction(); $this->defaultAidTypeRepo->update($activityDetails, $activity); $this->database->commit(); $this->logger->info('Activity Default Aid Type updated!', ['for' => $activity->default_aid_type]); $this->dbLogger->activity("activity.default_aid_type", ['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, ['defaultAidType' => $activityDetails]); } return false; }
/** * Update Activity Result * @param array $resultData * @param ActivityResult $activityResult * @return bool */ public function update(array $resultData, ActivityResult $activityResult) { try { $this->database->beginTransaction(); $resultExists = $activityResult->exists; $this->resultRepo->update($resultData, $activityResult); $this->database->commit(); $this->logger->info(sprintf('Activity Result %s!', $resultExists ? 'updated' : 'saved'), ['for' => $activityResult->result]); $this->dbLogger->activity(sprintf("activity.result_%s", $resultExists ? 'updated' : 'saved'), ['activity_id' => $activityResult->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, ['result' => $resultData]); } return false; }
/** * @param $id * @param $formData * @return bool */ public function update($id, $formData) { $tags = []; if (isset($formData['tag'])) { $tags = $this->tag->createOrGet($formData['tag']); } $this->database->beginTransaction(); try { $question = $this->find($id); if (!$question->update($formData)) { return false; } $question->tags()->sync($tags); $this->saveAnswers($formData, $question); $this->saveSubQuestions($formData, $question); $this->database->commit(); return $question; } catch (\Exception $e) { dd($e); $this->database->rollback(); return false; } $this->database->rollback(); return false; }
/** * @param $id * @param $formData * @return bool */ public function update($id, $formData) { $this->db->beginTransaction(); $journey = $this->find($id); try { if (isset($formData['featured_image'])) { $this->file->delete($journey->featured_image_path); $featured_image_info = $this->fileUpload->handle($formData['featured_image'], $this->uploadPath); $formData['featured_image'] = $featured_image_info['filename']; } if (isset($formData['menu_image'])) { $this->file->delete($journey->menu_image_path); $menu_image_info = $this->fileUpload->handle($formData['menu_image'], $this->uploadPath); $formData['menu_image'] = $menu_image_info['filename']; } if (isset($formData['small_menu_image'])) { $this->file->delete($journey->small_menu_image_path); $small_menu_image_info = $this->fileUpload->handle($formData['small_menu_image'], $this->uploadPath); $formData['small_menu_image'] = $small_menu_image_info['filename']; } $journey->update($formData); $this->saveSubcategory($formData, $journey); $this->updateSubcategory($formData); $this->db->commit(); return true; } catch (Exception $e) { $this->db->rollback(); return false; } return; }
/** * @param object $command * @param callable $next * * @return mixed * @throws Exception */ public function execute($command, callable $next) { $this->database->beginTransaction(); try { $returnValue = $next($command); $this->database->commit(); } catch (Exception $exception) { if ($exception instanceof IgnoresRollback) { $this->database->commit(); } else { $this->database->rollback(); } throw $exception; } return $returnValue; }
/** * @param $id * @param $formData * @return bool */ public function update($id, $formData) { $this->db->beginTransaction(); $category = $this->find($id); try { if (isset($formData['main_image'])) { $this->file->delete($category->main_image_path); $main_image_info = $this->fileUpload->handle($formData['main_image'], $this->uploadPath); $formData['main_image'] = $main_image_info['filename']; } if (isset($formData['icon'])) { $this->file->delete($category->icon_path); $icon_info = $this->fileUpload->handle($formData['icon'], $this->uploadPath); $formData['icon'] = $icon_info['filename']; } if (isset($formData['small_icon'])) { $this->file->delete($category->small_icon_path); $small_icon_info = $this->fileUpload->handle($formData['small_icon'], $this->uploadPath); $formData['small_icon'] = $small_icon_info['filename']; } $category->update($formData); $this->db->commit(); return true; } catch (Exception $e) { $this->db->rollback(); return false; } return; }
/** * save new activity from wizard * @param array $identifier * @param $defaultFieldValues * @return bool */ public function store(array $identifier, $defaultFieldValues) { try { $this->database->beginTransaction(); $result = $this->activityRepo->store($identifier, $defaultFieldValues, $this->auth->user()->organization->id); $this->activityRepo->saveDefaultValues($result->id, $defaultFieldValues); $this->database->commit(); $this->logger->info('Activity identifier added!', ['for' => $identifier['activity_identifier']]); $this->logger->activity("activity.activity_added", ['identifier' => $identifier['activity_identifier'], 'organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]); return $result; } catch (Exception $exception) { $this->database->rollback(); $this->logger->error($exception, ['ActivityIdentifier' => $identifier]); } return false; }
/** * Performs the import. */ public function import() { $this->startedAt = microtime(true); $this->callEventHandler($this->beforeHandler); $this->fileIterator = $this->openFile($this->getImportFile(), $this->getDelimiter(), $this->getIgnoreLines(), $this->getTakeLines()); $this->imported = 0; $rules = $this->getRowValidationRules(); if ($this->useTransaction) { $this->db->beginTransaction(); } foreach ($this->fileIterator as $values) { $row = $this->mapValues($values, $this->getFields()); $key = $this->mapValues($values, $this->getKeyFields()); if (!empty($rules)) { $this->validateRow($row, $rules); } switch ($this->mode) { case self::MODE_INSERT: $this->insert($row); break; case self::MODE_INSERT_NEW: $this->insertNew($row, $key); break; case self::MODE_UPDATE: $this->update($row, $key); break; default: //self::MODE_UPSERT $this->upsert($row, $key); } ++$this->imported; $this->callEventHandler($this->importedHandler); } if ($this->useTransaction) { $this->db->commit(); } $this->callEventHandler($this->afterHandler); $this->fileIterator = null; $this->executionTime = $this->getElapsedTime($this->startedAt); }
/** * updates username * @param $userId * @param UsernameRequest $usernameRequest * @param DatabaseManager $database * @return mixed */ public function updateUsername($userId, UsernameRequest $usernameRequest, DatabaseManager $database) { $input = $usernameRequest->all(); $user = $this->user->findOrFail($userId); $organization = $this->organization->findOrFail($this->orgId); $database->beginTransaction(); $organization->user_identifier = $input['organization_user_identifier']; $user->username = $input['username']; $user->save(); $organization->save(); $database->commit(); $response = $user->save() && $organization->save() ? ['type' => 'success', 'code' => ['updated', ['name' => 'Username']]] : ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Username']]]; return redirect('user/profile')->withResponse($response); }
/** * @param Activity $activity * @param $element * @return bool */ public function deleteElement(Activity $activity, $element) { try { $this->database->beginTransaction(); $this->activityRepo->deleteElement($activity, $element); $this->database->commit(); $this->logger->info(sprintf('Activity element %s has been deleted.', $element), ['for ' => $activity->id]); $this->logger->activity("activity.activity_element_deleted", ['element' => $element, '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); } return false; }
/** * save document * @param Document $document * @param bool $update * @return mixed */ public function store(Document $document, $update = false) { try { $this->database->beginTransaction(); $this->repo->store($document); $this->database->commit(); $this->logger->info(sprintf('Document %s successfully.', $update ? 'updated' : 'saved'), ['for' => $this->auth->user()->organization->id]); $this->dbLogger->activity(sprintf("activity.document_%s", $update ? 'updated' : 'saved'), ['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, ['document' => $document]); } return false; }
/** * update settings * @param $input * @param $organization * @param $settings * @return bool */ public function updateSettings($input, $organization, $settings) { try { $this->dbManager->beginTransaction(); $this->repo->updateSettings($input, $organization, $settings); $this->logger->info('Settings Updated Successfully.'); $this->dbLogger->activity("activity.settings_updated", ['organization' => $this->auth->user()->organization->name, 'organization_id' => $this->auth->user()->organization->id]); $this->dbManager->commit(); return true; } catch (Exception $e) { $this->dbManager->rollback(); $this->logger->error($e, ['settings' => $input]); } return false; }
/** * Delete an existing UserGroup. * @param $userGroup * @return bool */ public function deleteGroup($userGroup) { try { $userGroupName = $userGroup->group_name; $groupAdmin = $userGroup->user; $this->databaseManager->beginTransaction(); $userGroup->delete(); $groupAdmin->delete(); $this->databaseManager->commit(); $this->logger->info("User Group successfully deleted.", ['group_name' => $userGroupName, 'super_admin' => auth()->user()->username]); $this->logger->activity("activity.group_organization_deleted", ['group_name' => $userGroupName, 'super_admin' => auth()->user()->username]); return true; } catch (Exception $exception) { $this->databaseManager->rollback(); $this->logger->error(sprintf("User Group could not be deleted due to %s.", $exception->getMessage()), ['group_name' => $userGroupName, 'super_admin' => auth()->user()->username, 'trace' => $exception->getTraceAsString()]); } }
/** * @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; }
/** * @param $id * @param $formData * * @return bool */ public function update($id, $formData) { $tags = []; if (isset($formData['tag'])) { $tags = $this->tag->createOrGet($formData['tag']); } $this->database->beginTransaction(); try { $formData['is_published'] = isset($formData['is_published']) ? true : false; $post = $this->find($id); $post->created_at = $formData['created_at']; if (isset($formData['metadata']['data']['phone'])) { $formData['metadata']['data']['phone'] = array_values($formData['metadata']['data']['phone']); } if ($formData['metadata']['type'] === 'text') { $formData = $this->formatTypeTextUpdate($post, $formData); } if ($formData['metadata']['type'] === 'audio') { $formData = $this->formatTypeAudioUpdate($post, $formData); } if ($formData['metadata']['type'] === 'video') { $formData = $this->getVideoData($formData); } if (isset($formData['metadata']['featured_image'])) { $this->file->delete($this->uploadPath . '/' . $post->metadata->featured_image); $formData['metadata']['featured_image'] = $this->upload($formData['metadata']['featured_image']); } else { $formData['metadata']['featured_image'] = isset($post->metadata->featured_image) ? $post->metadata->featured_image : ''; } if (!$post->update($formData)) { return false; } $this->updateRelations($formData, $post); $post->tags()->sync($tags); $this->database->commit(); return $post; } catch (\Exception $e) { $this->logger->error($e); $this->database->rollback(); return false; } $this->database->rollback(); return false; }
/** * add or update organization by superadmin * @param null $orgId * @param array $orgDetails * @return mixed|void */ public function saveOrganization(array $orgDetails, $orgId = null) { try { $this->database->beginTransaction(); $orgData = $this->makeOrganizationData($orgDetails); $organization = $this->organization->firstOrNew(['id' => $orgId]); $organization->fill($orgData)->save(); $adminData = $this->makeAdminData($orgDetails, $organization->id); $user = $this->user->firstOrNew(['org_id' => $organization->id]); $user->fill($adminData)->save(); $settingsData = $this->makeSettingsData($orgDetails, $organization->id); $settings = $this->settings->firstOrNew(['organization_id' => $organization->id]); $settings->fill($settingsData)->save(); $this->database->commit(); $this->logger->info($orgId ? 'Organization information Updated' : 'Organization added'); $this->dbLogger->activity($orgId ? "activity.organization_updated" : "activity.organization_added", ['user_id' => $user->id, 'organization_id' => $orgId]); } catch (Exception $exception) { $this->database->rollback(); $this->logger->error($exception, ['settings' => $orgDetails]); } }
/** * Begin dependant repository job * * @return void */ public function begin() { $this->db->beginTransaction(); }