Skip to content

Commit 42e4753

Browse files
committed
Fixed install failures
1 parent 1261e9b commit 42e4753

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

app/admin/mail/test-mail.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
# fetch mailer settings
2020
$mail_settings = $Admin->fetch_object("settingsMail", "id", 1);
2121

22+
# verify admin mail and name
23+
if (strlen($mail_settings->mAdminMail)==0 || strlen($mail_settings->mAdminName)==0) {
24+
$Result->show("danger", _("Mail settings are missing. Please set admin mail and name!"), true);
25+
}
2226

2327

2428
# initialize mailer

app/admin/users/edit-notify.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
# fetch mailer settings
1919
$mail_settings = $Admin->fetch_object("settingsMail", "id", 1);
2020

21+
# verify admin mail and name
22+
if (strlen($mail_settings->mAdminMail)==0 || strlen($mail_settings->mAdminName)==0) {
23+
$Result->show("danger", _("Cannot send mail, mail settings are missing. Please set them under administration > Mail Settings !"), true);
24+
}
2125

2226
# initialize mailer
2327
$phpipam_mail = new phpipam_mail($User->settings, $mail_settings);
@@ -73,7 +77,6 @@
7377
$content = $phpipam_mail->generate_message (implode("\r\n", $content));
7478
$content_plain = implode("\r\n",$content_plain);
7579

76-
7780
# try to send
7881
try {
7982
$phpipam_mail->Php_mailer->setFrom($mail_settings->mAdminMail, $mail_settings->mAdminName);

functions/classes/class.Install.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ public function __construct (Database_PDO $Database) {
4444
# Log object
4545
try { $this->Database->connect();
4646
} catch ( Exception $e ) {
47-
47+
$err = true;
4848
}
49-
if(!isset($e))
50-
$this->Log = new Logging ($this->Database);
5149
}
5250

5351

@@ -99,6 +97,7 @@ public function install_database ($rootuser, $rootpass, $drop_database = false,
9997

10098
# return true, if some errors occured script already died! */
10199
sleep(1);
100+
$this->Log = new Logging ($this->Database);
102101
$this->Log->write( "Database installation", "Database installed successfully. Version ".VERSION.".".REVISION." installed", 1 );
103102
return true;
104103
}
@@ -156,22 +155,25 @@ private function install_database_execute () {
156155
$query = file_get_contents("../../db/SCHEMA.sql");
157156

158157
# formulate queries
159-
$queries = explode(";\n", $query);
158+
$queries = array_filter(explode(";\n", $query));
160159

161160
# execute
162161
foreach($queries as $q) {
163-
try { $this->Database_root->runQuery($q.";"); }
164-
catch (Exception $e) {
165-
//unlock tables
166-
$this->Database_root->runQuery("UNLOCK TABLES;");
167-
//drop database
168-
try { $this->Database_root->runQuery("drop database if exists ". $this->db['name'] .";"); }
162+
//length check
163+
if (strlen($q)>0) {
164+
try { $this->Database_root->runQuery($q.";"); }
169165
catch (Exception $e) {
170-
$this->Result->show("danger", 'Cannot set permissions for user '. $db['user'] .': '.$e->getMessage(), true);
166+
//unlock tables
167+
$this->Database_root->runQuery("UNLOCK TABLES;");
168+
//drop database
169+
try { $this->Database_root->runQuery("drop database if exists ". $this->db['name'] .";"); }
170+
catch (Exception $e) {
171+
$this->Result->show("danger", 'Cannot set permissions for user '. $db['user'] .': '.$e->getMessage(), true);
172+
}
173+
//print error
174+
$this->Result->show("danger", "Cannot install sql SCHEMA file: ".$e->getMessage()."<br>query that failed: <pre>$q</pre>", false);
175+
$this->Result->show("info", "Database dropped", false);
171176
}
172-
//print error
173-
$this->Result->show("danger", "Cannot install sql SCHEMA file: ".$e->getMessage()."<br>query that failed: <pre>$q</pre>", false);
174-
$this->Result->show("info", "Database dropped", false);
175177
}
176178
}
177179
}
@@ -369,6 +371,7 @@ private function upgrade_database_execute () {
369371
foreach($queries as $query) {
370372
try { $this->Database->runQuery($query); }
371373
catch (Exception $e) {
374+
$this->Log = new Logging ($this->Database);
372375
# write log
373376
$this->Log->write( "Database upgrade", $e->getMessage()."<br>query: ".$query, 2 );
374377
# fail
@@ -379,6 +382,7 @@ private function upgrade_database_execute () {
379382

380383
# all good, print it
381384
sleep(1);
385+
$this->Log = new Logging ($this->Database);
382386
$this->Log->write( "Database upgrade", "Database upgraded from version ".$this->settings->version." to version ".VERSION.".".REVISION, 1 );
383387
return true;
384388
}

functions/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* set latest version */
33
define("VERSION", "1.19"); //version changes if database structure changes
44
/* set latest revision */
5-
define("REVISION", "020"); //revision always changes, verision only if database structure changes
5+
define("REVISION", "022"); //revision always changes, verision only if database structure changes
66
/* set last possible upgrade */
77
define("LAST_POSSIBLE", "1.1"); //minimum required version to be able to upgrade
88
?>

0 commit comments

Comments
 (0)