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
This commit is contained in:
Clemens Schwaighofer
2022-03-18 19:49:26 +09:00
parent 35a7229158
commit 023ab6811d
5 changed files with 159 additions and 5 deletions

127
README.V6-Upgrade.md Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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