Example #1
0
 /**
  * Sends a theme notification to the Factory.
  *
  * This is going to contact the Factory, so it qualifies as a third-party
  * call, therefore calling it during a normal page load is not advisable. A
  * possibly safer solution could be executing this via a menu callback called
  * through an asynchronous JavaScript call.
  *
  * If the request does not succeed (and $store_failed_notification is truthy),
  * the notification will be stored so that we may try again later when cron
  * runs.
  *
  * @param string $scope
  *   The scope. Either "theme", "site", "group", or "global".
  * @param string $event
  *   The type of theme event that occurred. Either "create", "modify", or
  *   "delete".
  * @param int $nid
  *   The node ID associated with the scope. Only required for "group" scope
  *   notifications. If empty, it will be filled in automatically for "theme"
  *   and "site" scope notifications.
  * @param string $theme
  *   The system name of the theme the event relates to. Only relevant for
  *   "theme" scope notifications.
  * @param int $timestamp
  *   The timestamp when the notification was created.
  * @param bool $store_failed_notification
  *   Optional variable to disable storing a notification when the sending
  *   fails. Should be only used in case of notifications which have been
  *   already added to the pending notification table.
  *
  * @return array
  *   The message response body and code.
  */
 public function sendNotification($scope, $event, $nid = NULL, $theme = NULL, $timestamp = NULL, $store_failed_notification = TRUE)
 {
     if (!$this->isEnabled()) {
         return array('code' => 500, 'data' => array('message' => t('The theme change notification feature is not enabled.')));
     }
     try {
         if (empty($nid) && in_array($scope, array('theme', 'site'))) {
             $site = acsf_get_acsf_site();
             $nid = $site->site_id;
         }
         $parameters = array('scope' => $scope, 'event' => $event, 'nid' => $nid);
         if ($theme) {
             $parameters['theme'] = $theme;
         }
         if ($timestamp) {
             $parameters['timestamp'] = $timestamp;
         }
         $message = new AcsfMessageRest('POST', 'site-api/v1/theme/notification', $parameters);
         $message->send();
         $response = array('code' => $message->getResponseCode(), 'data' => $message->getResponseBody());
     } catch (\Exception $e) {
         $error_message = t('AcsfThemeNotify failed with error: @message.', array('@message' => $e->getMessage()));
         syslog(LOG_ERR, $error_message);
         // Send a log message to the Factory.
         $acsf_log = new AcsfLog();
         $acsf_log->log('theme_notify', $error_message, LOG_ERR);
         $response = array('code' => 500, 'data' => array('message' => $error_message));
     }
     if ($store_failed_notification && $response['code'] !== 200) {
         $this->addNotification($event, $theme);
     }
     return $response;
 }
Example #2
0
 /**
  * Logs the specified message to the Site Factory via the REST API.
  *
  * @param string $type
  *   The type of log message, usually defining the source of the message.
  * @param string $message
  *   The log message to send.
  * @param string $level
  *   The severity of the log message. Uses the predefined syslog() constants
  *   that follow RFC 3164. Defaults to LOG_NOTICE.
  * @param int $timestamp
  *   The Unix timestamp representing when the event occurred. Defaults to
  *   REQUEST_TIME.
  * @param int $nid
  *   The site node ID that the message relates to. Defaults to the current
  *   site.
  */
 public function log($type, $message, $level = NULL, $timestamp = REQUEST_TIME, $nid = NULL)
 {
     if (empty($type) || empty($message)) {
         throw new \RuntimeException('Missing required parameter.');
     }
     if (!$this->enabled()) {
         return;
     }
     if (empty($nid)) {
         $site = AcsfSite::load();
         $nid = $site->site_id;
     }
     $record = array('type' => $type, 'message' => $message, 'level' => $level ?: LOG_NOTICE, 'timestamp' => $timestamp, 'nid' => $nid);
     try {
         $message = new AcsfMessageRest('POST', 'site-api/v1/sf-log', $record);
         $message->send();
         return $message->getResponseBody();
     } catch (\Exception $e) {
         // Swallow exceptions.
     }
 }
Example #3
0
 /**
  * Refreshes the site information from the Site Factory.
  *
  * @param array $data
  *   (Optional) Data that should be sent to the factory.
  *
  * @return bool
  *   Returns TRUE if the data fetch was successful.
  */
 public function refresh(array $data = array())
 {
     if (function_exists('is_acquia_host') && !is_acquia_host()) {
         return FALSE;
     }
     try {
         $site_id = !empty($this->site_id) ? $this->site_id : $GLOBALS['gardens_site_settings']['conf']['acsf_site_id'];
         $arguments = array('site_id' => $site_id, 'site_data' => $data);
         $message = new AcsfMessageRest('GET', 'site-api/v1/sync/' . $site_id, $arguments);
         $message->send();
         $site_info = $message->getResponseBody();
     } catch (AcsfMessageFailedResponseException $e) {
         // No need to fail, we can retry the site info call.
     }
     if (empty($site_info)) {
         watchdog('acsf_site', 'Could not retrieve site information after installation.', array(), WATCHDOG_CRITICAL);
         return FALSE;
     } else {
         // Allow other modules to consume the data.
         $context = $site_info;
         $event = AcsfEvent::create('acsf_site_data_receive', $context);
         $event->run();
         $this->saveSiteInfo($site_info['sf_site']);
         return TRUE;
     }
 }