/**
  * 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;
         });
     }
 }
 /**
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function activityBulkPublishToRegistry(Request $request)
 {
     $files = $request->get('activity_files');
     $settings = $this->settingsManager->getSettings(session('org_id'));
     $organization = $this->organizationManager->getOrganization(session('org_id'));
     if (is_null($files)) {
         $response = ['type' => 'warning', 'code' => ['message', ['message' => 'Please select activity XML files to be published.']]];
         return redirect()->back()->withResponse($response);
     }
     $pubFiles = [];
     $unpubFiles = [];
     $value = [];
     foreach ($files as $data) {
         $orgId = explode(':', $data)[0];
         $filename = explode(':', $data)[1];
         $publishedFile = $this->activityManager->getActivityPublishedData($filename, $orgId);
         $result = $this->publishToRegistryForBulk($publishedFile, $orgId);
         if ($result) {
             $pubFiles[] = $filename;
             $this->savePublishedDataInActivityRegistry($publishedFile);
         } else {
             $unpubFiles[] = $filename;
         }
     }
     if ($unpubFiles) {
         $value['unpublished'] = sprintf("The files %s could not be published to registry. Please try again.", implode(',', $unpubFiles));
     }
     if ($pubFiles) {
         $this->twitter->post($settings, $organization);
         $value['published'] = sprintf("The files %s have been published to registry", implode(',', $pubFiles));
     }
     return redirect()->back()->with('value', $value);
 }