diff --git a/scripts/update_cli.php b/scripts/update_cli.php new file mode 100644 index 00000000..06dff0a6 --- /dev/null +++ b/scripts/update_cli.php @@ -0,0 +1,130 @@ +#!/usr/bin/env php +&1", $output, $return_var); + exec("git reset --hard origin/master 2>&1", $output2, $return_var2); + echo implode("\n", $output) . "\n" . implode("\n", $output2) . "\n"; + } else { + // Perform a standard update (git pull) + exec("git pull 2>&1", $output, $return_var); + + // Check if the repository is already up to date + if (strpos(implode("\n", $output), 'Already up to date.') === false) { + echo implode("\n", $output) . "\n"; + echo "Update successful\n"; + } else { + // If already up-to-date, don't show the update success message + echo implode("\n", $output) . "\n"; + } + } +} + +// If "update_db" is requested +if (isset($options['update_db'])) { + require_once('database_version.php'); + + $latest_db_version = LATEST_DATABASE_VERSION; + + // Fetch the current version from the database + $result = mysqli_query($mysqli, "SELECT config_current_database_version FROM settings LIMIT 1"); + $row = mysqli_fetch_assoc($result); + DEFINE("CURRENT_DATABASE_VERSION", $row['config_current_database_version']); + $old_db_version = $row['config_current_database_version']; + + // Now include the update logic + require_once('database_updates.php'); + + // After database_updates.php has done its job, fetch the updated current DB version again + $result = mysqli_query($mysqli, "SELECT config_current_database_version FROM settings LIMIT 1"); + $row = mysqli_fetch_assoc($result); + $new_db_version = $row['config_current_database_version']; + + if ($old_db_version !== $latest_db_version) { + echo "Database updated from version $old_db_version to $new_db_version.\n"; + echo "The latest database version is $latest_db_version.\n"; + } else { + echo "Database is already at the latest version ($latest_db_version). No updates were applied.\n"; + } +}