From 611d01788f787bd4c2451bb75c05f224174ff984 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Mon, 29 Dec 2014 14:29:31 +0100
Subject: [PATCH] Add setup related utility functions to
 ApplicationBootstrap.php

---
 .../Application/ApplicationBootstrap.php      | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/library/Icinga/Application/ApplicationBootstrap.php b/library/Icinga/Application/ApplicationBootstrap.php
index 86dcef8c4..92e97ba39 100644
--- a/library/Icinga/Application/ApplicationBootstrap.php
+++ b/library/Icinga/Application/ApplicationBootstrap.php
@@ -113,6 +113,13 @@ abstract class ApplicationBootstrap
      */
     protected $isWeb = false;
 
+    /**
+     * Whether Icinga Web 2 requires setup
+     *
+     * @type bool
+     */
+    protected $requiresSetup = false;
+
     /**
      * Constructor
      *
@@ -393,6 +400,40 @@ abstract class ApplicationBootstrap
         return $this;
     }
 
+    /**
+     * Load the setup module if Icinga Web 2 requires setup
+     *
+     * @return $this
+     */
+    protected function loadSetupModuleIfNecessary()
+    {
+        if (! @file_exists($this->config->resolvePath('config.ini'))) {
+            $this->requiresSetup = true;
+            $this->moduleManager->loadModule('setup');
+        }
+        return $this;
+    }
+
+    /**
+     * Get whether Icinga Web 2 requires setup
+     *
+     * @return bool
+     */
+    public function requiresSetup()
+    {
+        return $this->requiresSetup;
+    }
+
+    /**
+     * Get whether the setup token exists
+     *
+     * @return bool
+     */
+    public function setupTokenExists()
+    {
+        return @file_exists($this->config->resolvePath('setup.token'));
+    }
+
     /**
      * Setup default logging
      *