Bläddra i källkod

installer: Better logging

1Day 3 år sedan
förälder
incheckning
54b55c0f58
2 ändrade filer med 23 tillägg och 7 borttagningar
  1. 10 7
      public/install/forms.php
  2. 13 0
      public/install/functions.php

+ 10 - 7
public/install/forms.php

@@ -29,6 +29,7 @@ if (isset($_POST['checkDB'])) {
 
     $db = new mysqli($_POST["databasehost"], $_POST["databaseuser"], $_POST["databaseuserpass"], $_POST["database"], $_POST["databaseport"]);
     if ($db->connect_error) {
+        wh_log($db->connect_error);
         header("LOCATION: index.php?step=2&message=Could not connect to the Database");
         die();
     }
@@ -78,14 +79,12 @@ if (isset($_POST['feedDB'])) {
     }
     $logs .= run_console('php artisan storage:link');
 
-    $logsfile = fopen("logs.txt", "w") or die("Unable to open file!");
-    fwrite($logsfile, $logs);
-    fclose($logsfile);
+    wh_log($logs);
 
     if (strpos(getEnvironmentValue("APP_KEY"), 'base64') !== false) {
         header("LOCATION: index.php?step=3");
     } else {
-        header("LOCATION: index.php?step=2.5&message=There was an error. Please check install/logs.txt !");
+        header("LOCATION: index.php?step=2.5&message=There was an error. Please check the .txt file in install/log !");
     }
 
 
@@ -123,7 +122,8 @@ if (isset($_POST['checkSMTP'])) {
 
     $db = new mysqli(getEnvironmentValue("DB_HOST"), getEnvironmentValue("DB_USERNAME"), getEnvironmentValue("DB_PASSWORD"), getEnvironmentValue("DB_DATABASE"), getEnvironmentValue("DB_PORT"));
     if ($db->connect_error) {
-        header("LOCATION: index.php?step=4&message=Could not connect to the Database");
+        wh_log($db->connect_error);
+        header("LOCATION: index.php?step=4&message=Could not connect to the Database: ");
     die();
     }
     $values = [
@@ -181,6 +181,7 @@ if (isset($_POST['checkPtero'])) {
 
         $db = new mysqli(getEnvironmentValue("DB_HOST"), getEnvironmentValue("DB_USERNAME"), getEnvironmentValue("DB_PASSWORD"), getEnvironmentValue("DB_DATABASE"), getEnvironmentValue("DB_PORT"));
         if ($db->connect_error) {
+            wh_log($db->connect_error);
             header("LOCATION: index.php?step=5&message=Could not connect to the Database");
             die();
         }
@@ -188,6 +189,7 @@ if (isset($_POST['checkPtero'])) {
         if ($db->query($query1) && $db->query($query2)) {
             header("LOCATION: index.php?step=6");
         } else {
+            wh_log($db->error);
             header("LOCATION: index.php?step=5&message=Something went wrong when communicating with the Database!");
         }
     }
@@ -198,6 +200,7 @@ if (isset($_POST['checkPtero'])) {
 if (isset($_POST['createUser'])) {
     $db = new mysqli(getEnvironmentValue("DB_HOST"), getEnvironmentValue("DB_USERNAME"), getEnvironmentValue("DB_PASSWORD"), getEnvironmentValue("DB_DATABASE"), getEnvironmentValue("DB_PORT"));
     if ($db->connect_error) {
+        wh_log($db->connect_error);
         header("LOCATION: index.php?step=6&message=Could not connect to the Database");
         die();
     }
@@ -273,8 +276,8 @@ if (isset($_POST['createUser'])) {
     if ($db->query($query1)) {
         header("LOCATION: index.php?step=7");
     } else {
-
-        header("LOCATION: index.php?step=6&message=Something went wrong when communicating with the Database!");
+        wh_log($db->error);
+        header("LOCATION: index.php?step=6&message=Something went wrong when communicating with the Database");
 
     }
 

+ 13 - 0
public/install/functions.php

@@ -130,4 +130,17 @@ function run_console($command)
     return shell_exec($cmd);
 }
 
+function wh_log($log_msg)
+{
+    $log_filename = "log";
+    if (!file_exists($log_filename))
+    {
+        // create directory/folder uploads.
+        mkdir($log_filename, 0777, true);
+    }
+    $log_file_data = $log_filename.'/log_' . date('d-M-Y') . '.log';
+    // if you don't add `FILE_APPEND`, the file will be erased each time you add a log
+    file_put_contents($log_file_data, "[".date('h:i:s')."] " . $log_msg . "\n", FILE_APPEND);
+}
+
 ?>