@@ -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 }
0 commit comments