diff --git a/src/controllers/DiagnosticsController.php b/src/controllers/DiagnosticsController.php index b081e132..ab8e0f04 100755 --- a/src/controllers/DiagnosticsController.php +++ b/src/controllers/DiagnosticsController.php @@ -28,23 +28,13 @@ public function beforeAction($action): bool public function actionIndex(string $path): Response { - Craft::$app->getView()->registerAssetBundle(BlitzAsset::class); - Sprig::bootstrap(); Sprig::$core->components->setConfig(['requestClass' => 'busy']); - $siteId = null; - $site = Craft::$app->getRequest()->getParam('site'); - if ($site) { - $site = Craft::$app->getSites()->getSiteByHandle($site); - $siteId = $site ? $site->id : null; - } - if (empty($siteId)) { - $siteId = Craft::$app->getSites()->getCurrentSite()->id; - } + Craft::$app->getView()->registerAssetBundle(BlitzAsset::class); return $this->renderTemplate('blitz/_utilities/diagnostics/' . $path, [ - 'siteId' => $siteId, + 'siteId' => DiagnosticsHelper::getSiteId(), ]); } diff --git a/src/helpers/DiagnosticsHelper.php b/src/helpers/DiagnosticsHelper.php index 30cc12d4..782ec7f0 100644 --- a/src/helpers/DiagnosticsHelper.php +++ b/src/helpers/DiagnosticsHelper.php @@ -29,6 +29,21 @@ */ class DiagnosticsHelper { + public static function getSiteId(): ?int + { + $siteId = null; + $site = Craft::$app->getRequest()->getParam('site'); + if ($site) { + $site = Craft::$app->getSites()->getSiteByHandle($site); + $siteId = $site ? $site->id : null; + } + if (empty($siteId)) { + $siteId = Craft::$app->getSites()->getCurrentSite()->id; + } + + return $siteId; + } + public static function getPagesCount(int $siteId): int { return CacheRecord::find() diff --git a/src/utilities/DiagnosticsUtility.php b/src/utilities/DiagnosticsUtility.php index e40af53c..a5195610 100644 --- a/src/utilities/DiagnosticsUtility.php +++ b/src/utilities/DiagnosticsUtility.php @@ -8,6 +8,7 @@ use Craft; use craft\base\Utility; use putyourlightson\blitz\assets\BlitzAsset; +use putyourlightson\blitz\helpers\DiagnosticsHelper; /** * @since 4.10.0 @@ -51,18 +52,8 @@ public static function contentHtml(): string { Craft::$app->getView()->registerAssetBundle(BlitzAsset::class); - $siteId = null; - $site = Craft::$app->getRequest()->getParam('site'); - if ($site) { - $site = Craft::$app->getSites()->getSiteByHandle($site); - $siteId = $site ? $site->id : null; - } - if (empty($siteId)) { - $siteId = Craft::$app->getSites()->getCurrentSite()->id; - } - return Craft::$app->getView()->renderTemplate('blitz/_utilities/diagnostics/', [ - 'siteId' => $siteId, + 'siteId' => DiagnosticsHelper::getSiteId(), ]); } }