/**
  * 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());
     }
 }
Exemple #2
0
 /**
  * Updates the modules list for the provided site.
  *
  * This updates the list of modules that this site has with the module documents.
  *
  * @param ModuleManager $moduleManager
  *
  * @throws DocumentNotFoundException
  */
 public function updateModules(ModuleManager $moduleManager)
 {
     foreach ($this->getModules() as $siteModule) {
         /** @var ModuleDocument $module */
         try {
             $module = $moduleManager->findByProjectName($siteModule['name']);
         } catch (DocumentNotFoundException $e) {
             throw new DocumentNotFoundException('Error getting module [' . $siteModule['name'] . ']: ' . $e->getMessage());
             continue;
         }
         $moduleSites = $module->getSites();
         // Check if the site URL is already in the list for this module.
         $alreadyExists = FALSE;
         if (is_array($moduleSites)) {
             foreach ($moduleSites as $moduleSite) {
                 if ($moduleSite['id'] == $this->getId()) {
                     $alreadyExists = TRUE;
                     break;
                 }
             }
         }
         if ($alreadyExists) {
             $module->updateSite($this->getId(), $siteModule['version']);
         } else {
             $module->addSite($this->getId(), $this->getUrl(), $siteModule['version']);
         }
         $moduleManager->updateDocument();
     }
 }
 /**
  * Update the Drupal Core and Modules with the latest versions.
  *
  * @param bool $updateNewSitesOnly
  *   Only update modules on sites marked as new.
  */
 public function updateAllDrupalModules($updateNewSitesOnly = FALSE)
 {
     $this->logger->addInfo('*** Starting Drupal Update Request Service ***');
     $drupalAllModuleVersions = array();
     $moduleLatestVersion = array();
     $majorVersions = $this->siteManager->getAllMajorVersionReleases();
     foreach ($majorVersions as $version) {
         $modules = $this->drupalModuleManager->getAllByVersion($version);
         /** @var ModuleDocument $module */
         foreach ($modules as $module) {
             $this->logger->addInfo('Updating - ' . $module->getProjectName() . ' for version: ' . $version);
             try {
                 $this->processDrupalUpdateData($module->getProjectName(), $version);
             } catch (\Exception $e) {
                 $this->logger->addWarning(' - Unable to update module version [' . $version . ']: ' . $e->getMessage());
                 continue;
             }
             $drupalAllModuleVersions[$version][$module->getProjectName()] = $drupalModuleVersions = $this->moduleVersions;
             $moduleVersions = array();
             // Get the recommended module version.
             if (isset($drupalModuleVersions[ModuleDocument::MODULE_VERSION_TYPE_RECOMMENDED])) {
                 $moduleRecommendedLatestVersion = $drupalModuleVersions[ModuleDocument::MODULE_VERSION_TYPE_RECOMMENDED][0];
                 $moduleVersions[ModuleDocument::MODULE_VERSION_TYPE_RECOMMENDED] = $moduleRecommendedLatestVersion;
                 $moduleLatestVersion[$version][$module->getProjectName()][ModuleDocument::MODULE_VERSION_TYPE_RECOMMENDED] = $moduleRecommendedLatestVersion;
             }
             // Get the other module version.
             if (isset($drupalModuleVersions[ModuleDocument::MODULE_VERSION_TYPE_OTHER])) {
                 $moduleOtherLatestVersion = $drupalModuleVersions[ModuleDocument::MODULE_VERSION_TYPE_OTHER][0];
                 $moduleVersions[ModuleDocument::MODULE_VERSION_TYPE_OTHER] = $moduleOtherLatestVersion;
                 $moduleLatestVersion[$version][$module->getProjectName()][ModuleDocument::MODULE_VERSION_TYPE_OTHER] = $moduleOtherLatestVersion;
             }
             $module->setName($this->getModuleName());
             $module->setIsNew(FALSE);
             $module->setLatestVersion($version, $moduleVersions);
             $module->setProjectStatus($this->projectStatus);
             $this->drupalModuleManager->updateDocument();
         }
     }
     foreach ($majorVersions as $version) {
         // Update the core after the modules to update the versions of the modules
         // for a site.
         $this->logger->addInfo('Updating - Drupal version: ' . $version);
         try {
             $this->processDrupalUpdateData('drupal', $version);
         } catch (\Exception $e) {
             $this->logger->addWarning(' - Unable to update drupal version [' . $version . ']: ' . $e->getMessage());
             continue;
         }
         $newOnly = $updateNewSitesOnly ? array('isNew' => TRUE) : array();
         $sites = $this->siteManager->getDocumentsBy(array_merge(array('coreVersion.release' => $version), $newOnly));
         // Update the sites for the major version with the latest core & module version information.
         $coreVersions = $this->moduleVersions[ModuleDocument::MODULE_VERSION_TYPE_RECOMMENDED];
         /** @var SiteDocument $site */
         foreach ($sites as $site) {
             $this->logger->addInfo('Updating site: ' . $site->getId() . ' - ' . $site->getUrl());
             if ($site->getCoreReleaseVersion() != $version) {
                 continue;
             }
             if (isset($moduleLatestVersion[$version])) {
                 $site->setModulesLatestVersion($moduleLatestVersion[$version]);
             }
             // Check for if the core version is out of date and requires a security update.
             $siteCurrentVersion = $site->getCoreVersion();
             $hasCriticalIssue = FALSE;
             $needsSecurityUpdate = FALSE;
             foreach ($coreVersions as $coreVersion) {
                 if ($coreVersion['version'] == $siteCurrentVersion) {
                     break;
                 }
                 if ($coreVersion['isSecurity']) {
                     $needsSecurityUpdate = TRUE;
                     $hasCriticalIssue = TRUE;
                 }
             }
             // Check all the site modules to see if any of them are out of date and need a security update.
             foreach ($site->getModules() as $siteModule) {
                 if (!isset($siteModule['latestVersion'])) {
                     continue;
                 }
                 if ($siteModule['version'] == $siteModule['latestVersion']) {
                     continue;
                 }
                 if (is_null($siteModule['version'])) {
                     continue;
                 }
                 // Check to see if this site's modules require a security update.
                 $siteModuleVersionInfo = ModuleDocument::getVersionInfo($siteModule['version']);
                 $versionType = NULL;
                 if (isset($drupalAllModuleVersions[$version][$siteModule['name']][ModuleDocument::MODULE_VERSION_TYPE_RECOMMENDED])) {
                     $drupalModuleRecommendedVersionInfo = ModuleDocument::getVersionInfo($drupalAllModuleVersions[$version][$siteModule['name']][ModuleDocument::MODULE_VERSION_TYPE_RECOMMENDED][0]['version']);
                     $versionType = $drupalModuleRecommendedVersionInfo['minor'] == $siteModuleVersionInfo['minor'] ? ModuleDocument::MODULE_VERSION_TYPE_RECOMMENDED : NULL;
                 }
                 if (isset($drupalAllModuleVersions[$version][$siteModule['name']][ModuleDocument::MODULE_VERSION_TYPE_OTHER]) && is_null($versionType)) {
                     $drupalModuleOtherVersionInfo = ModuleDocument::getVersionInfo($drupalAllModuleVersions[$version][$siteModule['name']][ModuleDocument::MODULE_VERSION_TYPE_OTHER][0]['version']);
                     $versionType = $drupalModuleOtherVersionInfo['minor'] == $siteModuleVersionInfo['minor'] ? ModuleDocument::MODULE_VERSION_TYPE_OTHER : NULL;
                 }
                 if (!is_null($versionType)) {
                     foreach ($drupalAllModuleVersions[$version][$siteModule['name']][$versionType] as $drupalModule) {
                         if ($drupalModule['version'] == $siteModule['version']) {
                             break;
                         }
                         // Check for site module being a dev version - then skip.
                         if (isset($siteModuleVersionInfo['extra']) && strstr($siteModuleVersionInfo['extra'], 'dev') !== FALSE) {
                             break;
                         }
                         if ($drupalModule['isSecurity']) {
                             unset($drupalModule['version']);
                             $site->updateModule($siteModule['name'], $drupalModule);
                             $siteModule['isSecurity'] = TRUE;
                         }
                     }
                 }
                 if ($siteModule['isSecurity']) {
                     $hasCriticalIssue = TRUE;
                 }
             }
             $site->setLatestCoreVersion($coreVersions[0]['version'], $needsSecurityUpdate);
             $site->setIsNew(FALSE);
             $site->setHasCriticalIssue($hasCriticalIssue);
             $this->siteManager->updateDocument();
         }
     }
     $this->logger->addInfo('*** FINISHED Drupal Update Request Service ***');
 }