Ejemplo n.º 1
0
 /**
  * Constructor.
  *
  * @param string $ah_site
  *   (Optional) Acquia Hosting sitegroup.
  * @param string $ah_env
  *   (Optional) Acquia Hosting environment.
  *
  * @throws AcsfConfigIncompleteException
  */
 public function __construct($ah_site = NULL, $ah_env = NULL)
 {
     if (function_exists('is_acquia_host') && !is_acquia_host()) {
         return;
     }
     // If none specified, pick the site group and environment from $_ENV.
     if (empty($ah_site)) {
         $ah_site = $_ENV['AH_SITE_GROUP'];
     }
     if (empty($ah_env)) {
         $ah_env = $_ENV['AH_SITE_ENVIRONMENT'];
     }
     $this->ahSite = $ah_site;
     $this->ahEnv = $ah_env;
     $this->loadConfig();
     // Require the loadConfig implementation to set required values.
     foreach (array('url', 'username', 'password') as $key) {
         if (empty($this->{$key})) {
             throw new AcsfConfigIncompleteException(sprintf('The ACSF configuration was incomplete, no value was found for %s.', $key));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Sends the message to the remote server.
  */
 public function send()
 {
     if (function_exists('is_acquia_host') && !is_acquia_host()) {
         return;
     }
     $this->response = $this->sendMessage($this->config->getUrl(), $this->method, $this->endpoint, $this->parameters, $this->config->getUsername(), $this->config->getPassword());
     // Don't allow empty responses.
     if (empty($this->response)) {
         throw new AcsfMessageEmptyResponseException(sprintf('The message to %s resulted in an empty response.', $this->endpoint));
     }
     // Only allow AcsfMessageResponse compatible responses.
     if (!is_subclass_of($this->response, '\\Acquia\\Acsf\\AcsfMessageResponse')) {
         throw new AcsfMessageMalformedResponseException(sprintf('The message to %s resulted in a malformed response. It should be an AcsfMessageResponse object.', $this->endpoint));
     }
     // If the response failed, throw an exception.
     if ($this->response->failed()) {
         // The REST API returns error descriptions in the "message" field of the
         // response body.
         if (!empty($this->response->body['message'])) {
             $error_message = sprintf('The request to %s failed with HTTP error: %s %s.', $this->endpoint, $this->response->code, $this->response->body['message']);
         } else {
             $error_message = sprintf('The request to %s failed.', $this->endpoint);
         }
         throw new AcsfMessageFailedResponseException($error_message);
     }
     // Allow the implementer to respond right away.
     $this->receiveResponse($this->response);
     // Allow an anonymous callback.
     if (!empty($this->callback)) {
         try {
             $callback = $this->callback;
             $callback($this->response);
         } catch (\Exception $e) {
             // @todo log here?
         }
     }
 }
Ejemplo n.º 3
0
acsf_hooks_include('pre-sites-php');
if (!function_exists('is_acquia_host')) {
    /**
     * Checks whether the site is on Acquia Hosting.
     *
     * @return bool
     *   TRUE if the site is on Acquia Hosting, otherwise FALSE.
     */
    function is_acquia_host()
    {
        return file_exists('/var/acquia');
    }
}
// HTTP_HOST can be empty during early drush bootstrap. Also, check that we're
// on an Acquia server so we don't run this code for local development.
if (empty($_SERVER['HTTP_HOST']) || !is_acquia_host()) {
    return;
}
require_once dirname(__FILE__) . '/g/sites.inc';
// Drush site-install gets confused about the uri when we specify the
// --sites-subdir option. The HTTP_HOST is set incorrectly and we can't
// find it in the sites.json. By specifying the --acsf-install-uri option
// with the value of the standard domain, we can catch that here and
// correct the uri argument for drush site installs.
if (drupal_is_cli() && function_exists('drush_get_option') && ($http_host = drush_get_option('acsf-install-uri', FALSE))) {
    $host = $_SERVER['HTTP_HOST'] = $http_host;
    // Match the expected drupal sites.php key. @see conf_path().
    $dir = implode('.', array_reverse(explode(':', $host)));
} else {
    $host = rtrim($_SERVER['HTTP_HOST'], '.');
    // Match the expected drupal sites.php key. @see conf_path().
Ejemplo n.º 4
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;
     }
 }