コード例 #1
0
 /**
  * @param                          $id
  * @param Request                  $request
  * @param ActivityElementValidator $activityElementValidator
  * @return \Illuminate\Http\RedirectResponse
  */
 public function updateStatus($id, Request $request, ActivityElementValidator $activityElementValidator)
 {
     $activityData = $this->activityManager->getActivityData($id);
     if (Gate::denies('ownership', $activityData)) {
         return redirect()->back()->withResponse($this->getNoPrivilegesMessage());
     }
     $this->authorize('edit_activity', $activityData);
     $input = $request->all();
     $activityWorkflow = $input['activity_workflow'];
     if ($activityWorkflow == 3) {
         $this->authorize('publish_activity', $activityData);
     }
     $settings = $this->settingsManager->getSettings($activityData['organization_id']);
     $transactionData = $this->activityManager->getTransactionData($id);
     $resultData = $this->activityManager->getResultData($id);
     $organization = $this->organizationManager->getOrganization($activityData->organization_id);
     $orgElem = $this->organizationManager->getOrganizationElement();
     $activityElement = $this->activityManager->getActivityElement();
     $xmlService = $activityElement->getActivityXmlService();
     if ($activityWorkflow == 1) {
         $validationMessage = $activityElementValidator->validateActivity($activityData, $transactionData);
         if ($validationMessage) {
             $response = ['type' => 'warning', 'code' => ['message', ['message' => $validationMessage]]];
             return redirect()->back()->withResponse($response);
         }
         $messages = $xmlService->validateActivitySchema($activityData, $transactionData, $resultData, $settings, $activityElement, $orgElem, $organization);
         if ($messages != []) {
             $response = ['type' => 'danger', 'messages' => $messages, 'activity' => 'true'];
             return redirect()->back()->withResponse($response);
         }
     } elseif ($activityWorkflow == 3) {
         if (empty($settings['registry_info'][0]['publisher_id']) && empty($settings['registry_info'][0]['api_id'])) {
             $response = ['type' => 'warning', 'code' => ['settings_registry_info', ['name' => '']]];
             return redirect()->to('/settings')->withResponse($response);
         }
         $xmlService->generateActivityXml($activityData, $transactionData, $resultData, $settings, $activityElement, $orgElem, $organization);
         if ($settings['registry_info'][0]['publish_files'] == 'yes') {
             $publishedStatus = $this->publishToRegistry();
             $this->activityManager->updateStatus($input, $activityData);
             if ($publishedStatus) {
                 $this->activityManager->makePublished($activityData);
                 $this->activityManager->activityInRegistry($activityData);
                 $this->twitter->post($settings, $organization);
                 $response = ['type' => 'success', 'code' => ['publish_registry_publish', ['name' => '']]];
                 return redirect()->back()->withResponse($response);
             } else {
                 $response = ['type' => 'warning', 'code' => ['publish_registry', ['name' => '']]];
                 return redirect()->back()->withResponse($response);
             }
         }
     }
     $statusLabel = ['Completed', 'Verified', 'Published'];
     $response = $this->activityManager->updateStatus($input, $activityData) ? ['type' => 'success', 'code' => ['activity_statuses', ['name' => $statusLabel[$activityWorkflow - 1]]]] : ['type' => 'danger', 'code' => ['activity_statuses_failed', ['name' => $statusLabel[$activityWorkflow - 1]]]];
     return redirect()->back()->withResponse($response);
 }
コード例 #2
0
 /**
  * Publish an Activity.
  *
  * If the auto-publish option is set, the Activity data is published into the IATI Registry.
  * @param $activity
  * @param $details
  * @return bool
  */
 public function publish($activity, array $details)
 {
     try {
         $organization = $activity->organization;
         $settings = $organization->settings;
         $version = $settings->version;
         $this->xmlServiceProvider->initializeGenerator($version)->generate($activity, $this->organizationManager->getOrganizationElement(), $this->activityManager->getActivityElement());
         if (getVal($settings['registry_info'], [0, 'publish_files']) == 'yes') {
             $this->publisher->publishFile($organization->settings['registry_info'], $this->organizationDataProvider->fileBeingPublished($activity->id), $organization, $organization->settings->publishing_type);
             $this->activityManager->activityInRegistry($activity);
             $this->twitter->post($organization->settings, $organization);
         }
         $this->update($details, $activity);
         return true;
     } catch (\ErrorException $exception) {
         $this->logger->error($exception);
         return null;
     } catch (Exception $exception) {
         $this->logger->error($exception);
         return array_first(explode("\n", $exception->getMessage()), function () {
             return true;
         });
     }
 }