Exemplo n.º 1
0
 public function getSummary()
 {
     $resourceConfig = $this->data['resourceConfig'];
     if (isset($this->data['adminName'])) {
         $resourceConfig['username'] = $this->data['adminName'];
         if (isset($this->data['adminPassword'])) {
             $resourceConfig['password'] = $this->data['adminPassword'];
         }
     }
     $db = new DbTool($resourceConfig);
     try {
         $db->connectToDb();
         if (array_search(reset($this->data['tables']), $db->listTables(), true) === false) {
             if ($resourceConfig['username'] !== $this->data['resourceConfig']['username']) {
                 $message = sprintf(mt('setup', 'The database user "%s" will be used to setup the missing schema required by Icinga' . ' Web 2 in database "%s" and to grant access to it to a new login called "%s".'), $resourceConfig['username'], $resourceConfig['dbname'], $this->data['resourceConfig']['username']);
             } else {
                 $message = sprintf(mt('setup', 'The database user "%s" will be used to setup the missing' . ' schema required by Icinga Web 2 in database "%s".'), $resourceConfig['username'], $resourceConfig['dbname']);
             }
         } else {
             $message = sprintf(mt('setup', 'The database "%s" already seems to be fully set up. No action required.'), $resourceConfig['dbname']);
         }
     } catch (PDOException $_) {
         try {
             $db->connectToHost();
             if ($resourceConfig['username'] !== $this->data['resourceConfig']['username']) {
                 if ($db->hasLogin($this->data['resourceConfig']['username'])) {
                     $message = sprintf(mt('setup', 'The database user "%s" will be used to create the missing database' . ' "%s" with the schema required by Icinga Web 2 and to grant' . ' access to it to an existing login called "%s".'), $resourceConfig['username'], $resourceConfig['dbname'], $this->data['resourceConfig']['username']);
                 } else {
                     $message = sprintf(mt('setup', 'The database user "%s" will be used to create the missing database' . ' "%s" with the schema required by Icinga Web 2 and to grant' . ' access to it to a new login called "%s".'), $resourceConfig['username'], $resourceConfig['dbname'], $this->data['resourceConfig']['username']);
                 }
             } else {
                 $message = sprintf(mt('setup', 'The database user "%s" will be used to create the missing' . ' database "%s" with the schema required by Icinga Web 2.'), $resourceConfig['username'], $resourceConfig['dbname']);
             }
         } catch (Exception $_) {
             $message = mt('setup', 'No connection to database host possible. You\'ll need to setup the' . ' database with the schema required by Icinga Web 2 manually.');
         }
     }
     return '<h2>' . mt('setup', 'Database Setup', 'setup.page.title') . '</h2><p>' . $message . '</p>';
 }