From 023ab6811d77ed0f0f1506b3d71b9bfc87ebc2b5 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 18 Mar 2022 19:49:26 +0900 Subject: [PATCH] Add Upgrade to V6 readme file, other minor fixes typos in config file deprecate read env file function, use class instead add read/write menu_flag in Class\Backend, further updates in later versions --- README.V6-Upgrade.md | 127 +++++++++++++++++++++++++++ www/configs/config.master.php | 4 +- www/configs/read_env_file.php | 6 ++ www/lib/CoreLibs/Admin/Backend.php | 25 +++++- www/lib/CoreLibs/Get/ReadEnvFile.php | 2 +- 5 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 README.V6-Upgrade.md diff --git a/README.V6-Upgrade.md b/README.V6-Upgrade.md new file mode 100644 index 00000000..533124de --- /dev/null +++ b/README.V6-Upgrade.md @@ -0,0 +1,127 @@ +# Upgrade to Version 6 + + * remove old `lib/CoreLibs` and copy the new over + * copy `config/config.php` + * install composer if not installed `composer init` and `composer install` + * update composer.json + ```json +"autoload": { + "classmap": [ + "lib/" + ] +}, +``` +Run to update autoloader list +```sh +composer dump-autoload +``` + + * copy `includes/edit_base.inc` + * add session start in the top header block where the `header()` calls are +```php +// start session +CoreLibs\Create\Session::startSession(); +``` + * update all header calls if needed to add new log type call + ```php +// create logger +$log = new CoreLibs\Debug\Logging([ + 'log_folder' => BASE . LOG, + 'file_id' => LOG_FILE_ID, + 'print_file_date' => true, + 'debug_all' => $DEBUG_ALL ?? false, + 'echo_all' => $ECHO_ALL ?? false, + 'print_all' => $PRINT_ALL ?? false, +]); +``` + * add a db class +```php +// db config with logger +$db = new CoreLibs\DB\IO(DB_CONFIG, $log); +``` + * login class needs to have db and logger added +```php +// login & page access check +$login = new CoreLibs\ACL\Login($db, $log); +``` +* admin backend also needs logger +```php +$cms = new CoreLibs\Admin\Backend($db, $log); +``` +* update and `$cms` or similar calls so db is in `$cms->db->...` and log are in `$cms->log->...` +* update all `config.*.php` files where needed +* check config.master.php for `BASE_NAME` and `G_TITLE` and set them in the `.env` file so the `config.master.php` can be copied as os +* If not doable, see changed below in `config.master.php` must remove old auto loder and `FLASH` constant at least +**REMOVE:** +```php +/************* AUTO LOADER *******************/ +// read auto loader +require BASE . LIB . 'autoloader.php'; +``` +**UPDATE:** +```php +// SSL host name +// define('SSL_HOST', $_ENV['SSL_HOST'] ?? ''); +``` +```php +// define full regex +define('PASSWORD_REGEX', "/^" + . (defined('PASSWORD_LOWER') ? PASSWORD_LOWER : '') + . (defined('PASSWORD_UPPER') ? PASSWORD_UPPER : '') + . (defined('PASSWORD_NUMBER') ? PASSWORD_NUMBER : '') + . (defined('PASSWORD_SPECIAL') ? PASSWORD_SPECIAL : '') + . "[A-Za-z\d" . PASSWORD_SPECIAL_RANGE . "]{" . PASSWORD_MIN_LENGTH . "," . PASSWORD_MAX_LENGTH . "}$/"); +``` +```php +/************* LAYOUT WIDTHS *************/ +define('PAGE_WIDTH', '100%'); +define('CONTENT_WIDTH', '100%'); +``` +```php +/************* OVERALL CONTROL NAMES *************/ +// BELOW has HAS to be changed +// base name for all session and log names +// only alphanumeric characters, strip all others +define('BASE_NAME', preg_replace('/[^A-Za-z0-9]/', '', $_ENV['BASE_NAME'] ?? '')); +``` +```php +// BAIL ON MISSING DB CONFIG: +// we have either no db selction for this host but have db config entries +// or we have a db selection but no db config as array or empty +// or we have a selection but no matching db config entry +if ( + (!isset($SITE_CONFIG[HOST_NAME]['db_host']) && count($DB_CONFIG)) || + (isset($SITE_CONFIG[HOST_NAME]['db_host']) && + // missing DB CONFIG + ((is_array($DB_CONFIG) && !count($DB_CONFIG)) || + !is_array($DB_CONFIG) || + // has DB CONFIG but no match + empty($DB_CONFIG[$SITE_CONFIG[HOST_NAME]['db_host']])) + ) +) { + echo 'No matching DB config found for: "' . HOST_NAME . '". Contact Administrator'; + exit; +} +``` +```php +```php +/************* GENERAL PAGE TITLE ********/ +define('G_TITLE', $_ENV['G_TITLE'] ?? ''); +``` +* move all login passweords into the `.env` file in the `configs/` folder +in the `.env` file +``` +DB_NAME.TEST=some_database +... +``` +In the config then +```php +'db_name' => $_ENV['DB_NAME.TEST'] ?? '', +``` +* copy `layout/admin/javascript/edit.jq.js` +* check other javacsript files if needed (`edit.jq.js`) + +## IMPORTANT NOTE + +If no upgrade to V5 was done all calls that refered to `CoreLibs\Basic` will now fail and no longer be warned as deprected +See the old file for all methods and where they have moved diff --git a/www/configs/config.master.php b/www/configs/config.master.php index fa562888..597d52dc 100644 --- a/www/configs/config.master.php +++ b/www/configs/config.master.php @@ -245,9 +245,9 @@ if ( } // define the db config set name, the db config and the db schema define('DB_CONFIG_NAME', $SITE_CONFIG[HOST_NAME]['db_host']); -define('DB_CONFIG', isset($DB_CONFIG[DB_CONFIG_NAME]) ?? []); +define('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME] ?? []); // because we can't change constant, but we want to for db debug flag -$GLOBALS['DB_CONIFG'] = DB_CONFIG; +$GLOBALS['DB_CONFIG'] = DB_CONFIG; // define('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']); // define('DB_CONFIG_OTHER', SITE_CONFIG[$HOST_NAME]['db_host_other']); // override for login and global schemas diff --git a/www/configs/read_env_file.php b/www/configs/read_env_file.php index c3c6006d..c1f466ca 100644 --- a/www/configs/read_env_file.php +++ b/www/configs/read_env_file.php @@ -25,9 +25,15 @@ declare(strict_types=1); * 1 for file loadable, but no data inside * 2 for file not readable * 3 for file not found + * @deprecated V6 Use \CoreLibs\Get\ReadEnvFile::readEnvFile() */ function readEnvFile(string $path = __DIR__, string $env_file = '.env'): int { + trigger_error( + 'Method readEnvFile() is deprecated, use ' + . '\CoreLibs\Get\ReadEnvFile::readEnvFile()', + E_USER_DEPRECATED + ); // default -1; $status = -1; $env_file_target = $path . DIRECTORY_SEPARATOR . $env_file; diff --git a/www/lib/CoreLibs/Admin/Backend.php b/www/lib/CoreLibs/Admin/Backend.php index 809e3b11..f03df7ce 100644 --- a/www/lib/CoreLibs/Admin/Backend.php +++ b/www/lib/CoreLibs/Admin/Backend.php @@ -112,8 +112,8 @@ class Backend // CONSTRUCTOR / DECONSTRUCTOR |====================================> /** * main class constructor - * @param \CoreLibs\DB\IO $db Database connection class - * @param \CoreLibs\Debug\Logging $log Logging class, default set if not set + * @param \CoreLibs\DB\IO $db Database connection class + * @param \CoreLibs\Debug\Logging $log Logging class * @param \CoreLibs\Language\L10n|null $l10n l10n language class * if null, auto set */ @@ -276,6 +276,27 @@ class Backend $this->db->dbExec($q, 'NULL'); } + /** + * Set the menu show flag + * @param string|int $menu_show_flag + * @return string|int + */ + public function adbSetMenuShowFlag($menu_show_flag) + { + // must be string or int + $this->menu_show_flag = $menu_show_flag; + return $this->menu_show_flag; + } + + /** + * Return the menu show flag + * @return string|int + */ + public function adbGetMenuShowFlag() + { + return $this->menu_show_flag; + } + /** * menu creater (from login menu session pages) * @param int $flag visible flag trigger diff --git a/www/lib/CoreLibs/Get/ReadEnvFile.php b/www/lib/CoreLibs/Get/ReadEnvFile.php index ae759eb7..69a5881e 100644 --- a/www/lib/CoreLibs/Get/ReadEnvFile.php +++ b/www/lib/CoreLibs/Get/ReadEnvFile.php @@ -54,7 +54,7 @@ class ReadEnvFile $var = $matches[1]; $value = $matches[2]; $quotes = $matches[3]; - // wirte only if env is not set yet, and write only the first time + // write only if env is not set yet, and write only the first time if (empty($_ENV[$var])) { if (!empty($quotes)) { // match greedy for first to last so we move any " if there are