Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using MariaDB and ENV vars over settings.php, installer fails and instead throws error #504

Open
sahal opened this issue Jul 21, 2024 · 0 comments

Comments

@sahal
Copy link
Contributor

sahal commented Jul 21, 2024

If you use ENV vars rather than settings.php, Webcalendar will try to read from a table webcal_config, rather than launching the installer. When you launch http://localhost:8080/, you're presented with the following in your browser:

Error
Error executing query.

Table 'webcalendar_php8.webcal_config' doesn't exist
SELECT cal_value FROM webcal_config WHERE cal_setting = 'WEBCAL_PROGRAM_VERSION'

If you hit http://localhost:8080/install/ directly, however, you will be able to proceed with the install normally.


Test failure

Because #475 has yet to be merged, this particular change cannot be tested stand alone. To test the failure (and fix...), you can use my branch max951_plus_compose_plus_try_catch_reverted, which merges max951's fixes with mine.

We can test it failing first using my remote and branch.

git remote add sahal [email protected]:sahal/webcalendar.git
git fetch sahal --depth 1
git switch max951_plus_compose_plus_try_catch_reverted

To replicate this, you'll notice that I'm using ENV vars rather than settings.php as WEBCALENDAR_USE_ENV is set to true in the compose file.

./docker/docker-compose-php8-dev.yml:45:    # sees WEBCALENDAR_USE_ENV is set to true, it will use these env vars and ignore settings.php.
./docker/docker-compose-php8-dev.yml:50:      - WEBCALENDAR_USE_ENV=true
./docker/docker-compose-php8-dev.yml:72:      - WEBCALENDAR_USE_ENV=true

I've also commented out the part of the compose file that would install the required SQL (include/sql/tables-msql.sql). (This is a proposed change in #503)

Note: you'll have to make sure that your mysql docker volume created with docker-compose is removed -- which might mean cleaning up your stopped containers.

$ (ins)sahal@shakuntala[~/code/webcalendar]$ cat docker/docker-compose-php8-dev.yml 

. . .

      # install sql at start
      # To test the installer's built-in installer, comment this out
#      - type: bind
#        source: ../install/sql/tables-mysql.sql
#        target: /docker-entrypoint-initdb.d/tables-mysql.sql

Now, run docker-compose (or podman-compose as I am doing here):

(ins)sahal@shakuntala[~/code/webcalendar]$ podman-compose -f docker/docker-compose-php8-dev.yml up

Test Fix

Again, because #475 has yet to be merged, this particular change cannot be tested stand alone. To test the fix, you can use my branch max951_plus_compose_plus_try_catch, which merges max951's fixes with mine.

We can test the fix using my remote and branch.

git remote add sahal [email protected]:sahal/webcalendar.git
git fetch sahal --depth 1
git switch max951_plus_compose_plus_try_catch

Note: you'll have to make sure that your mysql docker volume created with docker-compose is removed -- which might mean cleaning up your stopped containers.

(cmd)sahal@shakuntala[~/code/webcalendar-clean]$ podman-compose -f docker/docker-compose-php8-dev.yml up

Diff of the fix

I am not sure how you want to fix this. I am not a php developer. I noticed that you were using try/catch blocks elsewhere and this is what I did.

(ins)sahal@shakuntala[~/code/webcalendar/docker]$ git diff HEAD~2 HEAD -- ../includes/config.php | pbcopy

diff --git a/includes/config.php b/includes/config.php
index 3b209349..8d6c2e72 100644
--- a/includes/config.php
+++ b/includes/config.php
@@ -164,6 +164,7 @@ function get_full_include_path($filename)
  */
 function do_config($callingFromInstall=false)
 {
+
   global $db_database, $db_debug, $db_host, $db_login, $db_password, $db_persistent,
     $db_type, $ignore_user_case, $NONUSER_PREFIX, $phpdbiVerbose, $PROGRAM_DATE,
     $PROGRAM_NAME, $PROGRAM_URL, $PROGRAM_VERSION, $readonly, $run_mode, $settings,
@@ -347,10 +348,15 @@ function do_config($callingFromInstall=false)
   $c = @dbi_connect($db_host, $db_login, $db_password, $db_database, false);
 
   if ($c && !$callingFromInstall) {
-    $rows = dbi_get_cached_rows('SELECT cal_value FROM webcal_config
-      WHERE cal_setting = \'WEBCAL_PROGRAM_VERSION\'');
-
-    //echo "<pre>"; print_r($rows); echo "</pre>"; exit;
+    try {
+      $rows = dbi_get_cached_rows('SELECT cal_value FROM webcal_config
+        WHERE cal_setting = \'WEBCAL_PROGRAM_VERSION\'',[],false,false);
+    } catch (Exception $ex) {
+      echo $e->getMessage();
+      error_log($e->getMessage());
+      header($locateStr);
+      exit;
+    }
     if (!$rows || empty($rows) || empty($rows[0])) {
       header($locateStr);
       exit;

If you'd like, I can put this in a clean branch (without max951's proposed changes from #475, and sans my docker updates from #503 -- in case you chose not to accept them).


Debug backtrace for funsies

I also added the following to the top of the do_config function in includes/config.php for funsies.

  echo '<pre>';
  print_r(debug_backtrace());
  echo '</pre>';

Here's the resultant file: debug_backtrace_do_config.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant