/** * Processes the data that has come back from the request. * * @param SiteDocument $site * The site being updated * @param $data * New data about the site. */ public function processUpdate(SiteDocument $site, $data) { $moduleData = json_decode(json_encode($data->contrib), TRUE); $this->drupalModuleManager->addModules($moduleData); $site->setName($data->site_name); $site->setCoreVersion($data->core->drupal->version); $site->setModules($moduleData, TRUE); try { $site->updateModules($this->drupalModuleManager); } catch (DocumentNotFoundException $e) { $this->logger->addWarning($e->getMessage()); } }
/** * Updates the dashboard following an update to a site. * * @param SiteDocument $site * The site object to update the dashboard for. * @param bool $forceDelete * If true, then the site will just be deleted from the dashboard. * * @throws \Doctrine\ODM\MongoDB\MongoDBException */ protected function updateDashboard(SiteDocument $site, $forceDelete = FALSE) { /** @var DashboardManager $dashboardManager */ $dashboardManager = $this->get('warden.dashboard_manager'); /** @var DashboardManager $dashboardSite */ $qb = $dashboardManager->createQueryBuilder(); $qb->field('siteId')->equals(new \MongoId($site->getId())); $cursor = $qb->getQuery()->execute()->toArray(); $dashboardSite = array_pop($cursor); if (empty($dashboardSite)) { return; } $dashboardManager->deleteDocument($dashboardSite->getId()); if ($forceDelete) { return; } // @todo this is the same as dashboard command - refactor. $hasCriticalIssue = $site->hasCriticalIssues(); $isModuleSecurityUpdate = FALSE; $modulesNeedUpdate = array(); foreach ($site->getModules() as $siteModule) { if (!isset($siteModule['latestVersion'])) { continue; } if ($siteModule['version'] == $siteModule['latestVersion']) { continue; } if (is_null($siteModule['version'])) { continue; } if ($siteModule['isSecurity']) { $isModuleSecurityUpdate = TRUE; $hasCriticalIssue = TRUE; } $modulesNeedUpdate[] = $siteModule; } if ($site->getLatestCoreVersion() == $site->getCoreVersion() && !$isModuleSecurityUpdate && !$hasCriticalIssue) { return; } /** @var DashboardDocument $dashboard */ $dashboard = $dashboardManager->makeNewItem(); $dashboard->setName($site->getName()); $dashboard->setSiteId($site->getId()); $dashboard->setUrl($site->getUrl()); $dashboard->setCoreVersion($site->getCoreVersion(), $site->getLatestCoreVersion(), $site->getIsSecurityCoreVersion()); $dashboard->setHasCriticalIssue($hasCriticalIssue); $dashboard->setAdditionalIssues($site->getAdditionalIssues()); $dashboard->setModules($modulesNeedUpdate); $dashboardManager->saveDocument($dashboard); }
/** * @param string $url * The URL to POST to * @param SiteDocument $site * The site being posted to * @param array $params * An array of keys and values to be posted * * @return mixed * The content of the response * * @throws WardenRequestException * If any error occurs */ public function post($url, SiteDocument $site, array $params = array()) { try { $this->setClientTimeout($this->connectionTimeout); // Don't verify SSL certificate. // @TODO make this optional $this->buzz->getClient()->setVerifyPeer(FALSE); if ($site->getAuthUser() && $site->getAuthPass()) { $headers = array(sprintf('Authorization: Basic %s', base64_encode($site->getAuthUser() . ':' . $site->getAuthPass()))); $this->setConnectionHeaders($headers); } $params['token'] = $this->sslEncryptionService->generateRequestToken(); $content = http_build_query($params); /** @var \Buzz\Message\Response $response */ $response = $this->buzz->post($url, $this->connectionHeaders, $content); if (!$response->isSuccessful()) { $this->logger->addError("Unable to request data from {$url}\nStatus code: " . $response->getStatusCode() . "\nHeaders: " . print_r($response->getHeaders(), TRUE)); throw new WardenRequestException("Unable to request data from {$url}. Check log for details."); } $site->setLastSuccessfulRequest(); $this->siteManager->updateDocument(); return $response->getContent(); } catch (ClientException $clientException) { throw new WardenRequestException($clientException->getMessage()); } }