/** * 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); }