Compare commits

...

23 Commits

Author SHA1 Message Date
Clemens Schwaighofer
c35d3c9324 Remove constant from deprecated ReadEnvFile class (now dotEnv) 2022-06-14 16:27:00 +09:00
Clemens Schwaighofer
e92a682a8c ACL\Login phpUnit tets update for ajax page tests 2022-06-14 16:24:17 +09:00
Clemens Schwaighofer
ea07e4b95b Update ACL\Login with internal ajax_page flag override
Also ajax flag return method
2022-06-14 16:23:24 +09:00
Clemens Schwaighofer
88178cb08d Rename class ReadEnvFile to DotEnv and add test cases
previous named Get\ReadEnvFile is no Get\DotEnv, static method is the
same.
Update for not parsing comments at the end of a line if the line was not
in quotes. Strips everything after comment mark and also right trims any
trailing spaces

Old:
FOO=Test # Comment -> $_ENV['FOO'] = "Test # Comment"

New:
FOO=Test # Comment -> $_ENV['FOO'] = "Test"

Add phpUnit tests for DotEnv class.
Update config.php with new class name

The old class name exists and is markted as deprecated until next major
release
2022-06-09 09:05:48 +09:00
Clemens Schwaighofer
5d98be06be Code clean up for phan and phpstan 2022-06-07 18:16:23 +09:00
Clemens Schwaighofer
183cadb0fd Class ACL\Login update with phpunit testing
Move logic from constructor to separate function
Add more public access methods for internal variable access (password
min length settings, error login code, error login string error)
All error messages are declared in constructor with wrapper function to
create html error string for template creation
Add wrapper function for exit/abort and page name read for easier mocking
in testing
Fixes for multi login main function caller and cached query problem: do
not cache query for login
Add reverse default access list SESSION variable and public readers
Update logout with unset of full SESSION array to empty, use external
session class for all session calls. Also unset euid on logout
2022-06-07 18:05:50 +09:00
Clemens Schwaighofer
2067a6fe1d Config master SSL site detection update 2022-06-07 18:05:34 +09:00
Clemens Schwaighofer
f5b6c639fb Fix primary key base number after more inserts are done 2022-06-03 11:13:35 +09:00
Clemens Schwaighofer
cde29c0362 Update DB\IO dbReturn and update connected tests
Switch the code point for these below for logic reasons
CLEAR_CACHE 1 => 2 (clear cache AFTER END read)
READ_NEW 2 => 1 (clear cache BEFORE first read)

in dbReturn cursor ext array:
remove firstcall entry because it is not needed
add new:
- cache_flag: $cache method call number
- assoc_flag: the assoc read flag from the method call
- cached: if there is data cached in the cursor ext array this is true
- finished: true if the last read was false
- db_read_finished: if true the db read has fiinished (read_rows =
  num_rows)
- read_finished: if true the current read (cache or db) via pos =
  num_rows is done
- log_pos: sequential number for each call with the same query hash
- log: array with current actions done in the last read

Update DB IO class test with all cursor, cursor ext, read single step,
read in loop, read again, etc tests
2022-06-03 11:03:06 +09:00
Clemens Schwaighofer
10234000b7 ACL\Login test class add
- db create shell script for ACL\Login to reset full database to known
  good stated
- basic tests written to check core login class
2022-06-02 18:14:58 +09:00
Clemens Schwaighofer
a63a50a412 add tests for dbReturn only
dbReturn special call test file, update main db test file

Main class_test file with links update
2022-06-02 16:38:10 +09:00
Clemens Schwaighofer
59da10b649 Session class update with session destroy / start wrapper
session start wrapper as protected method

session destroy wrapper with _SESSION array unset
2022-06-02 16:35:40 +09:00
Clemens Schwaighofer
b714de498f Add print boolean stand allone support function
in the Debug\Support add printBool to print out bool as string.
Same as printAsString with bool alone but you can control prefix name,
and true/false string names

Add printArray alias to prAr
2022-06-02 16:31:35 +09:00
Clemens Schwaighofer
aa11937ab2 Update Running time for better high resolution timer
Instead of ending with the second hr timer call, we print out difference
to the last one.
Add new method to print out from start time difference and add a reset
method
2022-06-02 16:30:22 +09:00
Clemens Schwaighofer
d64d5f081c Add Class for Memory Usage tracking 2022-06-02 16:26:55 +09:00
Clemens Schwaighofer
3085b52714 Update PHPdoc parts
Add empty line between description and first @param entry.
Some other minor comment layout and text fixes
2022-06-02 16:07:38 +09:00
Clemens Schwaighofer
9949a5ef7f Update core edit_* tables with various fixes
- import script with write to file option
- fix file names for functions
- add generic (non edit tables) for only set date, set uid or combine
- fix edit table edit_language insert data
- all trigger create remove the drop on exists, as in the flow the trigger will never exists
2022-05-31 20:17:32 +09:00
Clemens Schwaighofer
74ba935e96 Comment info update in L10n class 2022-05-27 15:01:30 +09:00
Clemens Schwaighofer
39a62ed59d Update phpunit tests for Debug\Logging 2022-05-26 15:20:19 +09:00
Clemens Schwaighofer
1379cf1519 Add print bool in logging class 2022-05-26 14:31:48 +09:00
Clemens Schwaighofer
2d15b78d21 Composer update 2022-05-26 09:52:37 +09:00
Clemens Schwaighofer
92ebdb4b9e Update session class and write session clas tester, update DB\IO Tester
DB\IO Tester now has correct testing for pgVersion string compare. Uses
mocked pgVersion return for this

Session class update with full magic set/get or method set/get for
_SESSION var. Also added full testing for this
2022-05-26 09:27:57 +09:00
Clemens Schwaighofer
a523a4e831 ACL\Login class update for phpstan check 2022-05-24 16:50:37 +09:00
111 changed files with 6978 additions and 957 deletions

View File

@@ -8,6 +8,9 @@ for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
echo "Translate language ${file}";
locale=$(echo "${file}" | cut -d "-" -f 1);
domain=$(echo "${file}" | cut -d "-" -f 2);
if [ ! -d "${base_folder}/includes/locale/${locale}/LC_MESSAGES/" ]; then
mkdir -p "${base_folder}/includes/locale/${locale}/LC_MESSAGES/";
fi;
msgfmt -o ${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo ${base_folder}../4dev/locale/${locale}-${domain}.po;
done;

View File

@@ -1,9 +1,9 @@
# this list only holds edit_* related table data
# functions
function/set_uid.sql
function/set_generic.sql
function/random_string.sql
function/set_edit_generic.sql
function/edit_set_access_uid.sql
function/edit_access_set_uid.sql
function/edit_group_set_uid.sql
function/edit_log_partition_insert.sql
# generic tables
table/edit_temp_files.sql

View File

@@ -6,20 +6,25 @@
#exit;
# if flagged 'y' then it will ask after each import to continue
development='y';
development='n';
# do not import anything, just order flow output
test='n';
input='';
# write to file do not write to DB directly
write='y';
# database connection info
db='<db name>';
host='<db host>';
user='<db user>';
schema="public";
schemas='public';
export PGPASSWORD='';
# log files
error_file="log/error";
output_file="log/output";
error_file='log/error';
output_file='log/output';
data_file='database_create_data.sql';
if [ "$write" = 'y' ]; then
rm -f "${data_file}";
fi;
if [ ! -f ORDER ]; then
echo "Could not find ORDER file";
exit;
@@ -40,26 +45,37 @@ while read file <&3; do
if [ -f "$file" ]; then
for path in "$schemas"; do
echo "[+] WORK ON '${file}' @ '${path}'";
# skip all on test
if [ "$test" = 'n' ]; then
echo "=== START [$file] ===>" >> ${error_file};
psql -U ${user} -h ${host} -f "${file}" ${db} 1>> ${output_file} 2>> ${error_file}
echo "=== END [$file] ===>" >> ${error_file};
fi;
if [ "$development" = "y" ]; then
echo "Press 'y' to move to next. Press 'r' to reload last file. ^c to abort";
fi;
while [ "$development" = "y" ] && [ "$input" != "y" ]; do
read -ep "Continue (y|r|^c): " input;
if [ "$input" = "r" ]; then
echo "Reload File '${file}' ...";
if [ "$test" = 'n' ]; then
echo "=== START RELOAD [$file] ===>" >> ${error_file};
psql -U ${user} -h ${host} -f "${file}" ${db} 1>> ${output_file} 2>> ${error_file}
echo "=== END RELOAD [$file] ===>" >> ${error_file};
# write to file
if [ "$write" = 'y' ]; then
echo "-- START: ${file}" >> ${data_file};
cat "${file}" >> ${data_file};
echo "-- END: ${file}" >> ${data_file};
else
# write to DB
echo "=== START [$file] ===>" >> ${error_file};
psql -U ${user} -h ${host} -f "${file}" ${db} 1>> ${output_file} 2>> ${error_file}
echo "=== END [$file] ===>" >> ${error_file};
# next wait for dev
if [ "$development" = "y" ]; then
echo "Press 'y' to move to next. Press 'r' to reload last file. ^c to abort";
fi;
# loop run for reload on failed
while [ "$development" = "y" ] && [ "$input" != "y" ]; do
read -ep "Continue (y|r|^c): " input;
if [ "$input" = "r" ]; then
echo "Reload File '${file}' ...";
if [ "$test" = 'n' ]; then
echo "=== START RELOAD [$file] ===>" >> ${error_file};
psql -U ${user} -h ${host} -f "${file}" ${db} 1>> ${output_file} 2>> ${error_file}
echo "=== END RELOAD [$file] ===>" >> ${error_file};
fi;
fi;
done;
input='';
fi;
done;
input='';
fi;
done;
elif [[ ${file::1} != "#" ]]; then
echo "[!] COULD NOT FIND FILE: '${file}'";

View File

@@ -68,10 +68,11 @@ INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Visitor', 'B0C4B3
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('User', '1E789E', 1);
-- edit language
-- short_name = locale without encoding
-- iso_name = encoding
DELETE FROM edit_language;
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('English', 'en_US', 'UTF-8', 1, 1, 1);
INSERT INTO edit_language (long_name, short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('Japanese', 'ja_JP', 'UTF-8', 2, 1, 0);
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('Japanese', 'ja_JP', 'UTF-8', 2, 1, 0);
-- edit group
DELETE FROM edit_group;
@@ -130,7 +131,7 @@ INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_
-- inserts admin user so basic users can be created
DELETE FROM edit_user;
INSERT INTO edit_user (username, password, enabled, debug, db_debug, email, protected, admin, edit_language_id, edit_group_id, edit_scheme_id, edit_access_right_id) VALUES ('admin', 'admin', 1, 1, 1, '', 1, 1,
(SELECT edit_language_id FROM edit_language WHERE short_name = 'en'),
(SELECT edit_language_id FROM edit_language WHERE short_name = 'en_US'),
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_scheme_id FROM edit_scheme WHERE name = 'Admin'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')

View File

@@ -0,0 +1,941 @@
-- START: function/random_string.sql
-- create random string with length X
CREATE FUNCTION random_string(randomLength int)
RETURNS text AS $$
SELECT array_to_string(
ARRAY(
SELECT substring(
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
trunc(random() * 62)::int + 1,
1
)
FROM generate_series(1, randomLength) AS gs(x)
),
''
)
$$ LANGUAGE SQL
RETURNS NULL ON NULL INPUT
VOLATILE; -- LEAKPROOF;-- END: function/random_string.sql
-- START: function/set_edit_generic.sql
-- adds the created or updated date tags
CREATE OR REPLACE FUNCTION set_edit_generic() RETURNS TRIGGER AS '
DECLARE
random_length INT = 12; -- that should be long enough
BEGIN
IF TG_OP = ''INSERT'' THEN
NEW.date_created := ''now'';
NEW.cuid := random_string(random_length);
ELSIF TG_OP = ''UPDATE'' THEN
NEW.date_updated := ''now'';
END IF;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';
-- END: function/set_edit_generic.sql
-- START: function/edit_access_set_uid.sql
-- add uid add for edit_access table
CREATE OR REPLACE FUNCTION set_edit_access_uid() RETURNS TRIGGER AS
$$
DECLARE
myrec RECORD;
v_uid VARCHAR;
BEGIN
-- skip if NEW.name is not set
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
-- use NEW.name as base, remove all spaces
-- name data is already unique, so we do not need to worry about this here
v_uid := REPLACE(NEW.name, ' ', '');
IF TG_OP = 'INSERT' THEN
-- always set
NEW.uid := v_uid;
ELSIF TG_OP = 'UPDATE' THEN
-- check if not set, then set
SELECT INTO myrec t.* FROM edit_access t WHERE edit_access_id = NEW.edit_access_id;
IF FOUND THEN
NEW.uid := v_uid;
END IF;
END IF;
END IF;
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';
-- END: function/edit_access_set_uid.sql
-- START: function/edit_group_set_uid.sql
-- add uid add for edit_group table
CREATE OR REPLACE FUNCTION set_edit_group_uid() RETURNS TRIGGER AS
$$
DECLARE
myrec RECORD;
v_uid VARCHAR;
BEGIN
-- skip if NEW.name is not set
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
-- use NEW.name as base, remove all spaces
-- name data is already unique, so we do not need to worry about this here
v_uid := REPLACE(NEW.name, ' ', '');
IF TG_OP = 'INSERT' THEN
-- always set
NEW.uid := v_uid;
ELSIF TG_OP = 'UPDATE' THEN
-- check if not set, then set
SELECT INTO myrec t.* FROM edit_group t WHERE edit_group_id = NEW.edit_group_id;
IF FOUND THEN
NEW.uid := v_uid;
END IF;
END IF;
END IF;
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';
-- END: function/edit_group_set_uid.sql
-- START: function/edit_log_partition_insert.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2018-07-17
-- DESCRIPTION:
-- partition the edit_log table by year
-- auto creates table if missing, if failure writes to overflow table
-- HISTORY:
CREATE OR REPLACE FUNCTION edit_log_insert_trigger ()
RETURNS TRIGGER AS
$$
DECLARE
start_date DATE := '2010-01-01';
end_date DATE;
timeformat TEXT := 'YYYY';
selector TEXT := 'year';
base_table TEXT := 'edit_log';
_interval INTERVAL := '1 ' || selector;
_interval_next INTERVAL := '2 ' || selector;
table_name TEXT;
-- compare date column
compare_date DATE := NEW.event_date;
compare_date_name TEXT := 'event_date';
-- the create commands
command_create_table TEXT := 'CREATE TABLE IF NOT EXISTS {TABLE_NAME} (CHECK({COMPARE_DATE_NAME} >= {START_DATE} AND {COMPARE_DATE_NAME} < {END_DATE})) INHERITS ({BASE_NAME})';
command_create_primary_key TEXT := 'ALTER TABLE {TABLE_NAME} ADD PRIMARY KEY ({BASE_TABLE}_id)';
command_create_foreign_key_1 TEXT := 'ALTER TABLE {TABLE_NAME} ADD CONSTRAINT {TABLE_NAME}_euid_fkey FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL';
command_create_trigger_1 TEXT = 'CREATE TRIGGER trg_{TABLE_NAME} BEFORE INSERT OR UPDATE ON {TABLE_NAME} FOR EACH ROW EXECUTE PROCEDURE set_edit_generic()';
BEGIN
-- we are in valid start time area
IF (NEW.event_date >= start_date) THEN
-- current table name
table_name := base_table || '_' || to_char(NEW.event_date, timeformat);
BEGIN
EXECUTE 'INSERT INTO ' || quote_ident(table_name) || ' SELECT ($1).*' USING NEW;
-- if insert failed because of missing table, create new below
EXCEPTION
WHEN undefined_table THEN
-- another block, so in case the creation fails here too
BEGIN
-- create new table here + all indexes
start_date := date_trunc(selector, NEW.event_date);
end_date := date_trunc(selector, NEW.event_date + _interval);
-- creat table
EXECUTE format(REPLACE( -- end date
REPLACE( -- start date
REPLACE( -- compare date name
REPLACE( -- base name (inherit)
REPLACE( -- table name
command_create_table,
'{TABLE_NAME}',
table_name
),
'{BASE_NAME}',
base_table
),
'{COMPARE_DATE_NAME}',
compare_date_name
),
'{START_DATE}',
quote_literal(start_date)
),
'{END_DATE}',
quote_literal(end_date)
));
-- create all indexes and triggers
EXECUTE format(REPLACE(
REPLACE(
command_create_primary_key,
'{TABLE_NAME}',
table_name
),
'{BASE_TABLE}',
base_table
));
-- FK constraints
EXECUTE format(REPLACE(command_create_foreign_key_1, '{TABLE_NAME}', table_name));
-- generic trigger
EXECUTE format(REPLACE(command_create_trigger_1, '{TABLE_NAME}', table_name));
-- insert try again
EXECUTE 'INSERT INTO ' || quote_ident(table_name) || ' SELECT ($1).*' USING NEW;
EXCEPTION
WHEN OTHERS THEN
-- if this faled, throw it into the overflow table (so we don't loose anything)
INSERT INTO edit_log_overflow VALUES (NEW.*);
END;
-- other errors, insert into overlow
WHEN OTHERS THEN
-- if this faled, throw it into the overflow table (so we don't loose anything)
INSERT INTO edit_log_overflow VALUES (NEW.*);
END;
-- main insert run done, check if we have to create next months table
BEGIN
-- check if next month table exists
table_name := base_table || '_' || to_char((SELECT NEW.event_date + _interval)::DATE, timeformat);
-- RAISE NOTICE 'SEARCH NEXT: %', table_name;
IF (SELECT to_regclass(table_name)) IS NULL THEN
-- move inner interval same
start_date := date_trunc(selector, NEW.event_date + _interval);
end_date := date_trunc(selector, NEW.event_date + _interval_next);
-- RAISE NOTICE 'CREATE NEXT: %', table_name;
-- create table
EXECUTE format(REPLACE( -- end date
REPLACE( -- start date
REPLACE( -- compare date name
REPLACE( -- base name (inherit)
REPLACE( -- table name
command_create_table,
'{TABLE_NAME}',
table_name
),
'{BASE_NAME}',
base_table
),
'{COMPARE_DATE_NAME}',
compare_date_name
),
'{START_DATE}',
quote_literal(start_date)
),
'{END_DATE}',
quote_literal(end_date)
));
-- create all indexes and triggers
EXECUTE format(REPLACE(
REPLACE(
command_create_primary_key,
'{TABLE_NAME}',
table_name
),
'{BASE_TABLE}',
base_table
));
-- FK constraints
EXECUTE format(REPLACE(command_create_foreign_key_1, '{TABLE_NAME}', table_name));
-- generic trigger
EXECUTE format(REPLACE(command_create_trigger_1, '{TABLE_NAME}', table_name));
END IF;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'Failed to create next table: %', table_name;
END;
ELSE
-- if outside valid date, insert into overflow
INSERT INTO edit_log_overflow VALUES (NEW.*);
END IF;
RETURN NULL;
END
$$
LANGUAGE 'plpgsql';
-- END: function/edit_log_partition_insert.sql
-- START: table/edit_temp_files.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/08
-- DESCRIPTION:
-- edit interface temporary files, list of all files in edit (admin) directory
-- TABLE: temp_files
-- HISTORY:
-- DROP TABLE temp_files;
CREATE TABLE temp_files (
filename VARCHAR,
folder VARCHAR
);
-- END: table/edit_temp_files.sql
-- START: table/edit_generic.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- edit tables, this is the generic table, inheriteded by most edit tables
-- TABLE: edit_generic
-- HISTORY:
-- DROP TABLE edit_generic;
CREATE TABLE edit_generic (
cuid VARCHAR,
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
date_updated TIMESTAMP WITHOUT TIME ZONE
);
-- END: table/edit_generic.sql
-- START: table/edit_visible_group.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- edit tables, postgres SQL statements for the mysql definitions
-- TABLE: edit_visible_group
-- HISTORY
-- DROP TABLE edit_visible_group;
CREATE TABLE edit_visible_group (
edit_visible_group_id SERIAL PRIMARY KEY,
name VARCHAR,
flag VARCHAR
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_visible_group.sql
-- START: table/edit_menu_group.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- edit tables, groupings for menu
-- TABLE: edit_menu_group
-- HISTORY
-- DROP TABLE edit_menu_group;
CREATE TABLE edit_menu_group (
edit_menu_group_id SERIAL PRIMARY KEY,
name VARCHAR,
flag VARCHAR,
order_number INT NOT NULL
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_menu_group.sql
-- START: table/edit_page.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- edit tables, this table contains all pages in the edit interface and allocates rights + values to it
-- TABLE: edit_page
-- HISTORY:
-- DROP TABLE edit_page;
CREATE TABLE edit_page (
edit_page_id SERIAL PRIMARY KEY,
content_alias_edit_page_id INT, -- alias for page content, if the page content is defined on a different page, ege for ajax backend pages
FOREIGN KEY (content_alias_edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE RESTRICT ON UPDATE CASCADE,
filename VARCHAR,
name VARCHAR UNIQUE,
order_number INT NOT NULL,
online SMALLINT NOT NULL DEFAULT 0,
menu SMALLINT NOT NULL DEFAULT 0,
popup SMALLINT NOT NULL DEFAULT 0,
popup_x SMALLINT,
popup_y SMALLINT,
hostname VARCHAR
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_page.sql
-- START: table/edit_query_string.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- edit tables
-- TABLE: edit_query_string
-- HISTORY:
-- DROP TABLE edit_query_string;
CREATE TABLE edit_query_string (
edit_query_string_id SERIAL PRIMARY KEY,
edit_page_id INT NOT NULL,
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
enabled SMALLINT NOT NULL DEFAULT 0,
name VARCHAR,
value VARCHAR,
dynamic SMALLINT NOT NULL DEFAULT 0
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_query_string.sql
-- START: table/edit_page_visible_group.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- reference table between visible groups and pages
-- TABLE: edit_page_visible_group
-- HISTORY:
-- DROP TABLE edit_page_visible_group;
CREATE TABLE edit_page_visible_group (
edit_page_id INT NOT NULL,
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_visible_group_id INT NOT NULL,
FOREIGN KEY (edit_visible_group_id) REFERENCES edit_visible_group (edit_visible_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
);
-- END: table/edit_page_visible_group.sql
-- START: table/edit_page_menu_group.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- reference table between menu groups and pages
-- TABLE: edit_page_menu_group
-- HISTORY:
-- DROP TABLE edit_page_menu_group;
CREATE TABLE edit_page_menu_group (
edit_page_id INT NOT NULL,
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_menu_group_id INT NOT NULL,
FOREIGN KEY (edit_menu_group_id) REFERENCES edit_menu_group (edit_menu_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
);
-- END: table/edit_page_menu_group.sql
-- START: table/edit_access_right.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- holds all access right levels for the edit interface and other access areas
-- this table is fixed, prefilled and not changable
-- TABLE: edit_access_right
-- HISTORY:
-- DROP TABLE edit_access_right;
CREATE TABLE edit_access_right (
edit_access_right_id SERIAL PRIMARY KEY,
name VARCHAR,
level SMALLINT,
type VARCHAR,
UNIQUE (level,type)
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_access_right.sql
-- START: table/edit_scheme.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- holds backend template schemes
-- TABLE: edit_scheme
-- HISTORY:
-- DROP TABLE edit_scheme;
CREATE TABLE edit_scheme (
edit_scheme_id SERIAL PRIMARY KEY,
enabled SMALLINT NOT NULL DEFAULT 0,
name VARCHAR,
header_color VARCHAR,
css_file VARCHAR,
template VARCHAR
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_scheme.sql
-- START: table/edit_language.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- languages for the backend, this not used for the encoding, but only for having different language strings
-- the backend encoding is all UTF-8 (not changeable)
-- TABLE: edit_language
-- HISTORY:
-- DROP TABLE edit_language;
CREATE TABLE edit_language (
edit_language_id SERIAL PRIMARY KEY,
enabled SMALLINT NOT NULL DEFAULT 0,
lang_default SMALLINT NOT NULL DEFAULT 0,
long_name VARCHAR,
short_name VARCHAR, -- en_US, en or en_US@latin without encoding
iso_name VARCHAR, -- should actually be encoding
order_number INT
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_language.sql
-- START: table/edit_group.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- list of pages the user can access, with a generic access level, one group per user
-- TABLE: edit_group
-- HISTORY:
-- DROP TABLE edit_group;
CREATE TABLE edit_group (
edit_group_id SERIAL PRIMARY KEY,
edit_scheme_id INT,
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_access_right_id INT NOT NULL,
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
enabled SMALLINT NOT NULL DEFAULT 0,
deleted SMALLINT DEFAULT 0,
uid VARCHAR,
name VARCHAR,
additional_acl JSONB
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_group.sql
-- START: table/edit_page_access.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- groups pages together to one page group to which the user is then subscribed
-- TABLE: edit_page_access
-- HISTORY:
-- DROP TABLE edit_page_access;
CREATE TABLE edit_page_access (
edit_page_access_id SERIAL PRIMARY KEY,
edit_group_id INT NOT NULL,
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_page_id INT NOT NULL,
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_access_right_id INT NOT NULL,
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
enabled SMALLINT NOT NULL DEFAULT 0
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_page_access.sql
-- START: table/edit_page_content.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2019/9/9
-- DESCRIPTION:
-- sub content to one page with additional edit access right set
-- can be eg JS content groups on one page
-- TABLE: edit_page_content
-- HISTORY:
-- DROP TABLE edit_page_content;
CREATE TABLE edit_page_content (
edit_page_content_id SERIAL PRIMARY KEY,
edit_page_id INT NOT NULL,
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_access_right_id INT NOT NULL,
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
uid VARCHAR UNIQUE,
name VARCHAR,
order_number INT NOT NULL,
online SMALLINT NOT NULL DEFAULT 0
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_page_content.sql
-- START: table/edit_user.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/06
-- DESCRIPTION:
-- holds the user that can login + group, scheme, lang and a default access right
-- TABLE: edit_user
-- HISTORY:
-- DROP TABLE edit_user;
CREATE TABLE edit_user (
edit_user_id SERIAL PRIMARY KEY,
connect_edit_user_id INT, -- possible reference to other user
FOREIGN KEY (connect_edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_language_id INT NOT NULL,
FOREIGN KEY (edit_language_id) REFERENCES edit_language (edit_language_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_group_id INT NOT NULL,
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_scheme_id INT,
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_access_right_id INT NOT NULL,
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
enabled SMALLINT NOT NULL DEFAULT 0,
deleted SMALLINT NOT NULL DEFAULT 0,
username VARCHAR UNIQUE,
password VARCHAR,
first_name VARCHAR,
last_name VARCHAR,
first_name_furigana VARCHAR,
last_name_furigana VARCHAR,
debug SMALLINT NOT NULL DEFAULT 0,
db_debug SMALLINT NOT NULL DEFAULT 0,
email VARCHAR,
protected SMALLINT NOT NULL DEFAULT 0,
admin SMALLINT NOT NULL DEFAULT 0,
last_login TIMESTAMP WITHOUT TIME ZONE,
login_error_count INT DEFAULT 0,
login_error_date_last TIMESTAMP WITHOUT TIME ZONE,
login_error_date_first TIMESTAMP WITHOUT TIME ZONE,
strict SMALLINT DEFAULT 0,
locked SMALLINT DEFAULT 0,
password_change_date TIMESTAMP WITHOUT TIME ZONE, -- only when password is first set or changed
password_change_interval INTERVAL, -- null if no change is needed, or d/m/y time interval
password_reset_time TIMESTAMP WITHOUT TIME ZONE, -- when the password reset was requested
password_reset_uid VARCHAR, -- the uid to access the password reset page
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
) INHERITS (edit_generic) WITHOUT OIDS;
COMMENT ON COLUMN edit_user.password_reset_time IS 'When the password reset was requested. For reset page uid valid check';
COMMENT ON COLUMN edit_user.password_reset_uid IS 'Password reset page uid';
-- END: table/edit_user.sql
-- START: table/edit_log.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- log data for backend interface, logs all user activities
-- TABLE: edit_log
-- HISTORY:
-- DROP TABLE edit_log;
CREATE TABLE edit_log (
edit_log_id SERIAL PRIMARY KEY,
euid INT, -- this is a foreign key, but I don't nedd to reference to it
FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL,
username VARCHAR,
password VARCHAR,
event_date TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
ip VARCHAR,
error TEXT,
event TEXT,
data_binary BYTEA,
data TEXT,
page VARCHAR,
action VARCHAR,
action_id VARCHAR,
action_yes VARCHAR,
action_flag VARCHAR,
action_menu VARCHAR,
action_loaded VARCHAR,
action_value VARCHAR,
action_type VARCHAR,
action_error VARCHAR,
user_agent VARCHAR,
referer VARCHAR,
script_name VARCHAR,
query_string VARCHAR,
server_name VARCHAR,
http_host VARCHAR,
http_accept VARCHAR,
http_accept_charset VARCHAR,
http_accept_encoding VARCHAR,
session_id VARCHAR
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_log.sql
-- START: table/edit_log_overflow.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2020/1/28
-- DESCRIPTION:
-- edit log overflow table
-- this is the overflow table for partition
-- TABLE: edit_log_overflow
-- HISTORY:
-- DROP TABLE edit_log_overflow;
CREATE TABLE IF NOT EXISTS edit_log_overflow () INHERITS (edit_log);
ALTER TABLE edit_log_overflow ADD PRIMARY KEY (edit_log_id);
ALTER TABLE edit_log_overflow ADD CONSTRAINT edit_log_overflow_euid_fkey FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL;
-- END: table/edit_log_overflow.sql
-- START: table/edit_access.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- is a "group" for the outside, a user can have serveral groups with different rights so he can access several parts from the outside
-- TABLE: edit_access
-- HISTORY:
-- DROP TABLE edit_access;
CREATE TABLE edit_access (
edit_access_id SERIAL PRIMARY KEY,
enabled SMALLINT NOT NULL DEFAULT 0,
protected SMALLINT DEFAULT 0,
deleted SMALLINT DEFAULT 0,
uid VARCHAR,
name VARCHAR UNIQUE,
description VARCHAR,
color VARCHAR,
additional_acl JSONB
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_access.sql
-- START: table/edit_access_user.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- groupings which user has rights to which access groups (incl ACL)
-- TABLE: edit_access_user
-- HISTORY:
-- DROP TABLE edit_access_user;
CREATE TABLE edit_access_user (
edit_access_user_id SERIAL PRIMARY KEY,
edit_access_id INT NOT NULL,
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_user_id INT NOT NULL,
FOREIGN KEY (edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_access_right_id INT NOT NULL,
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_default SMALLINT DEFAULT 0,
enabled SMALLINT NOT NULL DEFAULT 0
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_access_user.sql
-- START: table/edit_access_data.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2016/7/15
-- DESCRIPTION:
-- sub table to edit access, holds additional data for access group
-- TABLE: edit_access_data
-- HISTORY:
-- DROP TABLE edit_access_data;
CREATE TABLE edit_access_data (
edit_access_data_id SERIAL PRIMARY KEY,
edit_access_id INT NOT NULL,
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
enabled SMALLINT NOT NULL DEFAULT 0,
name VARCHAR,
value VARCHAR
) INHERITS (edit_generic) WITHOUT OIDS;
-- create a unique index for each attached data block for each edit access can
-- only have ONE value;
CREATE UNIQUE INDEX edit_access_data_edit_access_id_name_ukey ON edit_access_data (edit_access_id, name);
-- END: table/edit_access_data.sql
-- START: trigger/trg_edit_access_right.sql
-- DROP TRIGGER IF EXISTS trg_edit_access_right ON edit_access_right;
CREATE TRIGGER trg_edit_access_right
BEFORE INSERT OR UPDATE ON edit_access_right
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_access_right.sql
-- START: trigger/trg_edit_access.sql
-- DROP TRIGGER IF EXISTS trg_edit_access ON edit_access;
CREATE TRIGGER trg_edit_access
BEFORE INSERT OR UPDATE ON edit_access
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- DROP TRIGGER IF EXISTS trg_set_edit_access_uid ON edit_access;
CREATE TRIGGER trg_set_edit_access_uid
BEFORE INSERT OR UPDATE ON edit_access
FOR EACH ROW EXECUTE PROCEDURE set_edit_access_uid();
-- END: trigger/trg_edit_access.sql
-- START: trigger/trg_edit_access_data.sql
-- DROP TRIGGER IF EXISTS trg_edit_access_data ON edit_access_data;
CREATE TRIGGER trg_edit_access_data
BEFORE INSERT OR UPDATE ON edit_access_data
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_access_data.sql
-- START: trigger/trg_edit_access_user.sql
-- DROP TRIGGER IF EXISTS trg_edit_access_user ON edit_access_user;
CREATE TRIGGER trg_edit_access_user
BEFORE INSERT OR UPDATE ON edit_access_user
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_access_user.sql
-- START: trigger/trg_edit_group.sql
-- DROP TRIGGER IF EXISTS trg_edit_group ON edit_group;
CREATE TRIGGER trg_edit_group
BEFORE INSERT OR UPDATE ON edit_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- DROP TRIGGER IF EXISTS trg_set_edit_group_uid ON edit_group;
CREATE TRIGGER trg_set_edit_group_uid
BEFORE INSERT OR UPDATE ON edit_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_group_uid();
-- END: trigger/trg_edit_group.sql
-- START: trigger/trg_edit_language.sql
-- DROP TRIGGER IF EXISTS trg_edit_language ON edit_language;
CREATE TRIGGER trg_edit_language
BEFORE INSERT OR UPDATE ON edit_language
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_language.sql
-- START: trigger/trg_edit_log_overflow.sql
-- DROP TRIGGER IF EXISTS trg_edit_log_overflow ON edit_log_overflow;
CREATE TRIGGER trg_edit_log_overflow
BEFORE INSERT OR UPDATE ON edit_log_overflow
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_log_overflow.sql
-- START: trigger/trg_edit_log.sql
-- DROP TRIGGER IF EXISTS trg_edit_log ON edit_log;
CREATE TRIGGER trg_edit_log
BEFORE INSERT OR UPDATE ON edit_log
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- DROP TRIGGER IF EXISTS trg_edit_log_insert_partition ON edit_log;
CREATE TRIGGER trg_edit_log_insert_partition
BEFORE INSERT OR UPDATE ON edit_log
FOR EACH ROW EXECUTE PROCEDURE edit_log_insert_trigger();
-- END: trigger/trg_edit_log.sql
-- START: trigger/trg_edit_page_access.sql
-- DROP TRIGGER IF EXISTS trg_edit_page_access ON edit_page_access;
CREATE TRIGGER trg_edit_page_access
BEFORE INSERT OR UPDATE ON edit_page_access
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_page_access.sql
-- START: trigger/trg_edit_page_content.sql
-- DROP TRIGGER IF EXISTS trg_edit_page_content ON edit_page_content;
CREATE TRIGGER trg_edit_page_content
BEFORE INSERT OR UPDATE ON edit_page_content
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_page_content.sql
-- START: trigger/trg_edit_page.sql
-- DROP TRIGGER IF EXISTS trg_edit_page ON edit_page;
CREATE TRIGGER trg_edit_page
BEFORE INSERT OR UPDATE ON edit_page
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_page.sql
-- START: trigger/trg_edit_query_string.sql
-- DROP TRIGGER IF EXISTS trg_edit_query_string ON edit_query_string;
CREATE TRIGGER trg_edit_query_string
BEFORE INSERT OR UPDATE ON edit_query_string
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_query_string.sql
-- START: trigger/trg_edit_scheme.sql
-- DROP TRIGGER IF EXISTS trg_edit_scheme ON edit_scheme;
CREATE TRIGGER trg_edit_scheme
BEFORE INSERT OR UPDATE ON edit_scheme
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_scheme.sql
-- START: trigger/trg_edit_user.sql
-- DROP TRIGGER IF EXISTS trg_edit_user ON edit_user;
CREATE TRIGGER trg_edit_user
BEFORE INSERT OR UPDATE ON edit_user
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_user.sql
-- START: trigger/trg_edit_visible_group.sql
-- DROP TRIGGER IF EXISTS trg_edit_visible_group ON edit_visible_group;
CREATE TRIGGER trg_edit_visible_group
BEFORE INSERT OR UPDATE ON edit_visible_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_visible_group.sql
-- START: trigger/trg_edit_menu_group.sql
-- DROP TRIGGER IF EXISTS trg_edit_menu_group ON edit_menu_group;
CREATE TRIGGER trg_edit_menu_group
BEFORE INSERT OR UPDATE ON edit_menu_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_menu_group.sql
-- START: data/edit_tables.sql
-- edit tables insert data in order
-- edit visible group
DELETE FROM edit_visible_group;
INSERT INTO edit_visible_group (name, flag) VALUES ('Main Menu', 'main');
INSERT INTO edit_visible_group (name, flag) VALUES ('Data popup Menu', 'datapopup');
-- edit menu group
DELETE FROM edit_menu_group;
INSERT INTO edit_menu_group (name, flag, order_number) VALUES ('Admin Menu', 'admin', 1);
INSERT INTO edit_menu_group (name, flag, order_number) VALUES ('Admin Data Popup Menu', 'AdminDataPopup', 2);
-- edit page
DELETE FROM edit_page;
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_pages.php', 'Edit Pages', 1, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_users.php', 'Edit Users', 2, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_languages.php', 'Edit Languages', 3, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_schemes.php', 'Edit Schemes', 4, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_groups.php', 'Edit Groups', 5, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_visible_group.php', 'Edit Visible Groups', 6, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_menu_group.php', 'Edit Menu Groups', 7, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_access.php', 'Edit Access', 8, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_order.php', 'Edit Order', 9, 1, 0);
-- edit visible group
DELETE FROM edit_page_visible_group;
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Pages'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Users'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Languages'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Schemes'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Groups'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Visible Groups'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Menu Groups'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Access'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
-- INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Order'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
-- edit page menu group
DELETE FROM edit_page_menu_group;
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Pages'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Users'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Languages'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Schemes'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Groups'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Visible Groups'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Menu Groups'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Access'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
-- INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Order'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
-- edit access right
DELETE FROM edit_access_right;
INSERT INTO edit_access_right (name, level, type) VALUES ('Default', -1, 'default');
INSERT INTO edit_access_right (name, level, type) VALUES ('No Access', 0, 'none');
INSERT INTO edit_access_right (name, level, type) VALUES ('List', 10, 'list');
INSERT INTO edit_access_right (name, level, type) VALUES ('Read', 20, 'read');
INSERT INTO edit_access_right (name, level, type) VALUES ('Translator', 30, 'mod_trans');
INSERT INTO edit_access_right (name, level, type) VALUES ('Modify', 40, 'mod');
INSERT INTO edit_access_right (name, level, type) VALUES ('Create/Write', 60, 'write');
INSERT INTO edit_access_right (name, level, type) VALUES ('Delete', 80, 'del');
INSERT INTO edit_access_right (name, level, type) VALUES ('Site Admin', 90, 'siteadmin');
INSERT INTO edit_access_right (name, level, type) VALUES ('Admin', 100, 'admin');
-- edit scheme
DELETE FROM edit_scheme;
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Default Scheme', 'E0E2FF', 1);
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Admin', 'CC7E7E', 1);
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Visitor', 'B0C4B3', 1);
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('User', '1E789E', 1);
-- edit language
-- short_name = locale without encoding
-- iso_name = encoding
DELETE FROM edit_language;
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('English', 'en_US', 'UTF-8', 1, 1, 1);
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('Japanese', 'ja_JP', 'UTF-8', 2, 1, 0);
-- edit group
DELETE FROM edit_group;
INSERT INTO edit_group (name, enabled, edit_scheme_id, edit_access_right_id) VALUES ('Admin', 1, (SELECT edit_scheme_id FROM edit_scheme WHERE name = 'Admin'), (SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin'));
INSERT INTO edit_group (name, enabled, edit_scheme_id, edit_access_right_id) VALUES ('User', 1, (SELECT edit_scheme_id FROM edit_scheme WHERE name = 'User'), (SELECT edit_access_right_id FROM edit_access_right WHERE type = 'write'));
-- edit page access
DELETE FROM edit_page_access;
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Pages'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Users'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Languages'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Schemes'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Groups'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Visible Groups'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Menu Groups'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Access'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Order'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
-- edit user
-- inserts admin user so basic users can be created
DELETE FROM edit_user;
INSERT INTO edit_user (username, password, enabled, debug, db_debug, email, protected, admin, edit_language_id, edit_group_id, edit_scheme_id, edit_access_right_id) VALUES ('admin', 'admin', 1, 1, 1, '', 1, 1,
(SELECT edit_language_id FROM edit_language WHERE short_name = 'en_US'),
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_scheme_id FROM edit_scheme WHERE name = 'Admin'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
-- edit access
DELETE FROM edit_access;
INSERT INTO edit_access (name, enabled, protected) VALUES ('Admin Access', 1, 1);
-- edit access user
DELETE FROM edit_access_user;
INSERT INTO edit_access_user (edit_default, enabled, edit_access_id, edit_user_id, edit_access_right_id) VALUES (1, 1,
(SELECT edit_access_id FROM edit_access WHERE uid = 'AdminAccess'),
(SELECT edit_user_id FROM edit_user WHERE username = 'admin'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
-- END: data/edit_tables.sql

View File

@@ -1,6 +1,6 @@
-- adds the created or updated date tags
CREATE OR REPLACE FUNCTION set_generic() RETURNS TRIGGER AS '
CREATE OR REPLACE FUNCTION set_date() RETURNS TRIGGER AS '
BEGIN
IF TG_OP = ''INSERT'' THEN
NEW.date_created := ''now'';

View File

@@ -0,0 +1,18 @@
-- set generic with date and uid combined
-- don't use with set_generic/set_uid together
CREATE OR REPLACE FUNCTION set_generic() RETURNS TRIGGER AS '
DECLARE
random_length INT = 32; -- long for massive data
BEGIN
IF TG_OP = ''INSERT'' THEN
NEW.date_created := ''now'';
IF NEW.uid IS NULL THEN
NEW.uid := random_string(random_length);
END IF;
ELSIF TG_OP = ''UPDATE'' THEN
NEW.date_updated := ''now'';
END IF;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';

View File

@@ -1,12 +1,13 @@
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- cms tables; generic basic table
-- generic basic table with date and uid column
-- TABLE: generic
-- HISTORY:
-- DROP TABLE edit_generic;
-- DROP TABLE generic;
CREATE TABLE generic (
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
date_updated TIMESTAMP WITHOUT TIME ZONE
date_updated TIMESTAMP WITHOUT TIME ZONE,
uid VARCHAR
);

View File

@@ -1,9 +1,9 @@
DROP TRIGGER IF EXISTS trg_edit_access ON edit_access;
-- DROP TRIGGER IF EXISTS trg_edit_access ON edit_access;
CREATE TRIGGER trg_edit_access
BEFORE INSERT OR UPDATE ON edit_access
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
DROP TRIGGER IF EXISTS trg_set_edit_access_uid ON edit_access;
-- DROP TRIGGER IF EXISTS trg_set_edit_access_uid ON edit_access;
CREATE TRIGGER trg_set_edit_access_uid
BEFORE INSERT OR UPDATE ON edit_access
FOR EACH ROW EXECUTE PROCEDURE set_edit_access_uid();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_access_data ON edit_access_data;
-- DROP TRIGGER IF EXISTS trg_edit_access_data ON edit_access_data;
CREATE TRIGGER trg_edit_access_data
BEFORE INSERT OR UPDATE ON edit_access_data
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_access_right ON edit_access_right;
-- DROP TRIGGER IF EXISTS trg_edit_access_right ON edit_access_right;
CREATE TRIGGER trg_edit_access_right
BEFORE INSERT OR UPDATE ON edit_access_right
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_access_user ON edit_access_user;
-- DROP TRIGGER IF EXISTS trg_edit_access_user ON edit_access_user;
CREATE TRIGGER trg_edit_access_user
BEFORE INSERT OR UPDATE ON edit_access_user
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,9 +1,9 @@
DROP TRIGGER IF EXISTS trg_edit_group ON edit_group;
-- DROP TRIGGER IF EXISTS trg_edit_group ON edit_group;
CREATE TRIGGER trg_edit_group
BEFORE INSERT OR UPDATE ON edit_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
DROP TRIGGER IF EXISTS trg_set_edit_group_uid ON edit_group;
-- DROP TRIGGER IF EXISTS trg_set_edit_group_uid ON edit_group;
CREATE TRIGGER trg_set_edit_group_uid
BEFORE INSERT OR UPDATE ON edit_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_group_uid();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_language ON edit_language;
-- DROP TRIGGER IF EXISTS trg_edit_language ON edit_language;
CREATE TRIGGER trg_edit_language
BEFORE INSERT OR UPDATE ON edit_language
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,9 +1,9 @@
DROP TRIGGER IF EXISTS trg_edit_log ON edit_log;
-- DROP TRIGGER IF EXISTS trg_edit_log ON edit_log;
CREATE TRIGGER trg_edit_log
BEFORE INSERT OR UPDATE ON edit_log
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
DROP TRIGGER IF EXISTS trg_edit_log_insert_partition ON edit_log;
-- DROP TRIGGER IF EXISTS trg_edit_log_insert_partition ON edit_log;
CREATE TRIGGER trg_edit_log_insert_partition
BEFORE INSERT OR UPDATE ON edit_log
FOR EACH ROW EXECUTE PROCEDURE edit_log_insert_trigger();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_log_overflow ON edit_log_overflow;
-- DROP TRIGGER IF EXISTS trg_edit_log_overflow ON edit_log_overflow;
CREATE TRIGGER trg_edit_log_overflow
BEFORE INSERT OR UPDATE ON edit_log_overflow
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_menu_group ON edit_menu_group;
-- DROP TRIGGER IF EXISTS trg_edit_menu_group ON edit_menu_group;
CREATE TRIGGER trg_edit_menu_group
BEFORE INSERT OR UPDATE ON edit_menu_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_page ON edit_page;
-- DROP TRIGGER IF EXISTS trg_edit_page ON edit_page;
CREATE TRIGGER trg_edit_page
BEFORE INSERT OR UPDATE ON edit_page
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_page_access ON edit_page_access;
-- DROP TRIGGER IF EXISTS trg_edit_page_access ON edit_page_access;
CREATE TRIGGER trg_edit_page_access
BEFORE INSERT OR UPDATE ON edit_page_access
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_page_content ON edit_page_content;
-- DROP TRIGGER IF EXISTS trg_edit_page_content ON edit_page_content;
CREATE TRIGGER trg_edit_page_content
BEFORE INSERT OR UPDATE ON edit_page_content
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_query_string ON edit_query_string;
-- DROP TRIGGER IF EXISTS trg_edit_query_string ON edit_query_string;
CREATE TRIGGER trg_edit_query_string
BEFORE INSERT OR UPDATE ON edit_query_string
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_scheme ON edit_scheme;
-- DROP TRIGGER IF EXISTS trg_edit_scheme ON edit_scheme;
CREATE TRIGGER trg_edit_scheme
BEFORE INSERT OR UPDATE ON edit_scheme
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_user ON edit_user;
-- DROP TRIGGER IF EXISTS trg_edit_user ON edit_user;
CREATE TRIGGER trg_edit_user
BEFORE INSERT OR UPDATE ON edit_user
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,4 +1,4 @@
DROP TRIGGER IF EXISTS trg_edit_visible_group ON edit_visible_group;
-- DROP TRIGGER IF EXISTS trg_edit_visible_group ON edit_visible_group;
CREATE TRIGGER trg_edit_visible_group
BEFORE INSERT OR UPDATE ON edit_visible_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();

View File

@@ -1,4 +1,4 @@
-- update missing edit_* table data
-- 2019/12/11 update missing edit_* table data
ALTER TABLE edit_generic ADD cuid VARCHAR;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env bash
# note: there is currently no port selection, standard 5432 port is assumed
# note: we use the default in path postgresql commands and connect to whatever default DB is set
# PARAMETER 1: database data file to load
# PARAMETER 2: db user WHO MUST BE ABLE TO CREATE A DATABASE
# PARAMETER 3: db name
# PARAMETER 4: db host
load_sql="${1}";
# abort with 1 if we cannot find the file
if [ ! -f "${load_sql}" ]; then
echo 1;
exit 1;
fi;
db_user="${2}";
db_name="${3}";
db_host="${4}";
# empty db name or db user -> exit with 2
if [ -z "${db_user}" ] || [ -z "${db_name}" ] || [ -z "${db_host}" ]; then
echo 2;
exit 2;
fi;
# drop database, on error exit with 3
dropdb -U ${db_user} -h ${db_host} ${db_name} 2>&1;
if [ $? -ne 0 ]; then
echo 3;
exit 3;
fi;
# create database, on error exit with 4
createdb -U ${db_user} -O ${db_user} -h ${db_host} -E utf8 ${db_name} 2>&1;
if [ $? -ne 0 ]; then
echo 4;
exit 4;
fi;
# load data (redirect ALL error to null), on error exit with 5
psql -U ${db_user} -h ${db_host} -f ${load_sql} ${db_name} 2>&1 1>/dev/null 2>/dev/null;
if [ $? -ne 0 ]; then
echo 5;
exit 5;
fi;
echo 0;
exit 0;
# __END__

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
/**
* Test class for Create\Session
@@ -20,85 +21,246 @@ final class CoreLibsCreateSessionTest extends TestCase
*/
public function sessionProvider(): array
{
// 0: session name as parameter
// 1: type p (param), g: global, c: constant
// 2: exepcted name (session)
// 3: regex check
// 0: session name as parameter or for GLOBAL value
// 1: type p: parameter, g: global, d: php.ini default
// 2: mock data as array
// checkCliStatus: true/false,
// getSessionStatus: PHP_SESSION_DISABLED for abort,
// PHP_SESSION_NONE/ACTIVE for ok
// setSessionName: true/false,
// checkActiveSession: true/false, [1st call, 2nd call]
// getSessionId: string or false
// 3: exepcted name (session)
// 4: expected error string
return [
'session parameter' => [
'sessionNameParameter',
'p',
[
'checkCliStatus' => false,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => true,
'checkActiveSession' => [false, true],
'getSessionId' => '1234abcd4567'
],
'sessionNameParameter',
'/^\w+$/'
''
],
'session globals' => [
'sessionNameGlobals',
'g',
[
'checkCliStatus' => false,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => true,
'checkActiveSession' => [false, true],
'getSessionId' => '1234abcd4567'
],
'sessionNameGlobals',
'/^\w+$/'
''
],
'session name default' => [
'',
'd',
[
'checkCliStatus' => false,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => true,
'checkActiveSession' => [false, true],
'getSessionId' => '1234abcd4567'
],
'',
'/^\w+$/'
''
],
// error checks
// 1: we are in cli
'on cli error' => [
'',
'd',
[
'checkCliStatus' => true,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => true,
'checkActiveSession' => [false, true],
'getSessionId' => '1234abcd4567'
],
'',
'[SESSION] No sessions in php cli'
],
// 2: session disabled
'session disabled error' => [
'',
'd',
[
'checkCliStatus' => false,
'getSessionStatus' => PHP_SESSION_DISABLED,
'setSessionName' => true,
'checkActiveSession' => [false, true],
'getSessionId' => '1234abcd4567'
],
'',
'[SESSION] Sessions are disabled'
],
// 3: invalid session name: string
'invalid name chars error' => [
'1invalid$session#;',
'p',
[
'checkCliStatus' => false,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => false,
'checkActiveSession' => [false, true],
'getSessionId' => '1234abcd4567'
],
'',
'[SESSION] Invalid session name: 1invalid$session#;'
],
// 3: invalid session name: only numbers
'invalid name numbers only error' => [
'123',
'p',
[
'checkCliStatus' => false,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => false,
'checkActiveSession' => [false, true],
'getSessionId' => '1234abcd4567'
],
'',
'[SESSION] Invalid session name: 123'
],
// 3: invalid session name: invalid name short
// 3: invalid session name: too long (128)
// 4: failed to start session (2nd false on check active session)
'invalid name numbers only error' => [
'',
'd',
[
'checkCliStatus' => false,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => true,
'checkActiveSession' => [false, false],
'getSessionId' => '1234abcd4567'
],
'',
'[SESSION] Failed to activate session'
],
// 5: get session id return false
'invalid name numbers only error' => [
'',
'd',
[
'checkCliStatus' => false,
'getSessionStatus' => PHP_SESSION_NONE,
'setSessionName' => true,
'checkActiveSession' => [false, true],
'getSessionId' => false
],
'',
'[SESSION] getSessionId did not return a session id'
],
];
}
/**
* Undocumented function
* Test session start
*
* @covers ::startSession
* @dataProvider sessionProvider
* @testdox startSession $input name for $type will be $expected_n with $expected_i [$_dataName]
* @testdox startSession $input name for $type will be $expected (error: $expected_error) [$_dataName]
*
* @param string $input
* @param string $type
* @param string|bool $expected_n
* @param string|bool $expected_i
* @param array<mixed> $mock_data
* @param string $expected
* @param string $expected_error
* @return void
*/
public function testStartSession(
string $input,
string $type,
$expected_n,
$expected_i
array $mock_data,
string $expected,
string $expected_error,
): void {
/*
// MOCK class for dummy call
$session = new \CoreLibs\Create\Session();
$session_id = '';
// override expected
if ($type == 'd') {
$expected = ini_get('session.name');
}
/** @var \CoreLibs\Create\Session&MockObject $session_mock */
$session_mock = $this->createPartialMock(
\CoreLibs\Create\Session::class,
[
'checkCliStatus', 'getSessionStatus', 'checkActiveSession',
'setSessionName', 'startSessionCall', 'getSessionId',
'getSessionName'
]
);
// set return values based requested input values
// OK: true
// error: false
$session_mock->method('checkCliStatus')->willReturn($mock_data['checkCliStatus']);
// OK: PHP_SESSION_ACTIVE, PHP_SESSION_NONE
// error: PHP_SESSION_DISABLED
$session_mock->method('getSessionStatus')->willReturn($mock_data['getSessionStatus']);
// false: try start
// true: skip start
// note that on second call if false -> error
$session_mock->method('checkActiveSession')
->willReturnOnConsecutiveCalls(
$mock_data['checkActiveSession'][0],
$mock_data['checkActiveSession'][1],
);
// dummy set for session name
$session_mock->method('setSessionName')->with($input)->willReturn($mock_data['setSessionName']);
// set session name & return bsed on request data
$session_mock->method('getSessionName')->willReturn($expected);
// will not return anything
$session_mock->method('startSessionCall');
// in test case only return string
// false: will return false
$session_mock->method('getSessionId')->willReturn($mock_data['getSessionId']);
// regex for session id
$ression_id_regex = "/^\w+$/";
unset($GLOBALS['SET_SESSION_NAME']);
$session_id = '';
switch ($type) {
case 'p':
$session_id = $session->startSession($input);
$session_id = $session_mock->startSession($input);
break;
case 'g':
$GLOBALS['SET_SESSION_NAME'] = $input;
$session_id = $session->startSession();
$session_id = $session_mock->startSession();
break;
case 'd':
$expected_n = ini_get('session.name');
$session_id = \$session->startSession();
$session_id = $session_mock->startSession();
break;
}
$this->assertMatchesRegularExpression(
$expected_i,
(string)$session_id
);
$this->assertMatchesRegularExpression(
$expected_i,
(string)$session->getSessionId()
);
$this->assertEquals(
$expected_n,
$session->getSessionName()
);
if ($type == 'g') {
unset($GLOBALS['SET_SESSION_NAME']);
} */
$this->markTestSkipped('[CoreLibsCreateSessionTest] No implementation '
. 'for Create\Session. Cannot run session_start in CLI');
// asert checks
if (!empty($session_id)) {
$this->assertMatchesRegularExpression(
$ression_id_regex,
(string)$session_id,
'session id regex from retrun'
);
$this->assertMatchesRegularExpression(
$ression_id_regex,
(string)$session_mock->getSessionId()
);
$this->assertEquals(
$expected,
$session_mock->getSessionName()
);
} else {
// false checks
$this->assertEquals(
$expected_error,
$session_mock->getErrorStr(),
'error assert'
);
}
}
/**
@@ -109,7 +271,7 @@ final class CoreLibsCreateSessionTest extends TestCase
public function sessionNameProvider(): array
{
// 0: string for session
// 1: expected return
// 1: expected return as bool
return [
'valid name' => [
'abc',
@@ -141,7 +303,7 @@ final class CoreLibsCreateSessionTest extends TestCase
}
/**
* Undocumented function
* test valid session name
*
* @covers ::checkValidSessionName
* @dataProvider sessionNameProvider
@@ -158,6 +320,153 @@ final class CoreLibsCreateSessionTest extends TestCase
\CoreLibs\Create\Session::checkValidSessionName($input)
);
}
/**
* provider for set/get tests
*
* @return array
*/
public function sessionDataProvider(): array
{
return [
'test' => [
'foo',
'bar',
'bar',
],
'int key test' => [
123,
'bar',
'bar',
],
// more complex value tests
'array values' => [
'array',
[1, 2, 3],
[1, 2, 3],
]
];
}
/**
* method call test
*
* @covers ::setS
* @covers ::getS
* @covers ::issetS
* @covers ::unsetS
* @dataProvider sessionDataProvider
* @testdox setS/getS/issetS/unsetS $name with $input is $expected [$_dataName]
*
* @param string|int $name
* @param mixed $input
* @param mixed $expected
* @return void
*/
public function testMethodSetGet($name, $input, $expected): void
{
$session = new \CoreLibs\Create\Session();
$session->setS($name, $input);
$this->assertEquals(
$expected,
$session->getS($name),
'method set assert'
);
// isset true
$this->assertTrue(
$session->issetS($name),
'method isset assert ok'
);
$session->unsetS($name);
$this->assertEquals(
'',
$session->getS($name),
'method unset assert'
);
// iset false
$this->assertFalse(
$session->issetS($name),
'method isset assert false'
);
}
/**
* magic call test
*
* @covers ::__set
* @covers ::__get
* @covers ::__isset
* @covers ::__unset
* @dataProvider sessionDataProvider
* @testdox __set/__get/__iseet/__unset $name with $input is $expected [$_dataName]
*
* @param string|int $name
* @param mixed $input
* @param mixed $expected
* @return void
*/
public function testMagicSetGet($name, $input, $expected): void
{
$session = new \CoreLibs\Create\Session();
$session->$name = $input;
$this->assertEquals(
$expected,
$session->$name,
'magic set assert'
);
// isset true
$this->assertTrue(
isset($session->$name),
'magic isset assert ok'
);
unset($session->$name);
$this->assertEquals(
'',
$session->$name,
'magic unset assert'
);
// isset true
$this->assertFalse(
isset($session->$name),
'magic isset assert false'
);
}
/**
* unset all test
*
* @covers ::unsetAllS
* @testdox unsetAllS test
*
* @return void
*/
public function testUnsetAll(): void
{
$test_values = [
'foo' => 'abc',
'bar' => '123'
];
$session = new \CoreLibs\Create\Session();
foreach ($test_values as $name => $value) {
$session->setS($name, $value);
// confirm set
$this->assertEquals(
$value,
$session->getS($name),
'set assert: ' . $name
);
}
// unset all
$session->unsetAllS();
// check unset
foreach (array_keys($test_values) as $name) {
$this->assertEquals(
'',
$session->getS($name),
'unsert assert: ' . $name
);
}
}
}
// __END__

File diff suppressed because it is too large Load Diff

View File

@@ -709,6 +709,64 @@ final class CoreLibsDebugLoggingTest extends TestCase
);
}
public function prBlProvider(): array
{
return [
'true bool default' => [
true,
null,
null,
'true'
],
'false bool default' => [
false,
null,
null,
'false'
],
'true bool override' => [
true,
'ok',
'not ok',
'ok'
],
'false bool override' => [
false,
'ok',
'not ok',
'not ok'
],
];
}
/**
* check bool to string converter
*
* @covers ::prBl
* @dataProvider prBlProvider
* @textdox check prBl $input ($true/$false) is expected $false [$_dataName]
*
* @param bool $input
* @param string|null $true
* @param string|null $false
* @param string $expected
* @return void
*/
public function testPrBl(bool $input, ?string $true, ?string $false, string $expected): void
{
$this->log = new \CoreLibs\Debug\Logging();
$return = '';
if ($true === null && $false === null) {
$return = $this->log->prBl($input);
} elseif ($true !== null || $false !== null) {
$return = $this->log->prBl($input, $true ?? '', $false ?? '');
}
$this->assertEquals(
$expected,
$return
);
}
// from here are complex debug tests
/**

View File

@@ -0,0 +1,119 @@
<?php
declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
use CoreLibs\Debug\MemoryUsage;
/**
* Test class for Debug\MemoryUsage
* @coversDefaultClass \CoreLibs\Debug\MemoryUsage
* @testdox \CoreLibs\Debug\MemoryUsage method tests
*/
final class CoreLibsDebugMemoryUsageTest extends TestCase
{
/**
* Undocumented function
*
* @return array
*/
public function memoryUsageProvider(): array
{
$regex_raw_off = '/^\[[\w\s_-]+\] Peak\/Curr\/Change: \d+(\.\d+)? ?\w{1,2}\/'
. '\d+(\.\d+)? ?\w{1,2}\/'
. 'Since Start: \d+(\.\d+)? ?\w{1,2} \| '
. 'Since Last: \d+(\.\d+)? ?\w{1,2} \| '
. 'Since Set: \d+(\.\d+)? ?\w{1,2}$/';
$regex_raw_on = '/^\[[\w\s_-]+\] Peak\/Curr\/'
// . 'Change: \d+(\.\d+)? ?\w{1,2}\/\d+(\.\d+)? ?\w{1,2} \[\d+\]\/'
. 'Change: \d+(\.\d+)? ?\w{1,2}\/\d+(\.\d+)? ?\w{1,2}/'
. 'Since Start: \d+(\.\d+)? ?\w{1,2} \[\d+\] \| '
. 'Since Last: \d+(\.\d+)? ?\w{1,2} \[\d+\] \| '
. 'Since Set: \d+(\.\d+)? ?\w{1,2} \[\d+\]$/';
$regex_array = [
'prefix' => '/^[\w\s_-]+$/',
'peak' => '/^\d+$/',
'usage' => '/^\d+$/',
'start' => '/^\d+$/',
'last' => '/^\d+$/',
'set' => '/^\d+$/',
];
// 0: prefix
// 1: raw flag
// 2: set flags array
// 3: array output expected (as regex)
// 4: string output expected (as regex)
return [
'test normal' => [
'test',
null,
[],
$regex_array,
$regex_raw_off,
]
];
}
/**
* Undocumented function
*
* @cover ::resetMemory
* @cover ::debugMemoryFlag
* @cover ::setStartMemory
* @cover ::setMemory
* @cover ::memoryUsage
* @cover ::printMemoryUsage
* @dataProvider memoryUsageProvider
* @testdox memoryUsage with $prefix, raw memory $raw [$_dataName]
*
* @param string $prefix
* @param bool|null $raw
* @param array $set_flags
* @param array $expected_array
* @param string $expected_string
* @return void
*/
public function testMemoryUsage(
string $prefix,
?bool $raw,
array $settings,
array $expected_array,
string $expected_string
): void {
// always reeset to null
MemoryUsage::resetMemory();
MemoryUsage::debugMemoryFlag(true);
MemoryUsage::setStartMemory();
MemoryUsage::setMemory();
// run collector
$memory = MemoryUsage::memoryUsage($prefix);
if ($raw === null) {
$string = MemoryUsage::printMemoryUsage($memory);
} else {
$string = MemoryUsage::printMemoryUsage($memory, $raw);
}
// expected_array for each
foreach ($expected_array as $name => $regex) {
$this->assertMatchesRegularExpression(
$regex,
(string)$memory[$name],
'assert memory usage array ' . $name
);
}
// regex match string
$this->assertMatchesRegularExpression(
$expected_string,
$string,
'assert memory usage string as regex'
);
// TODO additional tests with use more memory and check diff matching
// TODO reset memory usage test
}
}
// __END__

View File

@@ -15,6 +15,8 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
{
public function hrRunningTimeProvider(): array
{
// 0: return time difference
// 1: return time on first run in regex
return [
'default time' => [
0 => null,
@@ -69,21 +71,73 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
*/
public function testHrRunningTime(?string $out_time, string $expected): void
{
// reset for each run
\CoreLibs\Debug\RunningTime::hrRunningTimeReset();
$start = \CoreLibs\Debug\RunningTime::hrRunningTime();
$this->assertEquals(
0,
$start
$start,
'assert first run 0'
);
time_nanosleep(1, 500);
if ($out_time === null) {
$end = \CoreLibs\Debug\RunningTime::hrRunningTime();
$second = \CoreLibs\Debug\RunningTime::hrRunningTime();
} else {
$end = \CoreLibs\Debug\RunningTime::hrRunningTime($out_time);
$second = \CoreLibs\Debug\RunningTime::hrRunningTime($out_time);
}
// print "E: " . $end . "\n";
$this->assertMatchesRegularExpression(
$expected,
(string)$end
(string)$second,
'assert second run regex'
);
if ($out_time === null) {
$end_second = \CoreLibs\Debug\RunningTime::hrRunningTimeFromStart();
} else {
$end_second = \CoreLibs\Debug\RunningTime::hrRunningTimeFromStart($out_time);
}
$this->assertEquals(
$end_second,
$second,
'assert end is equal second'
);
// sleep again, second messurement
time_nanosleep(1, 500);
if ($out_time === null) {
$third = \CoreLibs\Debug\RunningTime::hrRunningTime();
} else {
$third = \CoreLibs\Debug\RunningTime::hrRunningTime($out_time);
}
// third call is not null
$this->assertNotEquals(
0,
$third,
'assert third call not null'
);
// third call is bigger than end
$this->assertNotEquals(
$second,
$third,
'assert third different second'
);
// last messurement, must match start - end + last
if ($out_time === null) {
$end = \CoreLibs\Debug\RunningTime::hrRunningTimeFromStart();
} else {
$end = \CoreLibs\Debug\RunningTime::hrRunningTimeFromStart($out_time);
}
$this->assertGreaterThan(
$third,
$end,
'assert end greater third'
);
// new start
\CoreLibs\Debug\RunningTime::hrRunningTimeReset();
$new_start = \CoreLibs\Debug\RunningTime::hrRunningTime();
$this->assertEquals(
0,
$new_start,
'assert new run 0'
);
}

View File

@@ -45,7 +45,7 @@ final class CoreLibsDebugSupportTest extends TestCase
*
* @return array
*/
public function printArProvider(): array
public function printArrayProvider(): array
{
return [
'empty array' => [
@@ -62,6 +62,51 @@ final class CoreLibsDebugSupportTest extends TestCase
];
}
/**
* Undocumented function
*
* @return array
*/
public function printBoolProvider(): array
{
return [
'true input default' => [
0 => true,
1 => [],
2 => 'true'
],
'false input default' => [
0 => false,
1 => [],
2 => 'false'
],
'false input param name' => [
0 => false,
1 => [
'name' => 'param test'
],
2 => '<b>param test</b>: false'
],
'true input param name, true override' => [
0 => true,
1 => [
'name' => 'param test',
'true' => 'ok'
],
2 => '<b>param test</b>: ok'
],
'false input param name, true override, false override' => [
0 => false,
1 => [
'name' => 'param test',
'true' => 'ok',
'false' => 'not',
],
2 => '<b>param test</b>: not'
],
];
}
/**
* Undocumented function
*
@@ -184,8 +229,9 @@ final class CoreLibsDebugSupportTest extends TestCase
* Undocumented function
*
* @cover ::printAr
* @dataProvider printArProvider
* @testdox printAr $input will be $expected [$_dataName]
* @cover ::printArray
* @dataProvider printArrayProvider
* @testdox printAr/printArray $input will be $expected [$_dataName]
*
* @param array $input
* @param string $expected
@@ -195,7 +241,59 @@ final class CoreLibsDebugSupportTest extends TestCase
{
$this->assertEquals(
$expected,
\CoreLibs\Debug\Support::printAr($input)
\CoreLibs\Debug\Support::printAr($input),
'assert printAr'
);
$this->assertEquals(
$expected,
\CoreLibs\Debug\Support::printArray($input),
'assert printArray'
);
}
/**
* Undocumented function
*
* @cover ::printBool
* @dataProvider printBoolProvider
* @testdox printBool $input will be $expected [$_dataName]
*
* @param bool $input
* @param array $params
* @param string $expected
* @return void
*/
public function testPrintBool(bool $input, array $params, string $expected): void
{
if (
isset($params['name']) &&
isset($params['true']) &&
isset($params['false'])
) {
$string = \CoreLibs\Debug\Support::printBool(
$input,
$params['name'],
$params['true'],
$params['false']
);
} elseif (isset($params['name']) && isset($params['true'])) {
$string = \CoreLibs\Debug\Support::printBool(
$input,
$params['name'],
$params['true']
);
} elseif (isset($params['name'])) {
$string = \CoreLibs\Debug\Support::printBool(
$input,
$params['name']
);
} else {
$string = \CoreLibs\Debug\Support::printBool($input);
}
$this->assertEquals(
$expected,
$string,
'assert printBool'
);
}

View File

@@ -0,0 +1,162 @@
<?php
declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
use CoreLibs\Get\DotEnv;
/**
* Test class for ACL\Login
* @coversDefaultClass \CoreLibs\Get\DotEnv
* @testdox \CoreLibs\Get\DotEnv method tests
*/
final class CoreLibsGetDotEnvTest extends TestCase
{
/**
* Undocumented function
*
* @return array
*/
public function envFileProvider(): array
{
$dot_env_content = [
'SOMETHING' => 'A',
'OTHER' => 'B IS B',
'Complex' => 'A B \"D is F',
'HAS_SPACE' => 'ABC',
'HAS_COMMENT_QUOTES_SPACE' => 'Comment at end with quotes and space',
'HAS_COMMENT_QUOTES_NO_SPACE' => 'Comment at end with quotes no space',
'HAS_COMMENT_NO_QUOTES_SPACE' => 'Comment at end no quotes and space',
'HAS_COMMENT_NO_QUOTES_NO_SPACE' => 'Comment at end no quotes no space',
'COMMENT_IN_TEXT_QUOTES' => 'Foo bar # comment in here',
'FAILURE' => 'ABC',
'SIMPLEBOX' => 'A B C',
'TITLE' => '1',
'FOO' => '1.2',
'SOME.TEST' => 'Test Var',
'SOME.LIVE' => 'Live Var',
'A_TEST1' => 'foo',
'A_TEST2' => '${TEST1:-bar}',
'A_TEST3' => '${TEST4:-bar}',
'A_TEST5' => 'null',
'A_TEST6' => '${TEST5-bar}',
'A_TEST7' => '${TEST6:-bar}',
'B_TEST1' => 'foo',
'B_TEST2' => '${TEST1:=bar}',
'B_TEST3' => '${TEST4:=bar}',
'B_TEST5' => 'null',
'B_TEST6' => '${TEST5=bar}',
'B_TEST7' => '${TEST6=bar}',
'Test' => 'A',
'TEST' => 'B',
'LINE' => "ABC\nDEF",
'OTHERLINE' => "ABC\nAF\"ASFASDF\nMORESHIT",
'SUPERLINE' => '',
'__FOO_BAR_1' => 'b',
'__FOOFOO' => 'f ',
123123 => 'number',
'EMPTY' => '',
];
// 0: folder relative to test folder, if unset __DIR__
// 1: file, if unset .env
// 2: status to be returned
// 3: _ENV file content to be set
// 4: override chmod as octect in string
return [
'default' => [
'folder' => null,
'file' => null,
'status' => 3,
'content' => [],
'chmod' => null,
],
'cannot open file' => [
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
'file' => 'cannot_read.env',
'status' => 2,
'content' => [],
'chmod' => '000',
],
'empty file' => [
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
'file' => 'empty.env',
'status' => 1,
'content' => [],
'chmod' => null,
],
'override all' => [
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
'file' => 'test.env',
'status' => 0,
'content' => $dot_env_content,
'chmod' => null,
],
'override directory' => [
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
'file' => null,
'status' => 0,
'content' => $dot_env_content,
'chmod' => null,
],
];
}
/**
* test read .env file
*
* @covers ::readEnvFile
* @dataProvider envFileProvider
* @testdox Read _ENV file from $folder / $file with expected status: $expected_status and chmod $chmod [$_dataName]
*
* @param string|null $folder
* @param string|null $file
* @param int $expected_status
* @param array $expected_env
* @param string|null $chmod
* @return void
*/
public function testReadEnvFile(
?string $folder,
?string $file,
int $expected_status,
array $expected_env,
?string $chmod
): void {
// if we have file + chmod set
$old_chmod = null;
if (
is_file($folder . DIRECTORY_SEPARATOR . $file) &&
!empty($chmod)
) {
// get the old permissions
$old_chmod = fileperms($folder . DIRECTORY_SEPARATOR . $file);
chmod($folder . DIRECTORY_SEPARATOR . $file, octdec($chmod));
}
if ($folder !== null && $file !== null) {
$status = DotEnv::readEnvFile($folder, $file);
} elseif ($folder !== null) {
$status = DotEnv::readEnvFile($folder);
} else {
$status = DotEnv::readEnvFile();
}
$this->assertEquals(
$status,
$expected_status,
'Assert returned status equal'
);
// now assert read data
$this->assertEquals(
$_ENV,
$expected_env,
'Assert _ENV correct'
);
// if we have file and chmod unset
if ($old_chmod !== null) {
chmod($folder . DIRECTORY_SEPARATOR . $file, $old_chmod);
}
}
}
// __END__

View File

@@ -0,0 +1,941 @@
-- START: function/random_string.sql
-- create random string with length X
CREATE FUNCTION random_string(randomLength int)
RETURNS text AS $$
SELECT array_to_string(
ARRAY(
SELECT substring(
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
trunc(random() * 62)::int + 1,
1
)
FROM generate_series(1, randomLength) AS gs(x)
),
''
)
$$ LANGUAGE SQL
RETURNS NULL ON NULL INPUT
VOLATILE; -- LEAKPROOF;-- END: function/random_string.sql
-- START: function/set_edit_generic.sql
-- adds the created or updated date tags
CREATE OR REPLACE FUNCTION set_edit_generic() RETURNS TRIGGER AS '
DECLARE
random_length INT = 12; -- that should be long enough
BEGIN
IF TG_OP = ''INSERT'' THEN
NEW.date_created := ''now'';
NEW.cuid := random_string(random_length);
ELSIF TG_OP = ''UPDATE'' THEN
NEW.date_updated := ''now'';
END IF;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';
-- END: function/set_edit_generic.sql
-- START: function/edit_access_set_uid.sql
-- add uid add for edit_access table
CREATE OR REPLACE FUNCTION set_edit_access_uid() RETURNS TRIGGER AS
$$
DECLARE
myrec RECORD;
v_uid VARCHAR;
BEGIN
-- skip if NEW.name is not set
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
-- use NEW.name as base, remove all spaces
-- name data is already unique, so we do not need to worry about this here
v_uid := REPLACE(NEW.name, ' ', '');
IF TG_OP = 'INSERT' THEN
-- always set
NEW.uid := v_uid;
ELSIF TG_OP = 'UPDATE' THEN
-- check if not set, then set
SELECT INTO myrec t.* FROM edit_access t WHERE edit_access_id = NEW.edit_access_id;
IF FOUND THEN
NEW.uid := v_uid;
END IF;
END IF;
END IF;
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';
-- END: function/edit_access_set_uid.sql
-- START: function/edit_group_set_uid.sql
-- add uid add for edit_group table
CREATE OR REPLACE FUNCTION set_edit_group_uid() RETURNS TRIGGER AS
$$
DECLARE
myrec RECORD;
v_uid VARCHAR;
BEGIN
-- skip if NEW.name is not set
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
-- use NEW.name as base, remove all spaces
-- name data is already unique, so we do not need to worry about this here
v_uid := REPLACE(NEW.name, ' ', '');
IF TG_OP = 'INSERT' THEN
-- always set
NEW.uid := v_uid;
ELSIF TG_OP = 'UPDATE' THEN
-- check if not set, then set
SELECT INTO myrec t.* FROM edit_group t WHERE edit_group_id = NEW.edit_group_id;
IF FOUND THEN
NEW.uid := v_uid;
END IF;
END IF;
END IF;
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';
-- END: function/edit_group_set_uid.sql
-- START: function/edit_log_partition_insert.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2018-07-17
-- DESCRIPTION:
-- partition the edit_log table by year
-- auto creates table if missing, if failure writes to overflow table
-- HISTORY:
CREATE OR REPLACE FUNCTION edit_log_insert_trigger ()
RETURNS TRIGGER AS
$$
DECLARE
start_date DATE := '2010-01-01';
end_date DATE;
timeformat TEXT := 'YYYY';
selector TEXT := 'year';
base_table TEXT := 'edit_log';
_interval INTERVAL := '1 ' || selector;
_interval_next INTERVAL := '2 ' || selector;
table_name TEXT;
-- compare date column
compare_date DATE := NEW.event_date;
compare_date_name TEXT := 'event_date';
-- the create commands
command_create_table TEXT := 'CREATE TABLE IF NOT EXISTS {TABLE_NAME} (CHECK({COMPARE_DATE_NAME} >= {START_DATE} AND {COMPARE_DATE_NAME} < {END_DATE})) INHERITS ({BASE_NAME})';
command_create_primary_key TEXT := 'ALTER TABLE {TABLE_NAME} ADD PRIMARY KEY ({BASE_TABLE}_id)';
command_create_foreign_key_1 TEXT := 'ALTER TABLE {TABLE_NAME} ADD CONSTRAINT {TABLE_NAME}_euid_fkey FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL';
command_create_trigger_1 TEXT = 'CREATE TRIGGER trg_{TABLE_NAME} BEFORE INSERT OR UPDATE ON {TABLE_NAME} FOR EACH ROW EXECUTE PROCEDURE set_edit_generic()';
BEGIN
-- we are in valid start time area
IF (NEW.event_date >= start_date) THEN
-- current table name
table_name := base_table || '_' || to_char(NEW.event_date, timeformat);
BEGIN
EXECUTE 'INSERT INTO ' || quote_ident(table_name) || ' SELECT ($1).*' USING NEW;
-- if insert failed because of missing table, create new below
EXCEPTION
WHEN undefined_table THEN
-- another block, so in case the creation fails here too
BEGIN
-- create new table here + all indexes
start_date := date_trunc(selector, NEW.event_date);
end_date := date_trunc(selector, NEW.event_date + _interval);
-- creat table
EXECUTE format(REPLACE( -- end date
REPLACE( -- start date
REPLACE( -- compare date name
REPLACE( -- base name (inherit)
REPLACE( -- table name
command_create_table,
'{TABLE_NAME}',
table_name
),
'{BASE_NAME}',
base_table
),
'{COMPARE_DATE_NAME}',
compare_date_name
),
'{START_DATE}',
quote_literal(start_date)
),
'{END_DATE}',
quote_literal(end_date)
));
-- create all indexes and triggers
EXECUTE format(REPLACE(
REPLACE(
command_create_primary_key,
'{TABLE_NAME}',
table_name
),
'{BASE_TABLE}',
base_table
));
-- FK constraints
EXECUTE format(REPLACE(command_create_foreign_key_1, '{TABLE_NAME}', table_name));
-- generic trigger
EXECUTE format(REPLACE(command_create_trigger_1, '{TABLE_NAME}', table_name));
-- insert try again
EXECUTE 'INSERT INTO ' || quote_ident(table_name) || ' SELECT ($1).*' USING NEW;
EXCEPTION
WHEN OTHERS THEN
-- if this faled, throw it into the overflow table (so we don't loose anything)
INSERT INTO edit_log_overflow VALUES (NEW.*);
END;
-- other errors, insert into overlow
WHEN OTHERS THEN
-- if this faled, throw it into the overflow table (so we don't loose anything)
INSERT INTO edit_log_overflow VALUES (NEW.*);
END;
-- main insert run done, check if we have to create next months table
BEGIN
-- check if next month table exists
table_name := base_table || '_' || to_char((SELECT NEW.event_date + _interval)::DATE, timeformat);
-- RAISE NOTICE 'SEARCH NEXT: %', table_name;
IF (SELECT to_regclass(table_name)) IS NULL THEN
-- move inner interval same
start_date := date_trunc(selector, NEW.event_date + _interval);
end_date := date_trunc(selector, NEW.event_date + _interval_next);
-- RAISE NOTICE 'CREATE NEXT: %', table_name;
-- create table
EXECUTE format(REPLACE( -- end date
REPLACE( -- start date
REPLACE( -- compare date name
REPLACE( -- base name (inherit)
REPLACE( -- table name
command_create_table,
'{TABLE_NAME}',
table_name
),
'{BASE_NAME}',
base_table
),
'{COMPARE_DATE_NAME}',
compare_date_name
),
'{START_DATE}',
quote_literal(start_date)
),
'{END_DATE}',
quote_literal(end_date)
));
-- create all indexes and triggers
EXECUTE format(REPLACE(
REPLACE(
command_create_primary_key,
'{TABLE_NAME}',
table_name
),
'{BASE_TABLE}',
base_table
));
-- FK constraints
EXECUTE format(REPLACE(command_create_foreign_key_1, '{TABLE_NAME}', table_name));
-- generic trigger
EXECUTE format(REPLACE(command_create_trigger_1, '{TABLE_NAME}', table_name));
END IF;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'Failed to create next table: %', table_name;
END;
ELSE
-- if outside valid date, insert into overflow
INSERT INTO edit_log_overflow VALUES (NEW.*);
END IF;
RETURN NULL;
END
$$
LANGUAGE 'plpgsql';
-- END: function/edit_log_partition_insert.sql
-- START: table/edit_temp_files.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/08
-- DESCRIPTION:
-- edit interface temporary files, list of all files in edit (admin) directory
-- TABLE: temp_files
-- HISTORY:
-- DROP TABLE temp_files;
CREATE TABLE temp_files (
filename VARCHAR,
folder VARCHAR
);
-- END: table/edit_temp_files.sql
-- START: table/edit_generic.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- edit tables, this is the generic table, inheriteded by most edit tables
-- TABLE: edit_generic
-- HISTORY:
-- DROP TABLE edit_generic;
CREATE TABLE edit_generic (
cuid VARCHAR,
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
date_updated TIMESTAMP WITHOUT TIME ZONE
);
-- END: table/edit_generic.sql
-- START: table/edit_visible_group.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- edit tables, postgres SQL statements for the mysql definitions
-- TABLE: edit_visible_group
-- HISTORY
-- DROP TABLE edit_visible_group;
CREATE TABLE edit_visible_group (
edit_visible_group_id SERIAL PRIMARY KEY,
name VARCHAR,
flag VARCHAR
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_visible_group.sql
-- START: table/edit_menu_group.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- edit tables, groupings for menu
-- TABLE: edit_menu_group
-- HISTORY
-- DROP TABLE edit_menu_group;
CREATE TABLE edit_menu_group (
edit_menu_group_id SERIAL PRIMARY KEY,
name VARCHAR,
flag VARCHAR,
order_number INT NOT NULL
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_menu_group.sql
-- START: table/edit_page.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- edit tables, this table contains all pages in the edit interface and allocates rights + values to it
-- TABLE: edit_page
-- HISTORY:
-- DROP TABLE edit_page;
CREATE TABLE edit_page (
edit_page_id SERIAL PRIMARY KEY,
content_alias_edit_page_id INT, -- alias for page content, if the page content is defined on a different page, ege for ajax backend pages
FOREIGN KEY (content_alias_edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE RESTRICT ON UPDATE CASCADE,
filename VARCHAR,
name VARCHAR UNIQUE,
order_number INT NOT NULL,
online SMALLINT NOT NULL DEFAULT 0,
menu SMALLINT NOT NULL DEFAULT 0,
popup SMALLINT NOT NULL DEFAULT 0,
popup_x SMALLINT,
popup_y SMALLINT,
hostname VARCHAR
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_page.sql
-- START: table/edit_query_string.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- edit tables
-- TABLE: edit_query_string
-- HISTORY:
-- DROP TABLE edit_query_string;
CREATE TABLE edit_query_string (
edit_query_string_id SERIAL PRIMARY KEY,
edit_page_id INT NOT NULL,
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
enabled SMALLINT NOT NULL DEFAULT 0,
name VARCHAR,
value VARCHAR,
dynamic SMALLINT NOT NULL DEFAULT 0
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_query_string.sql
-- START: table/edit_page_visible_group.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- reference table between visible groups and pages
-- TABLE: edit_page_visible_group
-- HISTORY:
-- DROP TABLE edit_page_visible_group;
CREATE TABLE edit_page_visible_group (
edit_page_id INT NOT NULL,
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_visible_group_id INT NOT NULL,
FOREIGN KEY (edit_visible_group_id) REFERENCES edit_visible_group (edit_visible_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
);
-- END: table/edit_page_visible_group.sql
-- START: table/edit_page_menu_group.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- reference table between menu groups and pages
-- TABLE: edit_page_menu_group
-- HISTORY:
-- DROP TABLE edit_page_menu_group;
CREATE TABLE edit_page_menu_group (
edit_page_id INT NOT NULL,
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_menu_group_id INT NOT NULL,
FOREIGN KEY (edit_menu_group_id) REFERENCES edit_menu_group (edit_menu_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
);
-- END: table/edit_page_menu_group.sql
-- START: table/edit_access_right.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- holds all access right levels for the edit interface and other access areas
-- this table is fixed, prefilled and not changable
-- TABLE: edit_access_right
-- HISTORY:
-- DROP TABLE edit_access_right;
CREATE TABLE edit_access_right (
edit_access_right_id SERIAL PRIMARY KEY,
name VARCHAR,
level SMALLINT,
type VARCHAR,
UNIQUE (level,type)
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_access_right.sql
-- START: table/edit_scheme.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- holds backend template schemes
-- TABLE: edit_scheme
-- HISTORY:
-- DROP TABLE edit_scheme;
CREATE TABLE edit_scheme (
edit_scheme_id SERIAL PRIMARY KEY,
enabled SMALLINT NOT NULL DEFAULT 0,
name VARCHAR,
header_color VARCHAR,
css_file VARCHAR,
template VARCHAR
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_scheme.sql
-- START: table/edit_language.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- languages for the backend, this not used for the encoding, but only for having different language strings
-- the backend encoding is all UTF-8 (not changeable)
-- TABLE: edit_language
-- HISTORY:
-- DROP TABLE edit_language;
CREATE TABLE edit_language (
edit_language_id SERIAL PRIMARY KEY,
enabled SMALLINT NOT NULL DEFAULT 0,
lang_default SMALLINT NOT NULL DEFAULT 0,
long_name VARCHAR,
short_name VARCHAR, -- en_US, en or en_US@latin without encoding
iso_name VARCHAR, -- should actually be encoding
order_number INT
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_language.sql
-- START: table/edit_group.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- list of pages the user can access, with a generic access level, one group per user
-- TABLE: edit_group
-- HISTORY:
-- DROP TABLE edit_group;
CREATE TABLE edit_group (
edit_group_id SERIAL PRIMARY KEY,
edit_scheme_id INT,
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_access_right_id INT NOT NULL,
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
enabled SMALLINT NOT NULL DEFAULT 0,
deleted SMALLINT DEFAULT 0,
uid VARCHAR,
name VARCHAR,
additional_acl JSONB
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_group.sql
-- START: table/edit_page_access.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- groups pages together to one page group to which the user is then subscribed
-- TABLE: edit_page_access
-- HISTORY:
-- DROP TABLE edit_page_access;
CREATE TABLE edit_page_access (
edit_page_access_id SERIAL PRIMARY KEY,
edit_group_id INT NOT NULL,
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_page_id INT NOT NULL,
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_access_right_id INT NOT NULL,
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
enabled SMALLINT NOT NULL DEFAULT 0
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_page_access.sql
-- START: table/edit_page_content.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2019/9/9
-- DESCRIPTION:
-- sub content to one page with additional edit access right set
-- can be eg JS content groups on one page
-- TABLE: edit_page_content
-- HISTORY:
-- DROP TABLE edit_page_content;
CREATE TABLE edit_page_content (
edit_page_content_id SERIAL PRIMARY KEY,
edit_page_id INT NOT NULL,
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_access_right_id INT NOT NULL,
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
uid VARCHAR UNIQUE,
name VARCHAR,
order_number INT NOT NULL,
online SMALLINT NOT NULL DEFAULT 0
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_page_content.sql
-- START: table/edit_user.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/06
-- DESCRIPTION:
-- holds the user that can login + group, scheme, lang and a default access right
-- TABLE: edit_user
-- HISTORY:
-- DROP TABLE edit_user;
CREATE TABLE edit_user (
edit_user_id SERIAL PRIMARY KEY,
connect_edit_user_id INT, -- possible reference to other user
FOREIGN KEY (connect_edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_language_id INT NOT NULL,
FOREIGN KEY (edit_language_id) REFERENCES edit_language (edit_language_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_group_id INT NOT NULL,
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_scheme_id INT,
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_access_right_id INT NOT NULL,
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
enabled SMALLINT NOT NULL DEFAULT 0,
deleted SMALLINT NOT NULL DEFAULT 0,
username VARCHAR UNIQUE,
password VARCHAR,
first_name VARCHAR,
last_name VARCHAR,
first_name_furigana VARCHAR,
last_name_furigana VARCHAR,
debug SMALLINT NOT NULL DEFAULT 0,
db_debug SMALLINT NOT NULL DEFAULT 0,
email VARCHAR,
protected SMALLINT NOT NULL DEFAULT 0,
admin SMALLINT NOT NULL DEFAULT 0,
last_login TIMESTAMP WITHOUT TIME ZONE,
login_error_count INT DEFAULT 0,
login_error_date_last TIMESTAMP WITHOUT TIME ZONE,
login_error_date_first TIMESTAMP WITHOUT TIME ZONE,
strict SMALLINT DEFAULT 0,
locked SMALLINT DEFAULT 0,
password_change_date TIMESTAMP WITHOUT TIME ZONE, -- only when password is first set or changed
password_change_interval INTERVAL, -- null if no change is needed, or d/m/y time interval
password_reset_time TIMESTAMP WITHOUT TIME ZONE, -- when the password reset was requested
password_reset_uid VARCHAR, -- the uid to access the password reset page
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
) INHERITS (edit_generic) WITHOUT OIDS;
COMMENT ON COLUMN edit_user.password_reset_time IS 'When the password reset was requested. For reset page uid valid check';
COMMENT ON COLUMN edit_user.password_reset_uid IS 'Password reset page uid';
-- END: table/edit_user.sql
-- START: table/edit_log.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- log data for backend interface, logs all user activities
-- TABLE: edit_log
-- HISTORY:
-- DROP TABLE edit_log;
CREATE TABLE edit_log (
edit_log_id SERIAL PRIMARY KEY,
euid INT, -- this is a foreign key, but I don't nedd to reference to it
FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL,
username VARCHAR,
password VARCHAR,
event_date TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
ip VARCHAR,
error TEXT,
event TEXT,
data_binary BYTEA,
data TEXT,
page VARCHAR,
action VARCHAR,
action_id VARCHAR,
action_yes VARCHAR,
action_flag VARCHAR,
action_menu VARCHAR,
action_loaded VARCHAR,
action_value VARCHAR,
action_type VARCHAR,
action_error VARCHAR,
user_agent VARCHAR,
referer VARCHAR,
script_name VARCHAR,
query_string VARCHAR,
server_name VARCHAR,
http_host VARCHAR,
http_accept VARCHAR,
http_accept_charset VARCHAR,
http_accept_encoding VARCHAR,
session_id VARCHAR
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_log.sql
-- START: table/edit_log_overflow.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2020/1/28
-- DESCRIPTION:
-- edit log overflow table
-- this is the overflow table for partition
-- TABLE: edit_log_overflow
-- HISTORY:
-- DROP TABLE edit_log_overflow;
CREATE TABLE IF NOT EXISTS edit_log_overflow () INHERITS (edit_log);
ALTER TABLE edit_log_overflow ADD PRIMARY KEY (edit_log_id);
ALTER TABLE edit_log_overflow ADD CONSTRAINT edit_log_overflow_euid_fkey FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL;
-- END: table/edit_log_overflow.sql
-- START: table/edit_access.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- is a "group" for the outside, a user can have serveral groups with different rights so he can access several parts from the outside
-- TABLE: edit_access
-- HISTORY:
-- DROP TABLE edit_access;
CREATE TABLE edit_access (
edit_access_id SERIAL PRIMARY KEY,
enabled SMALLINT NOT NULL DEFAULT 0,
protected SMALLINT DEFAULT 0,
deleted SMALLINT DEFAULT 0,
uid VARCHAR,
name VARCHAR UNIQUE,
description VARCHAR,
color VARCHAR,
additional_acl JSONB
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_access.sql
-- START: table/edit_access_user.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2005/07/05
-- DESCRIPTION:
-- groupings which user has rights to which access groups (incl ACL)
-- TABLE: edit_access_user
-- HISTORY:
-- DROP TABLE edit_access_user;
CREATE TABLE edit_access_user (
edit_access_user_id SERIAL PRIMARY KEY,
edit_access_id INT NOT NULL,
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_user_id INT NOT NULL,
FOREIGN KEY (edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_access_right_id INT NOT NULL,
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
edit_default SMALLINT DEFAULT 0,
enabled SMALLINT NOT NULL DEFAULT 0
) INHERITS (edit_generic) WITHOUT OIDS;
-- END: table/edit_access_user.sql
-- START: table/edit_access_data.sql
-- AUTHOR: Clemens Schwaighofer
-- DATE: 2016/7/15
-- DESCRIPTION:
-- sub table to edit access, holds additional data for access group
-- TABLE: edit_access_data
-- HISTORY:
-- DROP TABLE edit_access_data;
CREATE TABLE edit_access_data (
edit_access_data_id SERIAL PRIMARY KEY,
edit_access_id INT NOT NULL,
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
enabled SMALLINT NOT NULL DEFAULT 0,
name VARCHAR,
value VARCHAR
) INHERITS (edit_generic) WITHOUT OIDS;
-- create a unique index for each attached data block for each edit access can
-- only have ONE value;
CREATE UNIQUE INDEX edit_access_data_edit_access_id_name_ukey ON edit_access_data (edit_access_id, name);
-- END: table/edit_access_data.sql
-- START: trigger/trg_edit_access_right.sql
-- DROP TRIGGER IF EXISTS trg_edit_access_right ON edit_access_right;
CREATE TRIGGER trg_edit_access_right
BEFORE INSERT OR UPDATE ON edit_access_right
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_access_right.sql
-- START: trigger/trg_edit_access.sql
-- DROP TRIGGER IF EXISTS trg_edit_access ON edit_access;
CREATE TRIGGER trg_edit_access
BEFORE INSERT OR UPDATE ON edit_access
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- DROP TRIGGER IF EXISTS trg_set_edit_access_uid ON edit_access;
CREATE TRIGGER trg_set_edit_access_uid
BEFORE INSERT OR UPDATE ON edit_access
FOR EACH ROW EXECUTE PROCEDURE set_edit_access_uid();
-- END: trigger/trg_edit_access.sql
-- START: trigger/trg_edit_access_data.sql
-- DROP TRIGGER IF EXISTS trg_edit_access_data ON edit_access_data;
CREATE TRIGGER trg_edit_access_data
BEFORE INSERT OR UPDATE ON edit_access_data
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_access_data.sql
-- START: trigger/trg_edit_access_user.sql
-- DROP TRIGGER IF EXISTS trg_edit_access_user ON edit_access_user;
CREATE TRIGGER trg_edit_access_user
BEFORE INSERT OR UPDATE ON edit_access_user
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_access_user.sql
-- START: trigger/trg_edit_group.sql
-- DROP TRIGGER IF EXISTS trg_edit_group ON edit_group;
CREATE TRIGGER trg_edit_group
BEFORE INSERT OR UPDATE ON edit_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- DROP TRIGGER IF EXISTS trg_set_edit_group_uid ON edit_group;
CREATE TRIGGER trg_set_edit_group_uid
BEFORE INSERT OR UPDATE ON edit_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_group_uid();
-- END: trigger/trg_edit_group.sql
-- START: trigger/trg_edit_language.sql
-- DROP TRIGGER IF EXISTS trg_edit_language ON edit_language;
CREATE TRIGGER trg_edit_language
BEFORE INSERT OR UPDATE ON edit_language
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_language.sql
-- START: trigger/trg_edit_log_overflow.sql
-- DROP TRIGGER IF EXISTS trg_edit_log_overflow ON edit_log_overflow;
CREATE TRIGGER trg_edit_log_overflow
BEFORE INSERT OR UPDATE ON edit_log_overflow
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_log_overflow.sql
-- START: trigger/trg_edit_log.sql
-- DROP TRIGGER IF EXISTS trg_edit_log ON edit_log;
CREATE TRIGGER trg_edit_log
BEFORE INSERT OR UPDATE ON edit_log
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- DROP TRIGGER IF EXISTS trg_edit_log_insert_partition ON edit_log;
CREATE TRIGGER trg_edit_log_insert_partition
BEFORE INSERT OR UPDATE ON edit_log
FOR EACH ROW EXECUTE PROCEDURE edit_log_insert_trigger();
-- END: trigger/trg_edit_log.sql
-- START: trigger/trg_edit_page_access.sql
-- DROP TRIGGER IF EXISTS trg_edit_page_access ON edit_page_access;
CREATE TRIGGER trg_edit_page_access
BEFORE INSERT OR UPDATE ON edit_page_access
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_page_access.sql
-- START: trigger/trg_edit_page_content.sql
-- DROP TRIGGER IF EXISTS trg_edit_page_content ON edit_page_content;
CREATE TRIGGER trg_edit_page_content
BEFORE INSERT OR UPDATE ON edit_page_content
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_page_content.sql
-- START: trigger/trg_edit_page.sql
-- DROP TRIGGER IF EXISTS trg_edit_page ON edit_page;
CREATE TRIGGER trg_edit_page
BEFORE INSERT OR UPDATE ON edit_page
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_page.sql
-- START: trigger/trg_edit_query_string.sql
-- DROP TRIGGER IF EXISTS trg_edit_query_string ON edit_query_string;
CREATE TRIGGER trg_edit_query_string
BEFORE INSERT OR UPDATE ON edit_query_string
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_query_string.sql
-- START: trigger/trg_edit_scheme.sql
-- DROP TRIGGER IF EXISTS trg_edit_scheme ON edit_scheme;
CREATE TRIGGER trg_edit_scheme
BEFORE INSERT OR UPDATE ON edit_scheme
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_scheme.sql
-- START: trigger/trg_edit_user.sql
-- DROP TRIGGER IF EXISTS trg_edit_user ON edit_user;
CREATE TRIGGER trg_edit_user
BEFORE INSERT OR UPDATE ON edit_user
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_user.sql
-- START: trigger/trg_edit_visible_group.sql
-- DROP TRIGGER IF EXISTS trg_edit_visible_group ON edit_visible_group;
CREATE TRIGGER trg_edit_visible_group
BEFORE INSERT OR UPDATE ON edit_visible_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_visible_group.sql
-- START: trigger/trg_edit_menu_group.sql
-- DROP TRIGGER IF EXISTS trg_edit_menu_group ON edit_menu_group;
CREATE TRIGGER trg_edit_menu_group
BEFORE INSERT OR UPDATE ON edit_menu_group
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
-- END: trigger/trg_edit_menu_group.sql
-- START: data/edit_tables.sql
-- edit tables insert data in order
-- edit visible group
DELETE FROM edit_visible_group;
INSERT INTO edit_visible_group (name, flag) VALUES ('Main Menu', 'main');
INSERT INTO edit_visible_group (name, flag) VALUES ('Data popup Menu', 'datapopup');
-- edit menu group
DELETE FROM edit_menu_group;
INSERT INTO edit_menu_group (name, flag, order_number) VALUES ('Admin Menu', 'admin', 1);
INSERT INTO edit_menu_group (name, flag, order_number) VALUES ('Admin Data Popup Menu', 'AdminDataPopup', 2);
-- edit page
DELETE FROM edit_page;
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_pages.php', 'Edit Pages', 1, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_users.php', 'Edit Users', 2, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_languages.php', 'Edit Languages', 3, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_schemes.php', 'Edit Schemes', 4, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_groups.php', 'Edit Groups', 5, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_visible_group.php', 'Edit Visible Groups', 6, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_menu_group.php', 'Edit Menu Groups', 7, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_access.php', 'Edit Access', 8, 1, 1);
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_order.php', 'Edit Order', 9, 1, 0);
-- edit visible group
DELETE FROM edit_page_visible_group;
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Pages'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Users'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Languages'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Schemes'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Groups'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Visible Groups'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Menu Groups'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Access'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
-- INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Order'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
-- edit page menu group
DELETE FROM edit_page_menu_group;
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Pages'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Users'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Languages'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Schemes'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Groups'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Visible Groups'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Menu Groups'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Access'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
-- INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Order'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
-- edit access right
DELETE FROM edit_access_right;
INSERT INTO edit_access_right (name, level, type) VALUES ('Default', -1, 'default');
INSERT INTO edit_access_right (name, level, type) VALUES ('No Access', 0, 'none');
INSERT INTO edit_access_right (name, level, type) VALUES ('List', 10, 'list');
INSERT INTO edit_access_right (name, level, type) VALUES ('Read', 20, 'read');
INSERT INTO edit_access_right (name, level, type) VALUES ('Translator', 30, 'mod_trans');
INSERT INTO edit_access_right (name, level, type) VALUES ('Modify', 40, 'mod');
INSERT INTO edit_access_right (name, level, type) VALUES ('Create/Write', 60, 'write');
INSERT INTO edit_access_right (name, level, type) VALUES ('Delete', 80, 'del');
INSERT INTO edit_access_right (name, level, type) VALUES ('Site Admin', 90, 'siteadmin');
INSERT INTO edit_access_right (name, level, type) VALUES ('Admin', 100, 'admin');
-- edit scheme
DELETE FROM edit_scheme;
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Default Scheme', 'E0E2FF', 1);
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Admin', 'CC7E7E', 1);
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Visitor', 'B0C4B3', 1);
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('User', '1E789E', 1);
-- edit language
-- short_name = locale without encoding
-- iso_name = encoding
DELETE FROM edit_language;
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('English', 'en_US', 'UTF-8', 1, 1, 1);
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('Japanese', 'ja_JP', 'UTF-8', 2, 1, 0);
-- edit group
DELETE FROM edit_group;
INSERT INTO edit_group (name, enabled, edit_scheme_id, edit_access_right_id) VALUES ('Admin', 1, (SELECT edit_scheme_id FROM edit_scheme WHERE name = 'Admin'), (SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin'));
INSERT INTO edit_group (name, enabled, edit_scheme_id, edit_access_right_id) VALUES ('User', 1, (SELECT edit_scheme_id FROM edit_scheme WHERE name = 'User'), (SELECT edit_access_right_id FROM edit_access_right WHERE type = 'write'));
-- edit page access
DELETE FROM edit_page_access;
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Pages'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Users'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Languages'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Schemes'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Groups'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Visible Groups'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Menu Groups'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Access'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Order'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
-- edit user
-- inserts admin user so basic users can be created
DELETE FROM edit_user;
INSERT INTO edit_user (username, password, enabled, debug, db_debug, email, protected, admin, edit_language_id, edit_group_id, edit_scheme_id, edit_access_right_id) VALUES ('admin', 'admin', 1, 1, 1, '', 1, 1,
(SELECT edit_language_id FROM edit_language WHERE short_name = 'en_US'),
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
(SELECT edit_scheme_id FROM edit_scheme WHERE name = 'Admin'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
-- edit access
DELETE FROM edit_access;
INSERT INTO edit_access (name, enabled, protected) VALUES ('Admin Access', 1, 1);
-- edit access user
DELETE FROM edit_access_user;
INSERT INTO edit_access_user (edit_default, enabled, edit_access_id, edit_user_id, edit_access_right_id) VALUES (1, 1,
(SELECT edit_access_id FROM edit_access WHERE uid = 'AdminAccess'),
(SELECT edit_user_id FROM edit_user WHERE username = 'admin'),
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
);
-- END: data/edit_tables.sql

1
4dev/tests/dotenv/.env Symbolic link
View File

@@ -0,0 +1 @@
test.env

View File

View File

View File

@@ -0,0 +1,49 @@
# enviroment file
SOMETHING=A
OTHER="B IS B"
Complex="A B \"D is F"
# COMMENT
HAS_SPACE= "ABC";
# COMMENT AT END
HAS_COMMENT_QUOTES_SPACE="Comment at end with quotes and space" # Comment QE
HAS_COMMENT_QUOTES_NO_SPACE="Comment at end with quotes no space"# Comment QES
HAS_COMMENT_NO_QUOTES_SPACE=Comment at end no quotes and space # Comment NQE
HAS_COMMENT_NO_QUOTES_NO_SPACE=Comment at end no quotes no space# Comment NQES
COMMENT_IN_TEXT_QUOTES="Foo bar # comment in here"
FAILURE = ABC
SIMPLEBOX= A B C
TITLE=1
FOO=1.2
SOME.TEST=Test Var
SOME.LIVE=Live Var
# VAR TESTS -
A_TEST1 = foo
A_TEST2 = ${TEST1:-bar} # TEST1 is set so the value of TEST2 = foo
A_TEST3 = ${TEST4:-bar} # TEST4 is not set so the value of TEST3 = bar
A_TEST5 = null
A_TEST6 = ${TEST5-bar} # TEST5 is set but empty so the value of TEST6 = null
A_TEST7 = ${TEST6:-bar} # TEST5 is set and empty so the value of TEST7 = bar
# VAR TESTS =
B_TEST1 = foo
B_TEST2 = ${TEST1:=bar} # TEST1 is set so the value of TEST2 = foo
B_TEST3 = ${TEST4:=bar} # TEST4 is not set so the value of TEST3 = bar and TEST4 = bar
B_TEST5 = null
B_TEST6 = ${TEST5=bar} # TEST5 is set but emtpy so the value of TEST6 = null
B_TEST7 = ${TEST6=bar} # TEST5 is set and empty so the value of TEST7 = bar and TEST5 = bar
# VAR TEST END
Test="A"
TEST="B"
TEST="D"
LINE="ABC
DEF"
OTHERLINE="ABC
AF\"ASFASDF
MORESHIT"
SUPERLINE=
"asfasfasf"
__FOO_BAR_1 = b
__FOOFOO = f
123123=number
EMPTY=
= flase
asfasdf

View File

@@ -0,0 +1,140 @@
<?php // phpcs:ignore warning
/**
* @phan-file-suppress PhanTypeSuspiciousStringExpression
*/
declare(strict_types=1);
// turn on all error reporting
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file
define('USE_DATABASE', true);
// sample config
require 'config.php';
// override ECHO ALL FALSE
$ECHO_ALL = true;
// define log file id
$LOG_FILE_ID = 'classTest-db';
ob_end_flush();
use CoreLibs\Debug\Support;
use CoreLibs\Debug\RunningTime;
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => $LOG_FILE_ID,
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
// db connection and attach logger
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$db->log->debug('START', '=============================>');
$PAGE_NAME = 'TEST CLASS: DB dbReturn';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><a href="class_test.db.php">Class Test DB</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
print "LOGFILE NAME: " . $db->log->getSetting('log_file_name') . "<br>";
print "LOGFILE ID: " . $db->log->getSetting('log_file_id') . "<br>";
print "DBINFO: " . $db->dbInfo() . "<br>";
// DB client encoding
print "DB client encoding: " . $db->dbGetEncoding() . "<br>";
print "DB search path: " . $db->dbGetSchema() . "<br>";
// SELECT read tests with dbReturn and cache values
print "<br>";
print "<b>dbReturn CACHE tests</b><br>";
// DATA has two rows for reading
// delete and repare base data
$db->dbExec("DELETE FROM test_db_return");
$db->dbExec("INSERT INTO test_db_return (uid, data) VALUES ('A1', 'Test A'), ('B1', 'Test B')");
// read query to use
$q_db_ret = "SELECT * FROM test_db_return ORDER BY uid";
RunningTime::hrRunningTime();
$cache_flag = 'USE_CACHE (0)';
print "dbReturn '" . $cache_flag . "'/Default: " . $q_db_ret . "<br>";
// SINGLE read on multi row return
// Do twice
for ($i = 1; $i <= 6; $i++) {
$res = $db->dbReturn($q_db_ret);
print $i . ") " . $cache_flag . ": "
. "res: " . (is_bool($res) ?
"<b>Bool:</b> " . $db->log->prBl($res) :
(is_array($res) ?
"Array: " . $db->log->prBl(is_array($res)) : '{-}')
) . ", "
. "cursor_ext: <pre>" . Support::printAr($db->dbGetCursorExt($q_db_ret)) . "</pre>";
print "Run time: " . RunningTime::hrRunningTime() . "<br>";
}
// reset all read data
$db->dbCacheReset($q_db_ret);
echo "<hr>";
$cache_flag = 'READ_NEW (1)';
print "dbReturn '" . $cache_flag . "': " . $q_db_ret . "<br>";
// NO CACHE
for ($i = 1; $i <= 6; $i++) {
$res = $db->dbReturn($q_db_ret, $db::READ_NEW);
print $i . ") " . $cache_flag . ": "
. "res: " . (is_bool($res) ?
"<b>Bool:</b> " . $db->log->prBl($res) :
(is_array($res) ?
"Array: " . $db->log->prBl(is_array($res)) : '{-}')
) . ", "
. "cursor_ext: <pre>" . Support::printAr($db->dbGetCursorExt($q_db_ret)) . "</pre>";
print "Run time: " . RunningTime::hrRunningTime() . "<br>";
}
// reset all read data
$db->dbCacheReset($q_db_ret);
echo "<hr>";
$cache_flag = 'CLEAR_CACHE (2)';
print "dbReturn '" . $cache_flag . "': " . $q_db_ret . "<br>";
// NO CACHE
for ($i = 1; $i <= 6; $i++) {
$res = $db->dbReturn($q_db_ret, $db::CLEAR_CACHE);
print $i . ") " . $cache_flag . ": "
. "res: " . (is_bool($res) ?
"<b>Bool:</b> " . $db->log->prBl($res) :
(is_array($res) ?
"Array: " . $db->log->prBl(is_array($res)) : '{-}')
) . ", "
. "cursor_ext: <pre>" . Support::printAr($db->dbGetCursorExt($q_db_ret)) . "</pre>";
print "Run time: " . RunningTime::hrRunningTime() . "<br>";
}
// reset all read data
$db->dbCacheReset($q_db_ret);
echo "<hr>";
$cache_flag = 'NO_CACHE (3)';
print "dbReturn '" . $cache_flag . "': " . $q_db_ret . "<br>";
// NO CACHE
for ($i = 1; $i <= 6; $i++) {
$res = $db->dbReturn($q_db_ret, $db::NO_CACHE);
print $i . ") " . $cache_flag . ": "
. "res: " . (is_bool($res) ?
"<b>Bool:</b> " . $db->log->prBl($res) :
(is_array($res) ?
"Array: " . $db->log->prBl(is_array($res)) : '{-}')
) . ", "
. "cursor_ext: <pre>" . Support::printAr($db->dbGetCursorExt($q_db_ret)) . "</pre>";
print "Run time: " . RunningTime::hrRunningTime() . "<br>";
}
// reset all data
$db->dbCacheReset($q_db_ret);
print "<br>";
print "Overall Run time: " . RunningTime::hrRunningTimeFromStart() . "<br>";
// __END__

View File

@@ -44,6 +44,7 @@ print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><a href="class_test.db.dbReturn.php">Class Test DB dbReturn</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
print "LOGFILE NAME: " . $db->log->getSetting('log_file_name') . "<br>";
@@ -72,6 +73,8 @@ $db->dbSetEncoding('SJIS');
print "ENCODING TEST: " . $db->dbVersionInfo('client_encoding') . "/" . $db->dbGetEncoding() . "<br>";
$db->dbResetEncoding();
// TEST CACHE READS
$res = $db->dbReturn("SELECT * FROM max_test");
print "DB RETURN ROWS: " . $db->dbGetNumRows() . "<br>";
@@ -97,6 +100,12 @@ print "NO CACHED DATA: <pre>" . print_r($db->dbGetCursorExt(), true) . "</pre><b
// print "UUD/TIME: " . $res['uid'] . "/" . $res['time'] . "<br>";
// }
// dbReturn tests on separate page
print "<br>";
print "<b>dbReturn CACHE tests</b><br>";
print '<a href="class_test.db.dbReturn.php">Class Test DB dbReturn</a><br>';
print "<br>";
print "<pre>";
print "SOCKET: " . pg_socket($db->dbGetDbh()) . "<br>";
@@ -182,7 +191,6 @@ print "UPDATE WITH PK " . $last_insert_pk
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
// INSERT WITH NO RETURNING
$status = $db->dbExec("INSERT INTO test_foobar (type, integer) VALUES ('WITHOUT DATA', 456)");
print "INSERT WITH NO PRIMARY KEY NO RETURNING STATUS: " . Support::printToString($status) . " |<br>"
@@ -222,7 +230,6 @@ if (
}
}
# db write class test
$table = 'test_foo';
print "TABLE META DATA: " . DgS::printAr($db->dbShowTableMetaData($table)) . "<br>";

View File

@@ -66,6 +66,10 @@ print "S::GETCALLERMETHOD: " . test() . "<br>";
print "S::GETCALLERMETHODLIST: <pre>" . print_r(test2(), true) . "</pre><br>";
print "S::PRINTAR: " . DebugSupport::printAr(['Foo', 'Bar']) . "<br>";
print "V-S::PRINTAR: " . $debug_support_class::printAr(['Foo', 'Bar']) . "<br>";
print "S::PRINTBOOL(default): " . DebugSupport::printBool(true) . "<br>";
print "S::PRINTBOOL(name): " . DebugSupport::printBool(true, 'Name') . "<br>";
print "S::PRINTBOOL(name, ok): " . DebugSupport::printBool(true, 'Name', 'ok') . "<br>";
print "S::PRINTBOOL(name, ok, not): " . DebugSupport::printBool(false, 'Name', 'ok', 'not') . "<br>";
print "S::DEBUSTRING(s): " . DebugSupport::debugString('SET') . "<br>";
print "S::DEBUSTRING(''): " . DebugSupport::debugString('') . "<br>";
print "S::DEBUSTRING(,s): " . DebugSupport::debugString(null, '{-}') . "<br>";
@@ -181,6 +185,10 @@ $debug->debug('TEST PER LEVEL', 'Per level test');
$debug->debug('()', 'Per level test: invalid chars');
$debug->setLogPer('level', false);
$ar = ['A', 1, ['B' => 'D']];
$debug->debug('ARRAY', 'Array: ' . $debug->prAr($ar));
$debug->debug('BOOL', 'True: ' . $debug->prBl(true) . ', False: ' . $debug->prBl(false));
// error message
// future DEPRECATED
// $debug->debug('BASIC CLASS', 'Debug test');

View File

@@ -0,0 +1,91 @@
<?php // phpcs:ignore warning
/**
* @phan-file-suppress PhanTypeSuspiciousStringExpression
*/
declare(strict_types=1);
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
ob_start();
// basic class test file
define('USE_DATABASE', false);
// sample config
require 'config.php';
// define log file id
$LOG_FILE_ID = 'classTest-memoryusage';
ob_end_flush();
use CoreLibs\Debug\MemoryUsage;
use CoreLibs\Debug\Support;
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => $LOG_FILE_ID,
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$PAGE_NAME = 'TEST CLASS: MEMORY USAGE';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
MemoryUsage::debugMemoryFlag(true);
print "Debug Flag: " . Support::printBool(MemoryUsage::debugMemoryFlag()) . "<br>";
MemoryUsage::setStartMemory();
MemoryUsage::setMemory();
$data = MemoryUsage::memoryUsage('first run');
print "Memory usage 1 array: " . Support::printAr($data) . "<br>";
print "Memory usage 1 string: " . MemoryUsage::printMemoryUsage($data) . "<br>";
print "Memory usage 1 string raw: " . MemoryUsage::printMemoryUsage($data, true) . "<br>";
$var = 'foo';
$out = '';
for ($i = 1; $i <= 100; $i++) {
$out .= $var;
}
$data = MemoryUsage::memoryUsage('second run');
print "Memory usage 2 array: " . Support::printAr($data) . "<br>";
print "Memory usage 2 string: " . MemoryUsage::printMemoryUsage($data) . "<br>";
print "Memory usage 2 string raw: " . MemoryUsage::printMemoryUsage($data, true) . "<br>";
MemoryUsage::setMemory();
$var = 'foasdfasdfasdfasdfasdfo';
$out = '';
for ($i = 1; $i <= 10000; $i++) {
$out .= $var;
}
$data = MemoryUsage::memoryUsage('third run');
print "Memory usage 3 array: " . Support::printAr($data) . "<br>";
print "Memory usage 3 string: " . MemoryUsage::printMemoryUsage($data) . "<br>";
print "Memory usage 3 string raw: " . MemoryUsage::printMemoryUsage($data, true) . "<br>";
$var = 'foasdfasdfasdasdfasdfasdfadfadfasdfasdfo';
$out = '';
for ($i = 1; $i <= 100000; $i++) {
$out .= $var;
}
$data = MemoryUsage::memoryUsage('forth run');
print "Memory usage 4 array: " . Support::printAr($data) . "<br>";
print "Memory usage 4 string: " . MemoryUsage::printMemoryUsage($data) . "<br>";
print "Memory usage 4 string raw: " . MemoryUsage::printMemoryUsage($data, true) . "<br>";
// error message
print $log->printErrorMsg();
print "</body></html>";
// __END__

View File

@@ -54,6 +54,7 @@ print "<html><head><title>TEST CLASS</title><head>";
print "<body>";
print '<div><a href="class_test.db.php">Class Test: DB</a></div>';
print '<div><a href="class_test.db.DbReturn.php">Class Test: DB dbReturn</a></div>';
print '<div><a href="class_test.colors.php">Class Test: COLORS</a></div>';
print '<div><a href="class_test.mime.php">Class Test: MIME</a></div>';
print '<div><a href="class_test.json.php">Class Test: JSON</a></div>';
@@ -75,6 +76,7 @@ print '<div><a href="class_test.randomkey.php">Class Test: RANDOM KEY</a></div>'
print '<div><a href="class_test.system.php">Class Test: SYSTEM</a></div>';
print '<div><a href="class_test.readenvfile.php">Class Test: READ ENV FILE</a></div>';
print '<div><a href="class_test.runningtime.php">Class Test: RUNNING TIME</a></div>';
print '<div><a href="class_test.memoryusage.php">Class Test: MEMORY USAGE</a></div>';
print '<div><a href="class_test.debug.php">Class Test: DEBUG</a></div>';
print '<div><a href="class_test.output.form.php">Class Test: OUTPUT FORM</a></div>';
print '<div><a href="class_test.admin.backend.php">Class Test: BACKEND ADMIN CLASS</a></div>';
@@ -94,13 +96,13 @@ print "<div>READ _ENV ARRAY:</div>";
print CoreLibs\Debug\Support::printAr(array_map('htmlentities', $_ENV));
// set + check edit access id
$edit_access_id = 3;
if (is_object($login) && isset($login->acl['unit'])) {
print "ACL UNIT: " . print_r(array_keys($login->acl['unit']), true) . "<br>";
if (is_object($login) && isset($login->loginGetAcl()['unit'])) {
print "ACL UNIT: " . print_r(array_keys($login->loginGetAcl()['unit']), true) . "<br>";
print "ACCESS CHECK: " . (string)$login->loginCheckEditAccess($edit_access_id) . "<br>";
if ($login->loginCheckEditAccess($edit_access_id)) {
$backend->edit_access_id = $edit_access_id;
} else {
$backend->edit_access_id = $login->acl['unit_id'];
$backend->edit_access_id = $login->loginGetAcl()['unit_id'];
}
} else {
print "Something went wrong with the login<br>";
@@ -131,8 +133,8 @@ $log->debug('SOME MARK', 'Some error output');
// INTERNAL SET
print "EDIT ACCESS ID: " . $backend->edit_access_id . "<br>";
if (is_object($login)) {
// print "ACL: <br>".$backend->print_ar($login->acl)."<br>";
$log->debug('ACL', "ACL: " . \CoreLibs\Debug\Support::printAr($login->acl));
// print "ACL: <br>".$backend->print_ar($login->loginGetAcl())."<br>";
$log->debug('ACL', "ACL: " . \CoreLibs\Debug\Support::printAr($login->loginGetAcl()));
// print "DEFAULT ACL: <br>".$backend->print_ar($login->default_acl_list)."<br>";
// print "DEFAULT ACL: <br>".$backend->print_ar($login->default_acl_list)."<br>";
// $result = array_flip(
@@ -147,7 +149,7 @@ if (is_object($login)) {
// );
// print "DEFAULT ACL: <br>".$backend->print_ar($result)."<br>";
// DEPRICATED CALL
// $backend->adbSetACL($login->acl);
// $backend->adbSetACL($login->loginGetAcl());
}
print "THIS HOST: " . HOST_NAME . ", with PROTOCOL: " . HOST_PROTOCOL . " is running SSL: " . HOST_SSL . "<br>";

View File

@@ -40,6 +40,9 @@ print '<div><h1>' . $PAGE_NAME . '</h1></div>';
print "ALREADY from config.php: " . \CoreLibs\Debug\Support::printAr($_ENV) . "<br>";
// test .env in local
$status = \CoreLibs\Get\DotEnv::readEnvFile('.', 'test.env');
print "test.env: STATUS: " . $status . "<br>";
print "AFTER reading test.env file: " . \CoreLibs\Debug\Support::printAr($_ENV) . "<br>";
// error message
print $log->printErrorMsg();

View File

@@ -52,8 +52,17 @@ echo "TIMED [hr]: " . RunningTime::hrRunningTime() . "<br>";
echo "TIMED [def]: " . RunningTime::runningTime() . "<br>";
echo "TIMED [string]: " . RunningTime::runningTimeString() . "<br>";
RunningTime::hrRunningTime();
echo "TIMED [hr-end] " . RunningTime::hrRunningTimeFromStart() . "<br>";
echo "<br>";
echo "RANDOM KEY [default]: " . \CoreLibs\Create\RandomKey::randomKeyGen() . "<br>";
echo "TIMED [hr]: " . RunningTime::hrRunningTime() . "<br>";
echo "TIMED 1 [hr]: " . RunningTime::hrRunningTime() . "<br>";
echo "TIMED 1 [hr-n]: " . RunningTime::hrRunningTime() . "<br>";
echo "TIMED 1 [hr-b]: " . RunningTime::hrRunningTime() . "<br>";
echo "TIMED 1 [hr-end]: " . RunningTime::hrRunningTimeFromStart() . "<br>";
RunningTime::hrRunningTimeReset();
RunningTime::hrRunningTime();
echo "TIMED 2 [hr]: " . RunningTime::hrRunningTime() . "<br>";
echo "TIMED 2 [hr-end]: " . RunningTime::hrRunningTimeFromStart() . "<br>";
// error message
print $log->printErrorMsg();

View File

@@ -120,6 +120,21 @@ print "[READ] B " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
print "[READ] Confirm " . $var . " is " . $value . ": "
. (($_SESSION[$var] ?? '') == $value ? 'Matching' : 'Not matching') . "<br>";
// test set wrappers methods
$session->setS('setwrap', 'YES, method set _SESSION var');
print "[READ WRAP] A setwrap: " . $session->getS('setwrap') . "<br>";
print "[READ WRAP] Isset: " . ($session->issetS('setwrap') ? 'Yes' : 'No') . "<br>";
$session->unsetS('setwrap');
print "[READ WRAP] unset setwrap: " . $session->getS('setwrap') . "<br>";
print "[READ WRAP] unset Isset: " . ($session->issetS('setwrap') ? 'Yes' : 'No') . "<br>";
// test __get/__set
$session->setwrap = 'YES, magic set _SESSION var';
print "[READ MAGIC] A setwrap: " . $session->setwrap . "<br>";
print "[READ MAGIC] Isset: " . (isset($session->setwrap) ? 'Yes' : 'No') . "<br>";
unset($session->setwrap);
print "[READ MAGIC] unset setwrap: " . $session->setwrap . "<br>";
print "[READ MAGIC] unset Isset: " . (isset($session->setwrap) ? 'Yes' : 'No') . "<br>";
// differnt session name
$session_name = 'class-test-session-ALT';
if (false === ($session_id = $session->startSession($session_name))) {

1
www/admin/test.env Symbolic link
View File

@@ -0,0 +1 @@
../../4dev/tests/dotenv/test.env

38
www/composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "fb2235a66a37d89e7941a863843d2e15",
"content-hash": "a71e6f4fbc06f0efb6ad34538b515c53",
"packages": [],
"packages-dev": [
{
@@ -415,16 +415,16 @@
},
{
"name": "phpdocumentor/type-resolver",
"version": "1.6.0",
"version": "1.6.1",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706"
"reference": "77a32518733312af16a44300404e945338981de3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706",
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/77a32518733312af16a44300404e945338981de3",
"reference": "77a32518733312af16a44300404e945338981de3",
"shasum": ""
},
"require": {
@@ -459,9 +459,9 @@
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
"support": {
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0"
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.1"
},
"time": "2022-01-04T19:58:01+00:00"
"time": "2022-03-15T21:29:03+00:00"
},
{
"name": "phpspec/prophecy",
@@ -850,16 +850,16 @@
},
{
"name": "phpunit/phpunit",
"version": "9.5.19",
"version": "9.5.20",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807"
"reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35ea4b7f3acabb26f4bb640f8c30866c401da807",
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/12bc8879fb65aef2138b26fc633cb1e3620cffba",
"reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba",
"shasum": ""
},
"require": {
@@ -937,7 +937,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.19"
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.20"
},
"funding": [
{
@@ -949,7 +949,7 @@
"type": "github"
}
],
"time": "2022-03-15T09:57:31+00:00"
"time": "2022-04-01T12:37:26+00:00"
},
{
"name": "sebastian/cli-parser",
@@ -1317,16 +1317,16 @@
},
{
"name": "sebastian/environment",
"version": "5.1.3",
"version": "5.1.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
"reference": "388b6ced16caa751030f6a69e588299fa09200ac"
"reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/388b6ced16caa751030f6a69e588299fa09200ac",
"reference": "388b6ced16caa751030f6a69e588299fa09200ac",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7",
"reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7",
"shasum": ""
},
"require": {
@@ -1368,7 +1368,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/environment/issues",
"source": "https://github.com/sebastianbergmann/environment/tree/5.1.3"
"source": "https://github.com/sebastianbergmann/environment/tree/5.1.4"
},
"funding": [
{
@@ -1376,7 +1376,7 @@
"type": "github"
}
],
"time": "2020-09-28T05:52:38+00:00"
"time": "2022-04-03T09:37:03+00:00"
},
{
"name": "sebastian/exporter",

View File

@@ -232,10 +232,16 @@ if (
exit;
}
// set SSL on
if (
(array_key_exists('HTTPS', $_SERVER) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
$_SERVER['SERVER_PORT'] == 443
$is_secure = false;
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$is_secure = true;
} elseif (
!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ||
!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on'
) {
$is_secure = true;
}
if ($is_secure) {
define('HOST_SSL', true);
define('HOST_PROTOCOL', 'https://');
} else {

View File

@@ -50,7 +50,7 @@ for (
is_file($__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php')
) {
// load enviorment file if it exists
\CoreLibs\Get\ReadEnvFile::readEnvFile(
\CoreLibs\Get\DotEnv::readEnvFile(
$__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH
);
// load master config file that loads all other config files

View File

@@ -19,15 +19,17 @@ if (!empty($DEBUG_ALL) && !empty($ENABLE_ERROR_HANDLING)) {
//------------------------------ library include start
// set output to quiet for load of classes & session settings
ob_start();
// set the session name
$SET_SESSION_NAME = EDIT_SESSION_NAME;
$LOG_FILE_ID = BASE_NAME . 'Admin';
//------------------------------ library include end
//------------------------------ basic variable settings start
// set the session name
$SET_SESSION_NAME = EDIT_SESSION_NAME;
$LOG_FILE_ID = BASE_NAME . 'Admin';
// ajax page flag
if (!isset($AJAX_PAGE)) {
$AJAX_PAGE = false;
}
// zip download flag
if (!isset($ZIP_STREAM)) {
$ZIP_STREAM = false;
}
@@ -48,9 +50,9 @@ if ($AJAX_PAGE && !$ZIP_STREAM) {
// start session
$session = new \CoreLibs\Create\Session($SET_SESSION_NAME);
// create logger
$log = new CoreLibs\Debug\Logging([
$log = new \CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => LOG_FILE_ID,
'file_id' => $LOG_FILE_ID,
'print_file_date' => true,
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
@@ -69,9 +71,9 @@ if (
}
}
// db config with logger
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$db = new \CoreLibs\DB\IO(DB_CONFIG, $log);
// login & page access check
$login = new CoreLibs\ACL\Login($db, $log, $session);
$login = new \CoreLibs\ACL\Login($db, $log, $session);
// lang, path, domain
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
@@ -82,15 +84,15 @@ $l10n = new \CoreLibs\Language\L10n(
$locale['path'],
);
// create smarty object
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
$smarty = new \CoreLibs\Template\SmartyExtend($l10n, $locale);
// create new Backend class with db and loger attached
$cms = new CoreLibs\Admin\Backend($db, $log, $session, $l10n, $locale);
$cms = new \CoreLibs\Admin\Backend($db, $log, $session, $l10n, $locale);
// the menu show flag (what menu to show)
$cms->menu_show_flag = 'main';
// db info
$cms->db->dbInfo();
// set acl
$cms->setACL($login->acl);
$cms->setACL($login->loginGetAcl());
// flush (can we move that to header block above)
ob_end_flush();
//------------------------------ class init end

File diff suppressed because it is too large Load Diff

View File

@@ -116,6 +116,7 @@ class Backend
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
/**
* main class constructor
*
* @param \CoreLibs\DB\IO $db Database connection class
* @param \CoreLibs\Debug\Logging $log Logging class
* @param \CoreLibs\Create\Session $session Session interface class
@@ -175,6 +176,7 @@ class Backend
/**
* set internal ACL from login ACL
*
* @param array<mixed> $acl login acl array
*/
public function setACL(array $acl): void
@@ -183,7 +185,8 @@ class Backend
}
/**
* writes all action vars plus other info into edit_log tabl
* writes all action vars plus other info into edit_log table
*
* @param string $event any kind of event description,
* @param string|array<mixed> $data any kind of data related to that event
* @param string $write_type write type can bei STRING or BINARY
@@ -255,6 +258,7 @@ class Backend
/**
* Set the menu show flag
*
* @param string|int $menu_show_flag
* @return string|int
*/
@@ -267,6 +271,7 @@ class Backend
/**
* Return the menu show flag
*
* @return string|int
*/
public function adbGetMenuShowFlag()
@@ -276,6 +281,7 @@ class Backend
/**
* menu creater (from login menu session pages)
*
* @param int $flag visible flag trigger
* @return array<mixed> menu array for output on page (smarty)
*/
@@ -403,6 +409,7 @@ class Backend
/**
* ONLY USED IN adbTopMenu
* checks if this filename is in the current situation (user id, etc) available
*
* @param string|null $filename filename
* @return bool true for visible/accessable menu point, false for not
*/
@@ -422,8 +429,8 @@ class Backend
}
/**
* @deprecated
* creates out of a normal db_return array an assoc array
*
* @param array<mixed> $db_array input array
* @param string|int|bool $key key
* @param string|int|bool $value value
@@ -440,8 +447,8 @@ class Backend
}
/**
* @deprecated
* converts bytes into formated string with KB, MB, etc
*
* @param string|int|float $number string or int or number
* @return string formatted string
* @deprecated \CoreLibs\Convert\Byte::humanReadableByteFormat()
@@ -456,8 +463,8 @@ class Backend
}
/**
* @deprecated
* converts picture to a thumbnail with max x and max y size
*
* @param string $pic source image file with or without path
* @param int $size_x maximum size width
* @param int $size_y maximum size height
@@ -485,6 +492,7 @@ class Backend
/**
* wrapper function to fill up the mssages array
*
* @param string $level info/warning/error
* @param string $msg string, can be printf formated
* @param array<mixed> $vars optional data for a possible printf formated msg
@@ -514,6 +522,7 @@ class Backend
/**
* writes live queue
*
* @param string $queue_key string to identfy the queue
* @param string $type [description]
* @param string $target [description]
@@ -559,17 +568,22 @@ class Backend
/**
* Basic class holds exact the same, except the Year/Month/Day/etc strings
* are translated in this call
*
* @param int $year year YYYY
* @param int $month month m
* @param int $day day d
* @param int $hour hour H
* @param int $min min i
* @param string $suffix additional info printed after the date time variable in the drop down
* @param string $suffix additional info printed after the date time
* variable in the drop down
* also used for ID in the on change JS call
* @param int $min_steps default is 1 (minute), can set to anything, is used as sum up from 0
* @param bool $name_pos_back default false, if set to true, the name will be printend
* @param int $min_steps default is 1 (minute), can set to anything,
* is used as sum up from 0
* @param bool $name_pos_back default false, if set to true,
* the name will be printend
* after the drop down and not before the drop down
* @return string HTML formated strings for drop down lists of date and time
* @return string HTML formated strings for drop down lists
* of date and time
*/
public function adbPrintDateTime(
$year,

View File

@@ -165,6 +165,7 @@ class Email
/**
* guesses the email type (mostly for mobile) from the domain
* if second is set to true, it will return short naming scheme (only provider)
*
* @param string $email email string
* @param bool $short default false, if true,
* returns only short type (pc instead of pc_html)
@@ -197,6 +198,7 @@ class Email
/**
* gets the short email type from a long email type
*
* @param string $email_type email string
* @return string|bool short string or false for invalid
*/
@@ -227,7 +229,7 @@ class Email
}
/**
* Undocumented function
* check email with all regex checks possible and return errors as array
*
* @param string $email Email address, will be checkd as lower
* @param bool $error_code_only If this is set to true it will only return

View File

@@ -12,6 +12,7 @@ class File
{
/**
* quick return the extension of the given file name
*
* @param string $filename file name
* @return string extension of the file name
*/
@@ -23,6 +24,7 @@ class File
/**
* get lines in a file
*
* @param string $file file for line count read
* @return int number of lines or -1 for non readable file
*/

View File

@@ -12,7 +12,6 @@ use CoreLibs\Convert\Json;
class Jason
{
/**
* @param string|null $json a json string, or null data
* @param bool $override if set to true, then on json error

View File

@@ -12,6 +12,7 @@ class Password
{
/**
* creates the password hash
*
* @param string $password password
* @return string hashed password
*/
@@ -25,6 +26,7 @@ class Password
/**
* checks if the entered password matches the hash
*
* @param string $password password
* @param string $hash password hash
* @return bool true or false
@@ -40,6 +42,7 @@ class Password
/**
* checks if the password needs to be rehashed
*
* @param string $hash password hash
* @return bool true or false
*/

View File

@@ -10,6 +10,7 @@ class PhpVersion
* checks if running PHP version matches given PHP version (min or max)
* if either is empty or null it will be ignored
* if no min version (null or empty)
*
* @param string|null $min_version minimum version as string (x, x.y, x.y.x)
* @param string|null $max_version optional maximum version as string (x, x.y, x.y.x)
* @return bool true if ok, false if not matching version

View File

@@ -13,6 +13,7 @@ class ArrayHandler
/**
* searches key = value in an array / array
* only returns the first one found
*
* @param string|int $needle needle (search for)
* @param array<mixed> $haystack haystack (search in)
* @param string|null $key_search_for the key to look out for, default empty
@@ -68,10 +69,12 @@ class ArrayHandler
/**
* recursive array search function, which returns all found not only the first one
*
* @param string|int $needle needle (search for)
* @param array<mixed> $haystack haystack (search in)
* @param string|int $key_search_for the key to look for in
* @param bool $old [true], if set to false will return new flat layout
* @param bool $old [true], if set to false will
* return new flat layout
* @param array<mixed>|null $path recursive call for previous path
* @return array<mixed>|null all array elements paths where
* the element was found
@@ -148,6 +151,7 @@ class ArrayHandler
/**
* array search simple. looks for key, value combination, if found, returns true
* on default does not strict check, so string '4' will match int 4 and vica versa
*
* @param array<mixed> $array search in as array
* @param string|int $key key (key to search in)
* @param string|int $value value (what to find)
@@ -184,6 +188,7 @@ class ArrayHandler
* ... etc
* bool key flag: true: handle keys as string or int
* default false: all keys are string
*
* @return array<mixed>|bool merged array
*/
public static function arrayMergeRecursive()
@@ -240,6 +245,7 @@ class ArrayHandler
* array_diff only checks elements from A that are not in B, but not the
* other way around.
* Note that like array_diff this only checks first level values not keys
*
* @param array<mixed> $a array to compare a
* @param array<mixed> $b array to compare b
* @return array<mixed> array with missing elements from a & b
@@ -254,9 +260,12 @@ class ArrayHandler
* search for the needle array elements in haystack and
* return the ones found as an array,
* is there nothing found, it returns FALSE (boolean)
*
* @param array<mixed> $needle elements to search for
* @param array<mixed> $haystack array where the $needle elements should be searched int
* @return array<mixed>|bool either the found elements or false for nothing found or error
* @param array<mixed> $haystack array where the $needle elements should
* be searched int
* @return array<mixed>|bool either the found elements or
* false for nothing found or error
*/
public static function inArrayAny(array $needle, array $haystack)
{
@@ -275,6 +284,7 @@ class ArrayHandler
/**
* creates out of a normal db_return array an assoc array
*
* @param array<mixed> $db_array return array from the database
* @param string|int|bool $key key set, false for not set
* @param string|int|bool $value value set, false for not set
@@ -313,6 +323,7 @@ class ArrayHandler
/**
* converts multi dimensional array to a flat array
* does NOT preserve keys
*
* @param array<mixed> $array multi dimensionial array
* @return array<mixed> flattened array
*/
@@ -330,6 +341,7 @@ class ArrayHandler
/**
* will loop through an array recursivly and write the array keys back
*
* @param array<mixed> $array multidemnsional array to flatten
* @param array<mixed> $return recoursive pass on array of keys
* @return array<mixed> flattened keys array
@@ -348,6 +360,7 @@ class ArrayHandler
/**
* as above will flatten an array, but in this case only the outmost
* leave nodes, all other keyswill be skipped
*
* @param array<mixed> $array multidemnsional array to flatten
* @return array<mixed> flattened keys array
*/
@@ -366,6 +379,7 @@ class ArrayHandler
/**
* searches for key -> value in an array tree and writes the value one level up
* this will remove this leaf will all other values
*
* @param array<mixed> $array nested array
* @param string|int $search key to find that has no sub leaf
* and will be pushed up

View File

@@ -66,9 +66,11 @@ class DateTime
/**
* a simple wrapper for the date format
* if an invalid timestamp is give zero timestamp unix time is used
*
* @param int|float $timestamp unix timestamp
* @param bool $show_micro show the micro time (default false)
* @param bool $micro_as_float Add the micro time with . instead of ms (default false)
* @param bool $micro_as_float Add the micro time with . instead
* of ms (default false)
* @return string formated date+time in Y-M-D h:m:s ms
*/
public static function dateStringFormat(
@@ -92,7 +94,9 @@ class DateTime
/**
* formats a timestamp into interval, not into a date
* @param string|int|float $timestamp interval in seconds and optional float micro seconds
*
* @param string|int|float $timestamp interval in seconds and optional
* float micro seconds
* @param bool $show_micro show micro seconds, default true
* @return string interval formatted string or string as is
*/
@@ -149,6 +153,7 @@ class DateTime
/**
* does a reverse of the timeStringFormat and converts the string from
* xd xh xm xs xms to a timestamp.microtime format
*
* @param string|int|float $timestring formatted interval
* @return string|int|float converted float interval, or string as is
*/
@@ -190,6 +195,7 @@ class DateTime
/**
* splits & checks date, wrap around for check_date function
*
* @param string $date a date string in the format YYYY-MM-DD
* @return bool true if valid date, false if date not valid
*/
@@ -214,6 +220,7 @@ class DateTime
/**
* splits & checks date, wrap around for check_date function
*
* @param string $datetime date (YYYY-MM-DD) + time (HH:MM:SS), SS can be dropped
* @return bool true if valid date, false if date not valid
*/
@@ -263,6 +270,7 @@ class DateTime
* 0 if both are equal
* 1 if the first date is bigger than the last
* false (bool): error
*
* @param string $start_date start date string in YYYY-MM-DD
* @param string $end_date end date string in YYYY-MM-DD
* @return int|bool false on error, or int -1/0/1 as difference
@@ -297,12 +305,14 @@ class DateTime
}
/**
* compares the two dates + times. if seconds missing in one set, add :00, converts / to -
* compares the two dates + times. if seconds missing in one set,
* add :00, converts / to -
* returns int/bool in:
* -1 if the first date is smaller the last
* 0 if both are equal
* 1 if the first date is bigger than the last
* false if no valid date/times chould be found
*
* @param string $start_datetime start date/time in YYYY-MM-DD HH:mm:ss
* @param string $end_datetime end date/time in YYYY-MM-DD HH:mm:ss
* @return int|bool false for error or -1/0/1 as difference
@@ -336,6 +346,7 @@ class DateTime
* calculates the days between two dates
* return: overall days, week days, weekend days as array 0...2 or named
* as overall, weekday and weekend
*
* @param string $start_date valid start date (y/m/d)
* @param string $end_date valid end date (y/m/d)
* @param bool $return_named return array type, false (default), true for named

View File

@@ -30,6 +30,7 @@ class Byte
* BYTE_FORMAT_ADJUST [2] use sprintf to always print two decimals
* BYTE_FORMAT_SI [3] use si standard 1000 instead of bytes 1024
* To use the constant from outside use class::CONSTANT
*
* @param string|int|float $bytes bytes as string int or pure int
* @param int $flags bitwise flag with use space turned on
* @return string converted byte number (float) with suffix
@@ -106,6 +107,7 @@ class Byte
* NOTE: large exabyte numbers will overflow
* flag allowed:
* BYTE_FORMAT_SI [3] use si standard 1000 instead of bytes 1024
*
* @param string|int|float $number any string or number to convert
* @param int $flags bitwise flag with use space turned on
* @return string|int|float converted value or original value

View File

@@ -23,6 +23,7 @@ class Colors
* converts the rgb values from int data to the valid rgb html hex string
* optional can turn of leading #
* if one value is invalid, will return false
*
* @param int $red red 0-255
* @param int $green green 0-255
* @param int $blue blue 0-255
@@ -49,6 +50,7 @@ class Colors
/**
* converts a hex RGB color to the int numbers
*
* @param string $hexStr RGB hexstring
* @param bool $return_as_string flag to return as string
* @param string $seperator string seperator: default: ","
@@ -90,6 +92,7 @@ class Colors
* converts RGB to HSB/V values
* returns:
* array with hue (0-360), sat (0-100%), brightness/value (0-100%)
*
* @param int $red red 0-255
* @param int $green green 0-255
* @param int $blue blue 0-255
@@ -136,6 +139,7 @@ class Colors
* hsb2rgb does not clean convert back to hsb in a round trip
* converts HSB/V to RGB values RGB is full INT
* if HSB/V value is invalid, sets this value to 0
*
* @param float $H hue 0-360 (int)
* @param float $S saturation 0-100 (int)
* @param float $V brightness/value 0-100 (int)
@@ -218,6 +222,7 @@ class Colors
* converts a RGB (0-255) to HSL
* return:
* array with hue (0-360), saturation (0-100%) and luminance (0-100%)
*
* @param int $red red 0-255
* @param int $green green 0-255
* @param int $blue blue 0-255
@@ -271,6 +276,7 @@ class Colors
/**
* converts an HSL to RGB
* if HSL value is invalid, set this value to 0
*
* @param float $hue hue: 0-360 (degrees)
* @param float $sat saturation: 0-100
* @param float $lum luminance: 0-100

View File

@@ -15,6 +15,7 @@ class Html
/**
* full wrapper for html entities
*
* @param mixed $string string to html encode
* @return mixed if string, encoded, else as is (eg null)
*/
@@ -42,10 +43,14 @@ class Html
* returns 'checked' or 'selected' if okay
* $needle is a var, $haystack an array or a string
* **** THE RETURN: VALUE WILL CHANGE TO A DEFAULT NULL IF NOT FOUND ****
* @param array<mixed>|string $haystack (search in) haystack can be an array or a string
*
* @param array<mixed>|string $haystack (search in) haystack can be
* an array or a string
* @param string $needle needle (search for)
* @param int $type type: 0: returns selected, 1, returns checked
* @return ?string returns checked or selected, else returns null
* @param int $type type: 0: returns selected, 1,
* returns checked
* @return ?string returns checked or selected,
* else returns null
*/
public static function checked($haystack, string $needle, int $type = 0): ?string
{

View File

@@ -21,6 +21,7 @@ class Json
* or failed convert to array
* In ANY case it will ALWAYS return array.
* Does not throw errors
*
* @param string|null $json a json string, or null data
* @param bool $override if set to true, then on json error
* set original value as array
@@ -49,6 +50,7 @@ class Json
/**
* returns human readable string for json errors thrown in jsonConvertToArray
*
* @param bool|boolean $return_string [default=false] if set to true
* it will return the message string and not
* the error number

View File

@@ -13,6 +13,7 @@ class Math
/**
* some float numbers will be rounded up even if they have no decimal entries
* this function fixes this by pre-rounding before calling ceil
*
* @param float $number number to round
* @param int|integer $precision intermediat round up decimals (default 10)
* @return float correct ceil number
@@ -25,6 +26,7 @@ class Math
/**
* round inside an a number, not the decimal part only
* eg 48767 with -2 -> 48700
*
* @param float $number number to round
* @param int $precision negative number for position in number (default -2)
* @return float rounded number
@@ -42,6 +44,7 @@ class Math
/**
* inits input to 0, if value is not numeric
*
* @param string|int|float $number string or number to check
* @return float if not number, then returns 0, else original input
*/

View File

@@ -55,6 +55,7 @@ class MimeAppName
/**
* Sets or updates a mime type
*
* @param string $mime MIME Name, no validiation
* @param string $app Applicaiton name
* @return void
@@ -71,6 +72,7 @@ class MimeAppName
/**
* get the application name from mime type
* if not set returns "Other file"
*
* @param string $mime MIME Name
* @return string Application name matching
*/

View File

@@ -19,6 +19,7 @@ class Hash
* hash returns false
* preg_replace fails for older php version
* Use __hash with crc32b or hash('crc32b', ...) for correct output
*
* @param string $string string to crc
* @return string crc32b hash (old type)
*/
@@ -39,6 +40,7 @@ class Hash
/**
* replacement for __crc32b call
*
* @param string $string string to hash
* @param bool $use_sha use sha instead of crc32b (default false)
* @return string hash of the string
@@ -58,6 +60,7 @@ class Hash
* defaults to adler 32
* allowed crc32b, adler32, fnv132, fnv1a32, joaat
* all that create 8 char long hashes
*
* @param string $string string to hash
* @param string $hash_type hash type (default adler32)
* @return string hash of the string
@@ -79,6 +82,7 @@ class Hash
/**
* Wrapper function for standard long hashd
*
* @param string $string String to be hashed
* @return string Hashed string
*/

View File

@@ -29,6 +29,7 @@ class RandomKey
}
/**
* sets the random key range with the default values
*
* @return void has no return
*/
private static function initRandomKeyData()
@@ -44,6 +45,7 @@ class RandomKey
/**
* validates they key length for random string generation
*
* @param int $key_length key length
* @return bool true for valid, false for invalid length
*/
@@ -63,6 +65,7 @@ class RandomKey
/**
* sets the key length and checks that they key given is valid
* if failed it will not change the default key length and return false
*
* @param int $key_length key length
* @return bool true/false for set status
*/
@@ -91,6 +94,7 @@ class RandomKey
* creates a random key based on the key_range with key_length
* if override key length is set, it will check on valid key and use this
* this will not set the class key length variable
*
* @param int $key_length key length override, -1 for use default
* @return string random key
*/

View File

@@ -15,8 +15,21 @@ namespace CoreLibs\Create;
class Session
{
/** @var string list for errors*/
private $error_str = '';
/** @var string list for errors */
private $session_intern_error_str = '';
/**
* Start session
* startSession should be called for complete check
* If this is called without any name set before the php.ini name is
* used.
*
* @return void
*/
protected function startSessionCall(): void
{
session_start();
}
/**
* init a session, if array is empty or array does not have session_name set
@@ -32,23 +45,41 @@ class Session
}
/**
* check if we are in CLI, we set this, so we can mock this too
* check if we are in CLI, we set this, so we can mock this
* Not this is just a wrapper for the static System::checkCLI call
*
* @return bool
* @return bool True if we are in a CLI enviroment, or false for everything else
*/
private function checkCLI(): bool
public function checkCliStatus(): bool
{
return \CoreLibs\Get\System::checkCLI();
}
/**
* Set session name call. If not valid session name, will return false
*
* @param string $session_name A valid string for session name
* @return bool True if session name is valid,
* False if not
*/
public function setSessionName(string $session_name): bool
{
if (!$this->checkValidSessionName($session_name)) {
return false;
}
session_name($session_name);
return true;
}
/**
* Return set error string, empty if none set
* Error strings are only set in the startSession method
*
* @return string Last error string
*/
public function getErrorStr(): string
{
return $this->error_str;
return $this->session_intern_error_str;
}
/**
@@ -88,13 +119,13 @@ class Session
public function startSession(?string $session_name = null)
{
// we can't start sessions on command line
if ($this->checkCLI()) {
$this->error_str = '[SESSION] No sessions in php cli';
if ($this->checkCliStatus()) {
$this->session_intern_error_str = '[SESSION] No sessions in php cli';
return false;
}
// if session are OFF
if ($this->getSessionStatus() === PHP_SESSION_DISABLED) {
$this->error_str = '[SESSION] Sessions are disabled';
$this->session_intern_error_str = '[SESSION] Sessions are disabled';
return false;
}
// session_status
@@ -108,20 +139,23 @@ class Session
if (!empty($session_name)) {
// invalid session name, abort
if (!$this->checkValidSessionName($session_name)) {
$this->error_str = '[SESSION] Invalid session name: ' . $session_name;
$this->session_intern_error_str = '[SESSION] Invalid session name: ' . $session_name;
return false;
}
session_name($session_name);
$this->setSessionName($session_name);
}
// start session
session_start();
$this->startSessionCall();
}
// if we still have no active session
if (!$this->checkActiveSession()) {
$this->error_str = '[SESSION] Failed to activate session';
$this->session_intern_error_str = '[SESSION] Failed to activate session';
return false;
}
return $this->getSessionId();
if (false === ($session_id = $this->getSessionId())) {
$this->session_intern_error_str = '[SESSION] getSessionId did not return a session id';
}
return $session_id;
}
/**
@@ -172,6 +206,39 @@ class Session
return session_write_close();
}
/**
* Proper destroy a session
* - unset the _SESSION array
* - unset cookie if cookie on and we have not strict mode
* - destroy session
*
* @return bool
*/
public function sessionDestroy(): bool
{
$_SESSION = [];
if (
ini_get('session.use_cookies') &&
!ini_get('session.use_strict_mode')
) {
$session_name = $this->getSessionName();
if ($session_name === false) {
$session_name = '';
}
$params = session_get_cookie_params();
setcookie(
(string)$session_name,
'',
time() - 42000,
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
}
return session_destroy();
}
/**
* get session status
* PHP_SESSION_DISABLED if sessions are disabled.
@@ -180,12 +247,125 @@ class Session
*
* https://www.php.net/manual/en/function.session-status.php
*
* @return int
* @return int See possible return int values above
*/
public function getSessionStatus(): int
{
return session_status();
}
// _SESSION set/unset methods
/**
* unset all _SESSION entries
*
* @return void
*/
public function unsetAllS(): void
{
foreach (array_keys($_SESSION ?? []) as $name) {
unset($_SESSION[$name]);
}
}
/**
* set _SESSION entry 'name' with any value
*
* @param string|int $name array name in _SESSION
* @param mixed $value value to set (can be anything)
* @return void
*/
public function setS($name, $value): void
{
$_SESSION[$name] = $value;
}
/**
* get _SESSION 'name' entry or empty string if not set
*
* @param string|int $name value key to get from _SESSION
* @return mixed value stored in _SESSION
*/
public function getS($name)
{
return $_SESSION[$name] ?? '';
}
/**
* Check if a name is set in the _SESSION array
*
* @param string|int $name Name to check for
* @return bool True for set, False fornot set
*/
public function issetS($name): bool
{
return isset($_SESSION[$name]);
}
/**
* unset one _SESSION entry 'name' if exists
*
* @param string|int $name _SESSION key name to remove
* @return void
*/
public function unsetS($name): void
{
if (isset($_SESSION[$name])) {
unset($_SESSION[$name]);
}
}
// set/get below
// ->var = value;
/**
* Undocumented function
*
* @param string|int $name
* @param mixed $value
* @return void
*/
public function __set($name, $value): void
{
$_SESSION[$name] = $value;
}
/**
* Undocumented function
*
* @param string|int $name
* @return mixed
*/
public function __get($name)
{
if (isset($_SESSION[$name])) {
return $_SESSION[$name];
}
}
/**
* Undocumented function
*
* @param string|int $name
* @return bool
*/
public function __isset($name): bool
{
return isset($_SESSION[$name]);
}
/**
* Undocumented function
*
* @param string|int $name
* @return void
*/
public function __unset($name): void
{
if (isset($_SESSION[$name])) {
unset($_SESSION[$name]);
}
}
}
// __END__

View File

@@ -15,6 +15,7 @@ class Uids
* creates psuedo random uuid v4
* Code take from class here:
* https://www.php.net/manual/en/function.uniqid.php#94959
*
* @return string pseudo random uuid v4
*/
public static function uuidv4(): string
@@ -44,6 +45,7 @@ class Uids
* TODO: make this a proper uniq ID creation
* add uuidv4 subcall to the uuid function too
* creates a uniq id
*
* @param string $type uniq id type, currently md5 or sha256 allowed
* if not set will use DEFAULT_HASH if set
* @return string uniq id
@@ -81,7 +83,7 @@ class Uids
return $uniq_id;
}
/**
/**
* create a unique id with the standard hash type defined in __hash
*
* @return string Unique ID with fixed length of 8 characters

View File

@@ -50,6 +50,7 @@ class ArrayIO extends \CoreLibs\DB\IO
/**
* constructor for the array io class, set the
* primary key name automatically (from array)
*
* @param array<mixed> $db_config db connection config
* @param array<mixed> $table_array table array config
* @param string $table_name table name string
@@ -93,6 +94,7 @@ class ArrayIO extends \CoreLibs\DB\IO
* works for <b>,<i>, and <a> (thought <a> can be / or should
* be handled with the magic links functions
* used with the read function
*
* @param string $text any html encoded string
* @return string decoded html string
*/
@@ -111,6 +113,7 @@ class ArrayIO extends \CoreLibs\DB\IO
/**
* changeds all HTML entities into non HTML ones
*
* @param string $text encoded html string
* @return string decoded html string
*/
@@ -126,6 +129,7 @@ class ArrayIO extends \CoreLibs\DB\IO
/**
* dumps the current data
*
* @param bool $write write to error message, default false
* @return string the array data as html string entry
*/
@@ -144,7 +148,9 @@ class ArrayIO extends \CoreLibs\DB\IO
}
/**
* checks if pk is set and if not, set from pk_id and if this also not set return 0
* checks if pk is set and if not, set from pk_id and
* if this also not set return 0
*
* @return bool true if pk value is set, else false
*/
public function dbCheckPkSet()
@@ -182,6 +188,7 @@ class ArrayIO extends \CoreLibs\DB\IO
/**
* deletes one dataset
*
* @param array<mixed> $table_array optional override for table array set
* set this as new table array too
* @return array<mixed> returns the table array that was deleted
@@ -241,8 +248,10 @@ class ArrayIO extends \CoreLibs\DB\IO
/**
* reads one row into the array
*
* @param boolean $edit on true convert data, else as is
* @param array<mixed> $table_array optional table array, overwrites internal set array
* @param array<mixed> $table_array optional table array, overwrites
* internal set array
* @return array<mixed> set table array with values
*/
public function dbRead($edit = false, $table_array = [])
@@ -315,6 +324,7 @@ class ArrayIO extends \CoreLibs\DB\IO
/**
* writes one set into DB or updates one set (if PK exists)
*
* @param boolean $addslashes old convert entities and set set escape
* @param array<mixed> $table_array optional table array, overwrites internal one
* @return array<mixed> table array or null

View File

@@ -263,15 +263,15 @@ use CoreLibs\Create\Uids;
class IO
{
// 0: normal read, store in cache
// 1: read cache, clean at the end
// 2: read new, clean at end
// 1: read new, keep at end, clean before new run
// 2: read new, clean at the end (temporary cache)
// 3: never cache
/** @var int */
public const USE_CACHE = 0;
/** @var int */
public const CLEAR_CACHE = 1;
public const READ_NEW = 1;
/** @var int */
public const READ_NEW = 2;
public const CLEAR_CACHE = 2;
/** @var int */
public const NO_CACHE = 3;
/** @var string */
@@ -1384,7 +1384,7 @@ class IO
// we only compare the first two
preg_match(
"/^(\d{1,})\.(\d{1,})\.?(\d{1,})?/",
$this->db_functions->__dbVersion(),
$this->dbVersion(),
$matches
);
$master = $matches[1];
@@ -1682,18 +1682,18 @@ class IO
* data, or with reset flag set calls data from DB again
* NOTE on $cache param:
* - if set to 0, if same query run again, will read from cache
* - if set to 1, at the end of the query (last row returned),
* the stored array will be deleted ...
* - if set to 2, the data will be read new and cached
* - if set to 1, the data will be read new and cached, cache reset a new run
* (wheres 1 reads cache AND destroys at end of read)
* - if set to 2, at the end of the query (last row returned),
* the stored array will be deleted ...
* - if set to 3, after EACH row, the data will be reset,
* no caching is done except for basic (count, etc)
* @param string $query Query string
* @param int $cache reset status: default: USE_CACHE
* USE_CACHE/0: normal read from cache on second run
* CLEAR_CACHE/1: read cache, clean at the end
* READ_NEW/2: read new, clean at end
* NO_CACHE/3: never cache [default]
* READ_NEW/1: write to cache, clean before new run
* CLEAR_CACHE/2: write cache, clean after finished
* NO_CACHE/3: don't write cache
* @param bool $assoc_only True to only returned the named and not
* index position ones
* @return array<mixed>|bool return array data or false on error/end
@@ -1714,17 +1714,44 @@ class IO
// pre declare array
if (!isset($this->cursor_ext[$query_hash])) {
$this->cursor_ext[$query_hash] = [
// cursor, null: unset, 1: finished read/cache, 2: object/resource reading
'cursor' => null,
// cached data
'data' => [],
// field names as array
'field_names' => [],
'firstcall' => 0,
// number of fields (field names)
'num_fields' => 0,
// number of rows that will be maximum returned
'num_rows' => 0,
'pos' => 0,
'query' => '',
// how many rows have been read from db
'read_rows' => 0,
// current read pos (db/cache), 0 on last read (finished)
'pos' => 0,
// the query used in this call
'query' => '',
// cache flag from method call
'cache_flag' => $cache,
// flag if we only have assoc data
'assoc_flag' => $assoc_only,
// flag if we have cache data stored at the moment
'cached' => false,
// when fetch array or cache read returns false
// in loop read that means dbReturn retuns false without erro
'finished' => false,
// read from cache/db (pos == rows)
'read_finished' => false,
// read from db only (read == rows)
'db_read_finished' => false,
// for debug
'log_pos' => 1, // how many times called overall
'log' => [], // current run log
];
} else {
$this->cursor_ext[$query_hash]['log_pos'] ++;
}
// reset log for each read
$this->cursor_ext[$query_hash]['log'] = [];
// set the query
$this->cursor_ext[$query_hash]['query'] = $query;
// before doing ANYTHING check if query is "SELECT ..." everything else does not work
@@ -1732,20 +1759,25 @@ class IO
$this->__dbError(17, false, $this->cursor_ext[$query_hash]['query']);
return false;
}
// set first call to false
$first_call = false;
// init return als false
$return = false;
// if it is a call with reset in it we reset the cursor,
// so we get an uncached return
// but only for the FIRST call (pos == 0)
if ($cache > self::USE_CACHE && !$this->cursor_ext[$query_hash]['pos']) {
$this->cursor_ext[$query_hash]['log'][] = 'Reset cursor';
$this->cursor_ext[$query_hash]['cursor'] = null;
if ($cache == self::READ_NEW) {
$this->cursor_ext[$query_hash]['log'][] = 'Cache reset';
$this->cursor_ext[$query_hash]['data'] = [];
}
}
// $this->debug('MENU', 'Reset: '.$reset.', Cursor: '
// .$this->cursor_ext[$query_hash]['cursor'].', Pos: '.$this->cursor_ext[$query_hash]['pos']
// .', Query: '.$query);
// if no cursor yet, execute
if (!$this->cursor_ext[$query_hash]['cursor']) {
$this->cursor_ext[$query_hash]['log'][] = 'No cursor';
// for DEBUG, print out each query executed
if ($this->db_debug) {
$this->__dbDebug('db', $this->cursor_ext[$query_hash]['query'], 'dbReturn', 'Q');
@@ -1773,13 +1805,14 @@ class IO
$this->__dbError(13, $this->cursor_ext[$query_hash]['cursor']);
return false;
} else {
$this->cursor_ext[$query_hash]['firstcall'] = 1;
$first_call = true;
}
} // only go if NO cursor exists
// if cursor exists ...
if ($this->cursor_ext[$query_hash]['cursor']) {
if ($this->cursor_ext[$query_hash]['firstcall'] == 1) {
if ($first_call === true) {
$this->cursor_ext[$query_hash]['log'][] = 'First call';
// count the rows returned (if select)
$this->cursor_ext[$query_hash]['num_rows'] =
$this->db_functions->__dbNumRows($this->cursor_ext[$query_hash]['cursor']);
@@ -1799,35 +1832,51 @@ class IO
);
}
$this->field_names = $this->cursor_ext[$query_hash]['field_names'];
// reset first call vars
$this->cursor_ext[$query_hash]['firstcall'] = 0;
// reset first call var
$first_call = false;
// reset the internal pos counter
$this->cursor_ext[$query_hash]['pos'] = 0;
// reset the global (for cache) read counter
$this->cursor_ext[$query_hash]['read_rows'] = 0;
// reset read finished flag
$this->cursor_ext[$query_hash]['finished'] = false;
$this->cursor_ext[$query_hash]['read_finished'] = false;
$this->cursor_ext[$query_hash]['db_read_finished'] = false;
// set cursor ccached flag based on cache flag
if ($cache < self::NO_CACHE) {
$this->cursor_ext[$query_hash]['cached'] = true;
}
}
// read data for further work ... but only if necessarry
// main database read if not all read and we have an active cursor
if (
$this->cursor_ext[$query_hash]['read_rows'] ==
$this->cursor_ext[$query_hash]['num_rows']
$this->cursor_ext[$query_hash]['read_rows'] !=
$this->cursor_ext[$query_hash]['num_rows'] &&
!is_int($this->cursor_ext[$query_hash]['cursor'])
) {
$return = false;
} else {
$return = $this->__dbConvertEncoding(
$this->db_functions->__dbFetchArray(
$this->cursor_ext[$query_hash]['cursor'],
$this->db_functions->__dbResultType($assoc_only)
)
);
$this->cursor_ext[$query_hash]['log'][] = 'DB Reading data: '
. (is_bool($return) ? 'EOF' : 'DATA');
// if returned is NOT an array, abort to false
if (!is_array($return)) {
$return = false;
}
}
// check if cached call or reset call ...
// read from cache, or do partial cache set and caching
if (!$return && $cache == self::USE_CACHE) {
// check if end of output ...
if ($this->cursor_ext[$query_hash]['pos'] >= $this->cursor_ext[$query_hash]['num_rows']) {
if (
$this->cursor_ext[$query_hash]['pos'] >=
$this->cursor_ext[$query_hash]['num_rows']
) {
$this->cursor_ext[$query_hash]['log'][] = 'USE CACHE, end';
// finish read
$this->cursor_ext[$query_hash]['finished'] = true;
// reset pos for next read
$this->cursor_ext[$query_hash]['pos'] = 0;
// if not reset given, set the cursor to true, so in a cached
// call on a different page we don't get problems from
@@ -1835,36 +1884,55 @@ class IO
$this->cursor_ext[$query_hash]['cursor'] = 1;
$return = false;
} else {
$this->cursor_ext[$query_hash]['log'][] = 'USE CACHE, read data';
$this->cursor_ext[$query_hash]['read_finished'] = false;
$this->cursor_ext[$query_hash]['finished'] = false;
// cached data read
$return = $this->__dbReturnCacheRead($query_hash, $assoc_only);
if (
$this->cursor_ext[$query_hash]['pos'] ==
$this->cursor_ext[$query_hash]['num_rows']
) {
$this->cursor_ext[$query_hash]['log'][] = 'USE CACHE, all cache rows read';
$this->cursor_ext[$query_hash]['read_finished'] = true;
}
}
} else {
// return row, if last && reset, then unset the hole hash array
if (
!$return &&
($cache == self::CLEAR_CACHE || $cache == self::NO_CACHE) &&
$this->cursor_ext[$query_hash]['pos']
) {
// unset data block only
$this->cursor_ext[$query_hash]['data'] = [];
$this->cursor_ext[$query_hash]['pos'] = 0;
} elseif (
!$return && $cache == self::READ_NEW &&
$this->cursor_ext[$query_hash]['pos']
) {
// at end of read reset pos & set cursor to 1
// (so it does not get lost in session transfer)
// return row, if last && reset, then unset the whole hash array
if (!$return && $this->cursor_ext[$query_hash]['pos']) {
$this->cursor_ext[$query_hash]['pos'] = 0;
$this->cursor_ext[$query_hash]['cursor'] = 1;
$return = false;
$this->cursor_ext[$query_hash]['finished'] = true;
// for clear cache, clear cache, else only write log info
if ($cache == self::CLEAR_CACHE) {
$this->cursor_ext[$query_hash]['log'][] = 'CLEAR CACHE, end';
// unset data block only
$this->cursor_ext[$query_hash]['data'] = [];
$this->cursor_ext[$query_hash]['cached'] = false;
} elseif ($cache == self::READ_NEW) {
$this->cursor_ext[$query_hash]['log'][] = 'READ NEW, end';
} elseif ($cache == self::NO_CACHE) {
$this->cursor_ext[$query_hash]['log'][] = 'NO CACHE, end';
}
}
// if something found, write data into hash array
if ($return) {
$this->cursor_ext[$query_hash]['log'][] = 'Return Data';
// internal position counter
$this->cursor_ext[$query_hash]['pos'] ++;
$this->cursor_ext[$query_hash]['read_rows'] ++;
// read is finished
if (
$this->cursor_ext[$query_hash]['read_rows'] ==
$this->cursor_ext[$query_hash]['num_rows']
) {
$this->cursor_ext[$query_hash]['log'][] = 'Return data all db rows read';
$this->cursor_ext[$query_hash]['db_read_finished'] = true;
$this->cursor_ext[$query_hash]['read_finished'] = true;
}
// if reset is < NO_CACHE level caching is done, else no
if ($cache < self::NO_CACHE) {
$this->cursor_ext[$query_hash]['log'][] = 'Cache Data';
// why was this here?
// $temp = [];
// foreach ($return as $field_name => $data) {

View File

@@ -59,15 +59,9 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/** @var object|resource|bool */ // replace object with PgSql\Connection
private $dbh;
/**
* class constructor, empty does nothing
*/
// public function __construct()
// {
// }
/**
* queries last error query and returns true or false if error was set
*
* @return bool true/false if last error is set
*/
public function __dbLastErrorQuery(): bool
@@ -81,6 +75,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_query, catches error and stores it in class var
*
* @param string $query Query string
* @return object|resource|bool query result (PgSql\Result)
*/
@@ -102,6 +97,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
* Proposed
* wrapperf or pg_query_params for queries in the style of
* SELECT foo FROM bar WHERE foobar = $1
*
* @param string $query Query string with placeholders $1, ..
* @param array<mixed> $params Matching parameters for each placerhold
* @return object|resource|bool Query result (PgSql\Result)
@@ -124,6 +120,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* sends an async query to the server
*
* @param string $query query string
* @return bool true/false if query was sent successful
*/
@@ -138,6 +135,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_get_result
*
* @return object|resource|bool resource handler or false for error (PgSql\Result)
*/
public function __dbGetResult()
@@ -158,6 +156,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_close
*
* @return void has no return
*/
public function __dbClose(): void
@@ -173,9 +172,11 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_prepare
*
* @param string $name statement name
* @param string $query query string
* @return object|resource|bool prepare statement handler or false for error (PgSql\Result)
* @return object|resource|bool prepare statement handler or
* false for error (PgSql\Result)
*/
public function __dbPrepare(string $name, string $query)
{
@@ -191,6 +192,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_execute for running a prepared statement
*
* @param string $name statement name
* @param array<mixed> $data data array
* @return object|resource|bool returns status or false for error (PgSql\Result)
@@ -209,6 +211,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_num_rows
*
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
* @return int number of rows, -1 on error
*/
@@ -222,6 +225,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_num_fields
*
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
* @return int number for fields in result, -1 on error
*/
@@ -235,6 +239,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_field_name
*
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
* @param int $i field position
* @return string|bool name or false on error
@@ -250,6 +255,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_fetch_array
* if through/true false, use __dbResultType(true)
*
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
* @param int $result_type result type as int number
* @return array<mixed>|bool array result data or false on end/error
@@ -265,6 +271,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* simple match up between assoc true/false
*
* @param bool $assoc_type true (default) for PGSQL_ASSOC, false for PGSQL_BOTH
* @return int valid result type for fetch array
*/
@@ -279,6 +286,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_fetch_all
*
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
* @return array<mixed>|bool data array or false for end/error
*/
@@ -292,6 +300,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_affected_rows
*
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
* @return int affected rows, 0 for none, -1 for error
*/
@@ -306,7 +315,9 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* reads the last inserted primary key for the query
* if there is no pk_name tries to auto built it from the table name
* this only works if db schema is after "no plural names. and pk name is table name + _id
* this only works if db schema is after no plural names
* and pk name is table name + _id
*
* detects schema prefix in table name
* @param string $query query string
* @param string|null $pk_name primary key name, if '' then auto detect
@@ -355,6 +366,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* queries database for the primary key name to this table in the selected schema
*
* @param string $table table name
* @param string $schema optional schema name, '' for default
* @return string|bool primary key name or false if not found
@@ -407,6 +419,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
*
* @param string $db_host host name
* @param string $db_user user name
* @param string $db_pass password
@@ -456,6 +469,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* reads the last error for this cursor and returns
* html formatted string with error name
*
* @param bool|object|resource $cursor cursor PgSql\Result (former resource)
* or null
* @return string error string
@@ -481,6 +495,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_meta_data
*
* @param string $table table name
* @param bool $extended show extended info (default true)
* @return array<mixed>|bool array data for the table info or false on error
@@ -496,6 +511,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_escape_string
*
* @param string|int|float|bool $string any string/int/float/bool
* @return string excaped string
*/
@@ -511,6 +527,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
* wrapper for pg_escape_literal
* difference to escape string is that this one adds quotes ('') around
* the string too
*
* @param string|int|float|bool $string any string/int/float/bool
* @return string excaped string including quites
*/
@@ -526,6 +543,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_escape_identifier
* Only used for table names, column names
*
* @param string $string any string
* @return string escaped string
*/
@@ -540,6 +558,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_escape_byte
*
* @param string $bytea bytea data stream
* @return string escaped bytea string
*/
@@ -553,6 +572,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for pg_connection_busy
*
* @return bool True if connection is busy, False if not or no db connection at all
*/
public function __dbConnectionBusy(): bool
@@ -565,6 +585,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* Experimental wrapper with scoket timetout
*
* @param integer $timeout_seconds Wait how many seconds on timeout
* @return boolean True if connection is busy, or false on
* not busy or no db connection at all
@@ -593,6 +614,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
* if not in array return empty string
* On default 'version' will be stripped of any space attached info
* eg 13.5 (other info) will return only 13.5
*
* @param string $parameter Parameter string to extract from array
* @param boolean $strip If parameter is server strip out on default
* Set to false to get original string AS is
@@ -617,6 +639,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* Returns all parameters that are possible from the db_version
*
* @return array<mixed> Parameter key names from pg_version
*/
public function __dbVersionInfoParameterList(): array
@@ -631,6 +654,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
* wrapper for pg_version
* Note: this only returns server version
* not connection version OR client version
*
* @return string version string
*/
public function __dbVersion(): string
@@ -649,6 +673,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
* Old version is 9.5.6 where 9.5 is the major version
* Newer Postgresql (10 on) have only one major version so eg 13.5
* is returned as 130005
*
* @return integer Server version
*/
public function __dbVersionNumeric(): int
@@ -662,6 +687,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
* This is a fallback for old PostgreSQL versions
* postgresql array to php array
* https://stackoverflow.com/a/27964420
*
* @param string $array_text Array text from PostgreSQL
* @param int $start Start string position
* @param int|null $end End string position from recursive call
@@ -721,6 +747,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
* Returns any server setting
* if no connection or empty parameter or other error returns false
* else returns a string
*
* @param string $parameter Parameter to query
* @return string|bool Settings value as string
*/
@@ -738,6 +765,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* wrapper for any SHOW data blocks
* eg search_path or client_encoding
*
* @param string $show_string Part to show, if invalid will return empty string
* @return string Found part as is
*/
@@ -758,6 +786,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* Sets a new database schema/search_path
* Checks if schema exits and if not aborts with error code 2
*
* @param string $db_schema Schema to set
* @return int Returns 0 if no error
* 1 for check query failed
@@ -788,6 +817,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* Returns current set schema/search_path
*
* @return string Search Path as currently set in DB
*/
public function __dbGetSchema(): string
@@ -798,6 +828,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/**
* set the client encoding
* Returns 0 on set ok, or 3 if the client encoding could not be set
*
* @param string $db_encoding
* @return int Returns 0 for no error
* [not used] 1 for check query failed

View File

@@ -16,7 +16,7 @@ class FileWriter
/** @var string */
private static $debug_folder;
/**
/**
* Set a debug log folder, if not set BASE+LOG folders are set
* if they are defined
* This folder name must exist and must be writeable
@@ -60,6 +60,7 @@ class FileWriter
/**
* writes a string to a file immediatly, for fast debug output
*
* @param string $string string to write to the file
* @param boolean $enter default true, if set adds a linebreak \n at the end
* @return bool True for log written, false for not wirrten

View File

@@ -310,6 +310,7 @@ class Logging
* Needs debug/echo/print ad target for which of the debug flag groups we check
* also needs level string to check in the per level output flag check.
* In case we have invalid target it will return false
*
* @param string $target target group to check debug/echo/print
* @param string $level level to check in detailed level flag
* @return bool true on access allowed or false on no access
@@ -332,6 +333,7 @@ class Logging
/**
* writes error msg data to file for current level
*
* @param string $level the level to write
* @param string $error_string error string to write
* @return bool True if message written, FAlse if not
@@ -412,6 +414,7 @@ class Logging
/**
* Temporary method to read all class variables for testing purpose
*
* @param string $name what variable to return
* @return mixed can be anything, bool, string, int, array
*/
@@ -425,6 +428,7 @@ class Logging
* sets the internal log file prefix id
* string must be a alphanumeric string
* if non valid string is given it returns the previous set one only
*
* @param string $string log file id string value
* @return string returns the set log file id string
* @deprecated Use $log->setLogId()
@@ -438,6 +442,7 @@ class Logging
* sets the internal log file prefix id
* string must be a alphanumeric string
* if non valid string is given it returns the previous set one only
*
* @param string $string log file id string value
* @return string returns the set log file id string
*/
@@ -460,6 +465,7 @@ class Logging
/**
* old name for setLogLevel
*
* @param string $type debug, echo, print
* @param string $flag on/off
* array $array of levels to turn on/off debug
@@ -475,6 +481,7 @@ class Logging
/**
* set log level settings for All types
* if invalid type, skip
*
* @param string $type Type to get: debug, echo, print
* @param bool $set True or False
* @return bool Return false if type invalid
@@ -491,6 +498,7 @@ class Logging
/**
* get the current log level setting for All level blocks
*
* @param string $type Type to get: debug, echo, print
* @return bool False on failure, or the boolean flag from the all var
*/
@@ -506,6 +514,7 @@ class Logging
/**
* passes list of level names, to turn on debug
* eg $foo->debugFor('print', 'on', ['LOG', 'DEBUG', 'INFO']);
*
* @param string $type debug, echo, print
* @param string $flag on/off
* @param array<mixed> $debug_on Array of levels to turn on/off debug
@@ -541,6 +550,7 @@ class Logging
/**
* return the log level for the array type normal and not (disable)
*
* @param string $type debug, echo, print
* @param string $flag on/off
* @param string|null $level if not null then check if this array entry is set
@@ -572,6 +582,7 @@ class Logging
* - class: split by class
* - page: split per page called
* - run: for each run
*
* @param string $type Type to get: level, class, page, run
* @param bool $set True or False
* @return bool Return false if type invalid
@@ -587,6 +598,7 @@ class Logging
/**
* return current set log per flag in bool
*
* @param string $type Type to get: level, class, page, run
* @return bool True of false for turned on or off
*/
@@ -601,6 +613,7 @@ class Logging
/**
* Set or get the log file date extension flag
* if null or empty parameter gets current flag
*
* @param boolean|null $set Set the date suffix for log files
* If set to null return current set
* @return boolean Current set flag
@@ -615,6 +628,7 @@ class Logging
/**
* Return current set log file name
*
* @return string Filename set set after the last time debug was called
*/
public function getLogFileName(): string
@@ -628,6 +642,7 @@ class Logging
* It uses some special code sets so we can convert that to pre flags
* for echo output {##HTMLPRE##} ... {##/HTMLPRE##}
* Do not use this without using it in a string in debug function
*
* @param array<mixed> $a Array to format
* @return string print_r formated
*/
@@ -636,14 +651,32 @@ class Logging
return '##HTMLPRE##' . print_r($a, true) . '##/HTMLPRE##';
}
/**
* Convert bool value to string value
*
* @param bool $bool Bool value to be transformed
* @param string $true Override default string 'true'
* @param string $false Override default string 'false'
* @return string $true or $false string for true/false bool
*/
public function prBl(
bool $bool,
string $true = 'true',
string $false = 'false'
): string {
return $bool ? $true : $false;
}
/**
* write debug data to error_msg array
*
* @param string $level id for error message, groups messages together
* @param string $string the actual error message
* @param bool $strip default on false, if set to true,
* all html tags will be stripped and <br> changed to \n
* this is only used for debug output
* @param string $prefix Attach some block before $string. Will not be stripped even
* @param string $prefix Attach some block before $string.
* Will not be stripped even
* when strip is true
* if strip is false, recommended to add that to $string
* @return bool True if logged, false if not logged
@@ -729,6 +762,7 @@ class Logging
/**
* for ECHO ON only
* returns error data as string so it can be echoed out
*
* @param string $header_prefix prefix string for header
* @return string error msg for all levels
*/
@@ -780,6 +814,7 @@ class Logging
* unsests the error message array
* can be used if writing is primary to file
* if no level given resets all
*
* @param string $level optional level
* @return void has no return
*/
@@ -795,6 +830,7 @@ class Logging
/**
* for ECHO ON only
* Get current error message array
*
* @return array<mixed> error messages collected
*/
public function getErrorMsg(): array
@@ -806,6 +842,7 @@ class Logging
* for ECHO ON only
* merges the given error array with the one from this class
* only merges visible ones
*
* @param array<mixed> $error_msg error array
* @return void has no return
*/

View File

@@ -0,0 +1,129 @@
<?php
/*
* dump memory usage
*/
declare(strict_types=1);
namespace CoreLibs\Debug;
use CoreLibs\Convert\Byte;
class MemoryUsage
{
/** @var int */
private static $start_memory = 0;
/** @var int */
private static $set_memory = 0;
/** @var int */
private static $previous_memory = 0;
/** @var bool */
private static $debug_memory = false;
/**
* set memory flag, or return set memory flag
*
* @param bool|null $set_debug
* @return bool
*/
public static function debugMemoryFlag(?bool $set_debug = null): bool
{
if ($set_debug === null) {
return self::$debug_memory;
}
self::$debug_memory = $set_debug;
return self::$debug_memory;
}
/**
* Reset all memory variables to 0
*
* @return void
*/
public static function resetMemory(): void
{
self::$start_memory = 0;
self::$set_memory = 0;
self::$previous_memory = 0;
}
/**
* set the start memory velue, or reset to a new start value
*
* @return void
*/
public static function setStartMemory(): void
{
self::$start_memory = memory_get_usage();
}
/**
* set the and independent memory set for a sub tracking outside main
*
* @return void
*/
public static function setMemory(): void
{
self::$set_memory = memory_get_usage();
}
/**
* calculate and set memory usage values
* this will return an array with all the data that can be used in
* printMemoryUsage for human readable output
*
* @param string $prefix A prefix tag
* @return array<string,int|string> return array
*/
public static function memoryUsage(string $prefix): array
{
// skip if DEBUG is off
if (self::$debug_memory === false) {
return [];
}
if (empty(self::$start_memory)) {
self::$start_memory = memory_get_usage();
}
$memory_usage = memory_get_usage();
$data = [
'prefix' => $prefix,
'peak' => memory_get_peak_usage(),
'usage' => $memory_usage,
'start' => $memory_usage - self::$start_memory,
'last' => $memory_usage - self::$previous_memory,
'set' => $memory_usage - self::$set_memory
];
self::$previous_memory = $memory_usage;
return $data;
}
/**
* returns a human readable output from the memoryUsage function
* can be used for logging purpose
*
* @param array<string,int|string> $data Data array from memoryUsage
* @param bool $raw Flag to shaw unconverted memory numbers
* @return string Return debug string with memory usage
*/
public static function printMemoryUsage(array $data, bool $raw = false): string
{
return
'[' . $data['prefix'] . '] Peak/Curr/Change: '
. Byte::humanReadableByteFormat($data['peak'])
. '/'
. Byte::humanReadableByteFormat($data['usage'])
// . ($raw === true ? ' [' . $data['usage'] . ']' : '')
. '/Since Start: '
. Byte::humanReadableByteFormat($data['start'])
. ($raw === true ? ' [' . $data['start'] . ']' : '')
. ' | Since Last: '
. Byte::humanReadableByteFormat($data['last'])
. ($raw === true ? ' [' . $data['last'] . ']' : '')
. ' | Since Set: '
. Byte::humanReadableByteFormat($data['set'])
. ($raw === true ? ' [' . $data['set'] . ']' : '');
}
}
// __END__

View File

@@ -12,43 +12,30 @@ class RunningTime
{
// hr
/** @var float */
private static $hr_starttime;
private static $hr_start_time;
/** @var float */
private static $hr_runtime;
private static $hr_end_time;
/** @var float */
private static $hr_endtime;
private static $hr_last_time;
// normal
/** @var float */
private static $starttime;
private static $start_time;
/** @var float */
private static $endtime;
private static $end_time;
/** @var string */
private static $runningtime_string;
private static $running_time_string;
/**
* for messure run time between two calls for this method
* uses the hrtime() for running time
* first call sets start time and returns 0,
* second call sets end time and returns the run time
* the out_time parameter can be:
* n/ns (nano), y/ys (micro), m/ms (milli), s (seconds)
* default is milliseconds
* @param string $out_time set return time adjustment calculation
* @return float running time without out_time suffix
* sub calculation for running time based on out time.
* If no running time set, return 0
*
* @param string $out_time
* @return float
*/
public static function hrRunningTime(string $out_time = 'ms'): float
{
// if start time not set, set start time
if (!self::$hr_starttime) {
self::$hr_starttime = hrtime(true);
self::$hr_runtime = 0;
} else {
self::$hr_endtime = hrtime(true);
self::$hr_runtime = self::$hr_endtime - self::$hr_starttime;
// reset start and end time past run
self::$hr_starttime = 0;
self::$hr_endtime = 0;
}
private static function hrRunningTimeCalc(
float $run_time,
string $out_time = 'ms'
): float {
// init divisor, just in case
$divisor = 1;
// check through valid out time, if nothing matches default to ms
@@ -74,8 +61,67 @@ class RunningTime
break;
}
// return the run time in converted format
self::$hr_runtime /= $divisor;
return self::$hr_runtime;
return $run_time /= $divisor;
}
/**
* for messure run time between two calls for this method
* uses the hrtime() for running time
* first call sets start time and returns 0,
* every other call sets end time and returns the run time since start
* the out_time parameter can be:
* n/ns (nano), y/ys (micro), m/ms (milli), s (seconds)
* default is milliseconds
*
* @param string $out_time set return time adjustment calculation
* @return float running time without out_time suffix
*/
public static function hrRunningTime(string $out_time = 'ms'): float
{
// if start time not set, set start time
if (!self::$hr_start_time) {
self::$hr_start_time = hrtime(true);
self::$hr_last_time = self::$hr_start_time;
$run_time = 0;
} else {
self::$hr_end_time = hrtime(true);
$run_time = self::$hr_end_time - self::$hr_last_time;
self::$hr_last_time = self::$hr_end_time;
}
return self::hrRunningTimeCalc($run_time, $out_time);
}
/**
* print overall end time , can only be called after hrRunningtime
* see $out_time parameter description in hrRunningtime.
* Does not record a new timestamp, only prints different between start and
* last recoreded timestamp
*
* @param string $out_time set return time adjustment calculation
* @return float overall running time without out_time suffix
*/
public static function hrRunningTimeFromStart(string $out_time = 'ms'): float
{
if (!self::$hr_start_time) {
return (float)0;
}
$time = self::hrRunningTimeCalc(
self::$hr_end_time - self::$hr_start_time,
$out_time
);
return $time;
}
/**
* reset hr running time internal variables (start, end, last)
*
* @return void
*/
public static function hrRunningTimeReset(): void
{
self::$hr_start_time = 0;
self::$hr_end_time = 0;
self::$hr_last_time = 0;
}
/**
@@ -91,24 +137,24 @@ class RunningTime
list($micro, $timestamp) = explode(' ', microtime());
$running_time = 0;
// set start & end time
if (!self::$starttime) {
if (!self::$start_time) {
// always reset running time string on first call
self::$runningtime_string = '';
self::$starttime = ((float)$micro + (float)$timestamp);
self::$runningtime_string .= $simple ? 'Start: ' : "<b>Started at</b>: ";
self::$running_time_string = '';
self::$start_time = ((float)$micro + (float)$timestamp);
self::$running_time_string .= $simple ? 'Start: ' : "<b>Started at</b>: ";
} else {
self::$endtime = ((float)$micro + (float)$timestamp);
self::$runningtime_string .= $simple ? 'End: ' : "<b>Stopped at</b>: ";
self::$end_time = ((float)$micro + (float)$timestamp);
self::$running_time_string .= $simple ? 'End: ' : "<b>Stopped at</b>: ";
}
self::$runningtime_string .= date('Y-m-d H:i:s', (int)$timestamp);
self::$runningtime_string .= ' ' . $micro . ($simple ? ', ' : '<br>');
self::$running_time_string .= date('Y-m-d H:i:s', (int)$timestamp);
self::$running_time_string .= ' ' . $micro . ($simple ? ', ' : '<br>');
// if both are set
if (self::$starttime && self::$endtime) {
$running_time = self::$endtime - self::$starttime;
self::$runningtime_string .= ($simple ? 'Run: ' : "<b>Script running time</b>: ") . $running_time . " s";
if (self::$start_time && self::$end_time) {
$running_time = self::$end_time - self::$start_time;
self::$running_time_string .= ($simple ? 'Run: ' : "<b>Script running time</b>: ") . $running_time . " s";
// reset start & end time after run
self::$starttime = 0;
self::$endtime = 0;
self::$start_time = 0;
self::$end_time = 0;
}
return $running_time;
}
@@ -120,7 +166,7 @@ class RunningTime
*/
public static function runningTimeString(): string
{
return self::$runningtime_string;
return self::$running_time_string;
}
}

View File

@@ -12,7 +12,9 @@ class Support
{
/**
* wrapper around microtime function to print out y-m-d h:i:s.ms
* @param int $set_microtime -1 to set micro time, 0 for none, positive for rounding
*
* @param int $set_microtime -1 to set micro time, 0 for none,
* positive for rounding
* @return string formated datetime string with microtime
*/
public static function printTime(int $set_microtime = -1): string
@@ -31,6 +33,7 @@ class Support
/**
* prints a html formatted (pre) array
*
* @param array<mixed> $array any array
* @param bool $no_html set to true to use ##HTMLPRE##
* @return string formatted array for output with <pre> tag added
@@ -44,12 +47,47 @@ class Support
}
}
/**
* alternate name for printAr function
*
* @param array<mixed> $array any array
* @param bool $no_html set to true to use ##HTMLPRE##
* @return string formatted array for output with <pre> tag added
*/
public static function printArray(array $array, bool $no_html = false): string
{
return self::printAr($array, $no_html);
}
/**
* convert bool value to string
* if $name is set prefix with nae
* default true: true, false: false
*
* @param bool $bool Variable to convert
* @param string $name [default: ''] Prefix name
* @param string $true [default: true] True string
* @param string $false [default: false] False string
* @return string String with converted bool text for debug
*/
public static function printBool(
bool $bool,
string $name = '',
string $true = 'true',
string $false = 'false'
): string {
$string = (!empty($name) ? '<b>' . $name . '</b>: ' : '')
. ($bool ? $true : $false);
return $string;
}
/**
* print out any data as string
* will convert boolean to TRUE/FALSE
* if object return get_class
* for array use printAr function, can be controlled with no_html for
* Debug\Logging compatible output
*
* @param mixed $mixed
* @param bool $no_html set to true to use ##HTMLPRE##
* @return string
@@ -57,7 +95,7 @@ class Support
public static function printToString($mixed, bool $no_html = false): string
{
if (is_bool($mixed)) {
return $mixed ? 'TRUE' : 'FALSE';
return self::printBool($mixed, '', 'TRUE', 'FALSE');
} elseif (is_resource($mixed)) {
return (string)$mixed;
} elseif (is_object($mixed)) {
@@ -74,9 +112,11 @@ class Support
/**
* if there is a need to find out which parent method called a child method,
* eg for debugging, this function does this
*
* call this method in the child method and you get the parent function that called
* @param int $level debug level, default 1
* @return ?string null or the function that called the function where this method is called
* @return ?string null or the function that called the function
* where this method is called
*/
public static function getCallerMethod(int $level = 1): ?string
{
@@ -95,6 +135,7 @@ class Support
* called is last in order
* Will start with start_level to skip unwanted from stack
* Defaults to skip level 0 wich is this methid
*
* @param integer $start_level From what level on, as defaul starts with 1
* to exclude self
* @return array<mixed> All method names in list where max is last called
@@ -119,6 +160,7 @@ class Support
* was called
* gets top level class
* loops over the debug backtrace until if finds the first class (from the end)
*
* @return string Class name with namespace
*/
public static function getCallerClass(): string

View File

@@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
namespace CoreLibs\Get;
class DotEnv
{
/** @var string constant comment char, set to # */
private const COMMENT_CHAR = '#';
/**
* parses .env file
*
* Rules for .env file
* variable is any alphanumeric string followed by = on the same line
* content starts with the first non space part
* strings can be contained in "
* strings MUST be contained in " if they are multiline
* if string starts with " it will match until another " is found
* anything AFTER " is ignored
* if there are two variables with the same name only the first is used
* variables are case sensitive
*
* @param string $path Folder to file, default is __DIR__
* @param string $env_file What file to load, default is .env
* @return int -1 other error
* 0 for success full load
* 1 for file loadable, no data or data already loaded
* 2 for file not readable or open failed
* 3 for file not found
*/
public static function readEnvFile(
string $path = __DIR__,
string $env_file = '.env'
): int {
// default -1;
$status = -1;
$env_file_target = $path . DIRECTORY_SEPARATOR . $env_file;
// this is not a file -> abort
if (!is_file($env_file_target)) {
$status = 3;
return $status;
}
// cannot open file -> abort
if (!is_readable($env_file_target)) {
$status = 2;
return $status;
}
// open file
if (($fp = fopen($env_file_target, 'r')) === false) {
$status = 2;
return $status;
}
// set to readable but not yet any data loaded
$status = 1;
$block = false;
$var = '';
while ($line = fgets($fp)) {
// main match for variable = value part
if (preg_match("/^\s*([\w_.]+)\s*=\s*((\"?).*)/", $line, $matches)) {
$var = $matches[1];
$value = $matches[2];
$quotes = $matches[3];
// 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
if (preg_match('/^"(.*[^\\\])"/U', $value, $matches)) {
$value = $matches[1];
} else {
// this is a multi line
$block = true;
// first " in string remove
// add removed new line back because this is a multi line
$value = ltrim($value, '"') . PHP_EOL;
}
} else {
// strip any quotes at end for unquoted single line
// an right hand spaces are removed too
$value = false !== ($pos = strpos($value, self::COMMENT_CHAR)) ?
rtrim(substr($value, 0, $pos)) : $value;
}
// if block is set, we strip line of slashes
$_ENV[$var] = $block === true ? stripslashes($value) : $value;
// set successful load
$status = 0;
}
} elseif ($block === true) {
// read line until there is a unescaped "
// this also strips everything after the last "
if (preg_match("/(.*[^\\\])\"/", $line, $matches)) {
$block = false;
// strip ending " and EVERYTHING that follows after that
$line = $matches[1];
}
// strip line of slashes
$_ENV[$var] .= stripslashes($line);
}
}
fclose($fp);
return $status;
}
}
// __END__

View File

@@ -4,6 +4,9 @@ declare(strict_types=1);
namespace CoreLibs\Get;
/**
* @deprecated use \CoreLibs\Get\DotEnv instead
*/
class ReadEnvFile
{
/**
@@ -24,71 +27,16 @@ class ReadEnvFile
* @return int -1 other error
* 0 for success full load
* 1 for file loadable, but no data inside
* 2 for file not readable
* 2 for file not readable or open failed
* 3 for file not found
* @deprecated Use \CoreLibs\Get\DotEnv::readEnvFile() instead
*/
public static function readEnvFile(
string $path = __DIR__,
string $env_file = '.env'
): int {
// default -1;
$status = -1;
$env_file_target = $path . DIRECTORY_SEPARATOR . $env_file;
// this is not a file -> abort
if (!is_file($env_file_target)) {
$status = 3;
return $status;
}
// cannot open file -> abort
if (($fp = fopen($env_file_target, 'r')) === false) {
$status = 2;
return $status;
}
// set to readable but not yet any data loaded
$status = 1;
$block = false;
$var = '';
while ($line = fgets($fp)) {
// main match for variable = value part
if (preg_match("/^\s*([\w_.]+)\s*=\s*((\"?).*)/", $line, $matches)) {
$var = $matches[1];
$value = $matches[2];
$quotes = $matches[3];
// 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
if (preg_match('/^"(.*[^\\\])"/U', $value, $matches)) {
$value = $matches[1];
} else {
// this is a multi line
$block = true;
// first " in string remove
// add removed new line back because this is a multi line
$value = ltrim($value, '"') . PHP_EOL;
}
}
// if block is set, we strip line of slashes
$_ENV[$var] = $block === true ? stripslashes($value) : $value;
// set successful load
$status = 0;
}
} elseif ($block === true) {
// read line until there is a unescaped "
// this also strips everything after the last "
if (preg_match("/(.*[^\\\])\"/", $line, $matches)) {
$block = false;
// strip ending " and EVERYTHING that follows after that
$line = $matches[1];
}
// strip line of slashes
$_ENV[$var] .= stripslashes($line);
}
}
fclose($fp);
return $status;
return \CoreLibs\Get\DotEnv::readEnvFile($path, $env_file);
}
}
// __END__

View File

@@ -17,6 +17,7 @@ class System
/**
* helper function for PHP file upload error messgaes to messge string
*
* @param int $error_code integer _FILE upload error code
* @return string message string, translated
*/
@@ -53,6 +54,7 @@ class System
/**
* get the host name without the port as given by the SELF var
*
* @return array<mixed> host name/port name
*/
public static function getHostName(): array
@@ -64,6 +66,7 @@ class System
/**
* get the page name of the curronte page
*
* @param int $strip_ext WITH_EXTENSION: keep filename as is (default)
* NO_EXTENSION: strip page file name extension
* FULL_PATH: keep filename as is, but add dirname too

View File

@@ -37,6 +37,7 @@ class FileReader
/**
* file read constructor
*
* @param string $filename file name to load
*/
public function __construct(string $filename)
@@ -55,6 +56,7 @@ class FileReader
/**
* read byte data length
*
* @param int $bytes how many bytes to read
* @return string read data as string
*/
@@ -83,6 +85,7 @@ class FileReader
/**
* seek to a position in the file
*
* @param int $pos position where to go to
* @return int file position after seek done
*/
@@ -98,6 +101,7 @@ class FileReader
/**
* get current position in file
*
* @return int current position in bytes
*/
public function currentpos(): int
@@ -107,6 +111,7 @@ class FileReader
/**
* file length/size
*
* @return int file size in bytes
*/
public function length(): int
@@ -116,6 +121,7 @@ class FileReader
/**
* close open file handler
*
* @return void has no return
*/
public function close(): void

View File

@@ -38,6 +38,7 @@ class StreamReader
/**
* should return a string [FIXME: perhaps return array of bytes?]
*
* @param int $bytes bytes to read
* @return bool dummy false
*/
@@ -48,6 +49,7 @@ class StreamReader
/**
* should return new position
*
* @param int $position seek to position
* @return bool dummy false
*/
@@ -58,6 +60,7 @@ class StreamReader
/**
* returns current position
*
* @return bool dummy false
*/
public function currentpos(): bool
@@ -67,6 +70,7 @@ class StreamReader
/**
* returns length of entire stream (limit for seekto()s)
*
* @return bool dummy false
*/
public function length(): bool

View File

@@ -33,6 +33,7 @@ class StringReader
/**
* constructor for string reader
*
* @param string $str basic string
*/
public function __construct(string $str = '')
@@ -43,6 +44,7 @@ class StringReader
/**
* read bytes in string
*
* @param int $bytes bytes to read in string
* @return string data read in length of bytes as string
*/
@@ -59,6 +61,7 @@ class StringReader
/**
* go to position in string
*
* @param int $pos position in string
* @return int new position in string after seek
*/
@@ -73,6 +76,7 @@ class StringReader
/**
* get current position in string
*
* @return int position in string
*/
public function currentpos(): int
@@ -82,6 +86,7 @@ class StringReader
/**
* get length of string
*
* @return int return length of assigned string
*/
public function length(): int

View File

@@ -402,7 +402,7 @@ class L10n
/**
* Sets the path for a domain.
* must be set before running l10nReloadMOfile
* must be set before running getTranslator (former l10nReloadMOfile)
*
* @param string $domain Domain name
* @param string $path Path where to find locales

View File

@@ -12,6 +12,7 @@ class Elements
{
/**
* print the date/time drop downs, used in any queue/send/insert at date/time place
*
* @param int $year year YYYY
* @param int $month month m
* @param int $day day d
@@ -22,8 +23,9 @@ class Elements
* also used for ID in the on change JS call
* @param int $min_steps default is 1 (minute), can set to anything,
* is used as sum up from 0
* @param bool $name_pos_back default false, if set to true, the name will be printend
* after the drop down and not before the drop down
* @param bool $name_pos_back default false, if set to true,
* the name will be printend after the drop down
* and not before the drop down
* @return string HTML formated strings for drop down lists of date and time
*/
public static function printDateTime(
@@ -132,9 +134,11 @@ class Elements
}
/**
* tries to find mailto:user@bubu.at and changes it into -> <a href="mailto:user@bubu.at">E-Mail senden</a>
* tries to find mailto:user@bubu.at and changes it into ->
* <a href="mailto:user@bubu.at">E-Mail senden</a>
* or tries to take any url (http, ftp, etc) and transform it into a valid URL
* the string is in the format: some url|name#css|, same for email
*
* @param string $string data to transform to a valid HTML url
* @param string $target target string, default _blank
* @return string correctly formed html url link
@@ -202,7 +206,8 @@ class Elements
$output
) ?: '';
// we have one slashes after the Protocol -> internal link no domain, strip out the proto
// we have one slashes after the Protocol ->
// internal link no domain, strip out the proto
// $output = preg_replace("/($protRegex)\/(.*)/e", "\\2", $ouput);
// post processing
@@ -217,6 +222,7 @@ class Elements
/**
* internal function, called by the magic url create functions.
* checks if title $_4 exists, if not, set url as title
*
* @param string $href url link
* @param string $atag anchor tag (define both type or url)
* @param string $_1 part of the URL, if atag is set, _1 is not used
@@ -253,6 +259,7 @@ class Elements
/**
* internal function for createing email, returns data to magic_url method
*
* @param string $mailto email address
* @param string $atag atag (define type of url)
* @param string $_1 parts of the email _1 before @, 3_ tld

View File

@@ -299,6 +299,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* construct form generator
*
* @param array<mixed> $db_config db config array, mandatory
* @param \CoreLibs\Debug\Logging|null $log Logging class, null auto set
* @param \CoreLibs\Language\L10n|null $l10n l10n language class, null auto set
@@ -463,6 +464,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* dumps all values into output (for error msg)
*
* @return string full table array data output as string html formatted
*/
public function formDumpTableArray()
@@ -482,6 +484,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
* the value of the $want_key array field
* works only with fields that appear only ONCE
* if multiple gets only FIRST
*
* @param string $want_key key to search for
* @param string|null $key_value value to match to (optional)
* @return string|null returns key found or empty string
@@ -505,6 +508,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* array of fields
*
* @param string $want_key the key where you want the data from
* @param string|null $key_value if set searches for special right value
* @return array<mixed> found key fields
@@ -529,6 +533,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* formated output for the error && warning msg
*
* @return array<string,string|int> error message with msg, width, clas
*/
public function formPrintMsg(): array
@@ -550,6 +555,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
// next for functions are pre_test fkts for easier default new,load, etc handling
/**
* default load procedure
*
* @param string $archive_id archive id to load
* @return void has no return
*/
@@ -568,6 +574,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* default new procedure
*
* @return void has no return
*/
public function formProcedureNew(): void
@@ -589,6 +596,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* default save procedure
*
* @return void has no return
*/
public function formProcedureSave(): void
@@ -608,6 +616,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* default delete procedure
*
* @return void has no return
*/
public function formProcedureDelete(): void
@@ -634,6 +643,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* default delete procedure
*
* @param array<mixed> $element_list element array that should be removed
* @param array<mixed> $remove_name key names that should be removed
* @return void has no return
@@ -732,6 +742,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* create the load list and return it as an array
*
*
* @return array<string,mixed> load list array with primary key, name and selected entry
*/
public function formCreateLoad(): array
@@ -794,6 +806,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* Create new entry element for HTML output
*
* @param bool $hide_new_checkbox show or hide the new checkbox, default is false
* @return array<string,string|int> return the new create array with name & checkbox show flag
*/
@@ -879,6 +892,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* create a form element based on the settings in the element array entry
*
* @param string $element_name the name from the array, you want to have build
* @param string|null $query can overrule internal query data,
* for drop down, as data comes from a reference table
@@ -1120,6 +1134,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
* should be cought like this ...
* if ($msg = $form->form_error_check())
* $error=1;
*
* @return void has no return
*/
public function formErrorCheck(): void
@@ -1530,6 +1545,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* sets the order to the maximum, if order flag is set in array
*
* @return array<mixed> table array with set order number
*/
public function formSetOrder(): array
@@ -1569,6 +1585,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* resets all values in table_array and in the reference tables
*
* @return void has no return
*/
public function formUnsetTableArray(): void
@@ -1601,6 +1618,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* load a table & reference
*
* @param string|null $pk_id overrule pk_id
* @return void has no return
*/
@@ -1644,6 +1662,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
* save a table, reference and all input fields
* note that the addslashes flag here is passed on to the dbWrite method
* it only does html conversion, add slashes for DB is done automatically
*
* @param bool $addslashes override internal addslasahes flag (default false)
* @return void has no return
*/
@@ -2036,6 +2055,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* delete a table and reference fields
*
* @return void
*/
public function formDeleteTableArray()
@@ -2081,6 +2101,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* creates HTML hidden input fields out of an hash array
*
* @param array<mixed> $hidden_array The list of fields to be added as hidden
* @return array<mixed> key -> value list of hidden fileds data
*/
@@ -2114,6 +2135,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* creates the multiple select part for a reference_table
*
* @param string $table_name Table name for reference array lookup
* @return array<string,mixed> Reference table output array
*/
@@ -2151,6 +2173,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
* this currently only works for a list that is filled from a sub table and creates
* only a connection to this one new version will allow a sub list with free input
* fields to directly fill a sub table to a master table
*
* @param string $table_name Which element entry to create
* @return array<string,mixed> Element for html creation
*/

View File

@@ -13,6 +13,7 @@ class Token
{
/**
* sets a form token in a session and returns form token
*
* @param string $name optional form name, default form_token
* @return string token name for given form id string
*/
@@ -26,6 +27,7 @@ class Token
/**
* checks if the form token matches the session set form token
*
* @param string $token token string to check
* @param string $name optional form name to check to, default form_token
* @return bool false if not set, or true/false if matching or not mtaching

View File

@@ -12,11 +12,14 @@ class Image
{
/**
* converts picture to a thumbnail with max x and max y size
*
* @param string $pic source image file with or without path
* @param int $size_x maximum size width
* @param int $size_y maximum size height
* @param string $dummy empty, or file_type to show an icon instead of nothing if file is not found
* @param string $path if source start is not ROOT path, if empty ROOT is choosen
* @param string $dummy empty, or file_type to show an icon
* instead of nothing if file is not found
* @param string $path if source start is not ROOT path,
* if empty ROOT is choosen
* @param string $cache_source cache path, if not given TMP is used
* @param bool $clear_cache if set to true, will create thumb all the tame
* @return string|bool thumbnail name, or false for error
@@ -154,6 +157,7 @@ class Image
* the resize is to max of one size
* if both are set, those are the max sizes (aspect ration is always ekpt)
* - if path is not given will cache folder for current path set
*
* @param string $filename source file name with full path
* @param int $thumb_width thumbnail width
* @param int $thumb_height thumbnail height
@@ -162,7 +166,8 @@ class Image
* create a dummy image file and return it
* @param bool $use_cache default to true, set to false to skip
* creating new image if exists
* @param bool $high_quality default to true, uses sample version, set to false
* @param bool $high_quality default to true, uses sample version,
* set to false to not use (default true)
* to use quick but less nice version
* @param int $jpeg_quality default 80, set image quality for jpeg only
* @return string|bool thumbnail with path
@@ -416,6 +421,7 @@ class Image
* reads the rotation info of an file and rotates it to be correctly upright
* this is done because not all software honers the exit Orientation flag
* only works with jpg or png
*
* @param string $filename path + filename to rotate. This file must be writeable
* @return void
*/

View File

@@ -109,6 +109,7 @@ class ProgressBar
/**
* progress bar constructor
*
* @param integer $width progress bar width, default 0
* @param integer $height progress bar height, default 0
*/
@@ -130,6 +131,7 @@ class ProgressBar
/**
* flush cache hack for IE and others
*
* @param integer $clear_buffer_size buffer size override
* @return void has not return
*/
@@ -146,6 +148,7 @@ class ProgressBar
/**
* [__calculatePercent description]
*
* @param float $step percent step to do
* @return float percent step done
*/
@@ -164,6 +167,7 @@ class ProgressBar
/**
* calculate position in bar step
*
* @param float $step percent step to do
* @return array<string,int|float> bar position as array
*/
@@ -224,6 +228,7 @@ class ProgressBar
/**
* set the step
*
* @param float $step percent step to do
* @return void
*/
@@ -241,6 +246,7 @@ class ProgressBar
// public functions
/**
* set frame layout
*
* @param integer $width bar width
* @param integer $height bar height
* @return void
@@ -269,6 +275,7 @@ class ProgressBar
/**
* set bar label text
* allowed types are: text, button, step, percent, percentlbl, crossbar
*
* @param string $type label type
* @param string $name label name (internal)
* @param string $value label output name (optional)
@@ -374,6 +381,7 @@ class ProgressBar
/**
* add a button to the progress bar
*
* @param string $name button name (internal)
* @param string $value button text (output)
* @param string $action button action (link)
@@ -389,6 +397,7 @@ class ProgressBar
/**
* set the label position
*
* @param string $name label name to set
* @param int $left left px
* @param int $top top px
@@ -439,6 +448,7 @@ class ProgressBar
/**
* set label color
*
* @param string $name label name to set
* @param string $color color value in rgb html hex
* @return void
@@ -455,6 +465,7 @@ class ProgressBar
/**
* set the label background color
*
* @param string $name label name to set
* @param string $color background color to set in rgb html hex
* @return void
@@ -471,6 +482,7 @@ class ProgressBar
/**
* [setLabelFont description]
*
* @param string $name label name to set
* @param int $size font size in px
* @param string $family font family (default empty)
@@ -521,7 +533,8 @@ class ProgressBar
}
/**
* set the label valeu
* set the label value
*
* @param string $name label name to set
* @param string $value label value (output)
* @return void
@@ -539,6 +552,7 @@ class ProgressBar
/**
* set the bar color
*
* @param string $color color for the progress bar in rgb html hex
* @return void
*/
@@ -554,6 +568,7 @@ class ProgressBar
/**
* set the progress bar background color
*
* @param string $color background color in rgb html hex
* @return void
*/
@@ -569,6 +584,7 @@ class ProgressBar
/**
* progress bar direct (left/right)
*
* @param string $direction set direction as left/right
* @return void
*/
@@ -591,6 +607,7 @@ class ProgressBar
/**
* get the progress bar base HTML
*
* @return string progress bar HTML code
*/
public function getHtml(): string
@@ -780,6 +797,7 @@ class ProgressBar
/**
* show the progress bar after initialize
*
* @return void has no return
*/
public function show(): void
@@ -792,6 +810,7 @@ class ProgressBar
/**
* move the progress bar by one step
* prints out javascript to move progress bar
*
* @param float $step percent step
* @return void has no return
*/
@@ -851,6 +870,7 @@ class ProgressBar
/**
* moves progress bar by one step (1)
*
* @return void has no return
*/
public function moveNext(): void
@@ -860,6 +880,7 @@ class ProgressBar
/**
* moves the progress bar back to the beginning
*
* @return void has no return
*/
public function moveMin(): void
@@ -869,6 +890,7 @@ class ProgressBar
/**
* hide the progress bar if it is visible
*
* @return void has no return
*/
public function hide(): void
@@ -888,6 +910,7 @@ class ProgressBar
/**
* show progress bar again after it was hidden with hide()
*
* @return void has no return
*/
public function unhide(): void

View File

@@ -156,6 +156,7 @@ class SmartyExtend extends \Smarty
* constructor class, just sets the language stuff
* calls L10 for pass on internaly in smarty
* also registers the getvar caller plugin
*
* @param \CoreLibs\Language\L10n $l10n l10n language class
* @param array<string,string> $locale locale data read from setLocale
*/
@@ -250,6 +251,7 @@ class SmartyExtend extends \Smarty
/**
* sets all internal paths and names that need to be passed on to the smarty template
*
* @return void
*/
public function setSmartyPaths(): void
@@ -344,6 +346,7 @@ class SmartyExtend extends \Smarty
/**
* wrapper call for setSmartyVars
* this is for frontend type and will not set any only admin needed variables
*
* @return void
*/
public function setSmartyVarsFrontend(): void
@@ -362,6 +365,7 @@ class SmartyExtend extends \Smarty
/**
* set smarty pass on variables, sub template names and finally calls the smarty parser
*
* @param boolean $admin_call default false, will set admin only variables
* @return void
*/
@@ -472,6 +476,7 @@ class SmartyExtend extends \Smarty
/**
* merge outside object HEADER/DATA/DEBUG_DATA vars into the smarty class
*
* @param object $cms object that has header/data/debug_data
* @return void
*/
@@ -490,6 +495,7 @@ class SmartyExtend extends \Smarty
/**
* render smarty data (can be called sepparate)
*
* @return void
*/
public function renderSmarty(): void

View File

@@ -37,8 +37,10 @@ return array(
'CoreLibs\\DB\\SQL\\SqlInterface\\SqlFunctions' => $baseDir . '/lib/CoreLibs/DB/SQL/SqlInterface/SqlFunctions.php',
'CoreLibs\\Debug\\FileWriter' => $baseDir . '/lib/CoreLibs/Debug/FileWriter.php',
'CoreLibs\\Debug\\Logging' => $baseDir . '/lib/CoreLibs/Debug/Logging.php',
'CoreLibs\\Debug\\MemoryUsage' => $baseDir . '/lib/CoreLibs/Debug/MemoryUsage.php',
'CoreLibs\\Debug\\RunningTime' => $baseDir . '/lib/CoreLibs/Debug/RunningTime.php',
'CoreLibs\\Debug\\Support' => $baseDir . '/lib/CoreLibs/Debug/Support.php',
'CoreLibs\\Get\\DotEnv' => $baseDir . '/lib/CoreLibs/Get/DotEnv.php',
'CoreLibs\\Get\\ReadEnvFile' => $baseDir . '/lib/CoreLibs/Get/ReadEnvFile.php',
'CoreLibs\\Get\\System' => $baseDir . '/lib/CoreLibs/Get/System.php',
'CoreLibs\\Language\\Core\\CachedFileReader' => $baseDir . '/lib/CoreLibs/Language/Core/CachedFileReader.php',
@@ -179,7 +181,6 @@ return array(
'PHPUnit\\Framework\\MockObject\\MockObject' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/MockObject.php',
'PHPUnit\\Framework\\MockObject\\MockTrait' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/MockTrait.php',
'PHPUnit\\Framework\\MockObject\\MockType' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/MockType.php',
'PHPUnit\\Framework\\MockObject\\MockedCloneMethod' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/Api/MockedCloneMethod.php',
'PHPUnit\\Framework\\MockObject\\OriginalConstructorInvocationRequiredException' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/Exception/OriginalConstructorInvocationRequiredException.php',
'PHPUnit\\Framework\\MockObject\\ReflectionException' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/Exception/ReflectionException.php',
'PHPUnit\\Framework\\MockObject\\ReturnValueNotConfiguredException' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/Exception/ReturnValueNotConfiguredException.php',
@@ -210,7 +211,6 @@ return array(
'PHPUnit\\Framework\\MockObject\\UnknownClassException' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/Exception/UnknownClassException.php',
'PHPUnit\\Framework\\MockObject\\UnknownTraitException' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/Exception/UnknownTraitException.php',
'PHPUnit\\Framework\\MockObject\\UnknownTypeException' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/Exception/UnknownTypeException.php',
'PHPUnit\\Framework\\MockObject\\UnmockedCloneMethod' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/Api/UnmockedCloneMethod.php',
'PHPUnit\\Framework\\MockObject\\Verifiable' => $vendorDir . '/phpunit/phpunit/src/Framework/MockObject/Verifiable.php',
'PHPUnit\\Framework\\NoChildTestSuiteException' => $vendorDir . '/phpunit/phpunit/src/Framework/Exception/NoChildTestSuiteException.php',
'PHPUnit\\Framework\\OutputError' => $vendorDir . '/phpunit/phpunit/src/Framework/Exception/OutputError.php',

View File

@@ -102,8 +102,10 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9
'CoreLibs\\DB\\SQL\\SqlInterface\\SqlFunctions' => __DIR__ . '/../..' . '/lib/CoreLibs/DB/SQL/SqlInterface/SqlFunctions.php',
'CoreLibs\\Debug\\FileWriter' => __DIR__ . '/../..' . '/lib/CoreLibs/Debug/FileWriter.php',
'CoreLibs\\Debug\\Logging' => __DIR__ . '/../..' . '/lib/CoreLibs/Debug/Logging.php',
'CoreLibs\\Debug\\MemoryUsage' => __DIR__ . '/../..' . '/lib/CoreLibs/Debug/MemoryUsage.php',
'CoreLibs\\Debug\\RunningTime' => __DIR__ . '/../..' . '/lib/CoreLibs/Debug/RunningTime.php',
'CoreLibs\\Debug\\Support' => __DIR__ . '/../..' . '/lib/CoreLibs/Debug/Support.php',
'CoreLibs\\Get\\DotEnv' => __DIR__ . '/../..' . '/lib/CoreLibs/Get/DotEnv.php',
'CoreLibs\\Get\\ReadEnvFile' => __DIR__ . '/../..' . '/lib/CoreLibs/Get/ReadEnvFile.php',
'CoreLibs\\Get\\System' => __DIR__ . '/../..' . '/lib/CoreLibs/Get/System.php',
'CoreLibs\\Language\\Core\\CachedFileReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/CachedFileReader.php',
@@ -244,7 +246,6 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9
'PHPUnit\\Framework\\MockObject\\MockObject' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/MockObject.php',
'PHPUnit\\Framework\\MockObject\\MockTrait' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/MockTrait.php',
'PHPUnit\\Framework\\MockObject\\MockType' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/MockType.php',
'PHPUnit\\Framework\\MockObject\\MockedCloneMethod' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/Api/MockedCloneMethod.php',
'PHPUnit\\Framework\\MockObject\\OriginalConstructorInvocationRequiredException' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/Exception/OriginalConstructorInvocationRequiredException.php',
'PHPUnit\\Framework\\MockObject\\ReflectionException' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/Exception/ReflectionException.php',
'PHPUnit\\Framework\\MockObject\\ReturnValueNotConfiguredException' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/Exception/ReturnValueNotConfiguredException.php',
@@ -275,7 +276,6 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9
'PHPUnit\\Framework\\MockObject\\UnknownClassException' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/Exception/UnknownClassException.php',
'PHPUnit\\Framework\\MockObject\\UnknownTraitException' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/Exception/UnknownTraitException.php',
'PHPUnit\\Framework\\MockObject\\UnknownTypeException' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/Exception/UnknownTypeException.php',
'PHPUnit\\Framework\\MockObject\\UnmockedCloneMethod' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/Api/UnmockedCloneMethod.php',
'PHPUnit\\Framework\\MockObject\\Verifiable' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/MockObject/Verifiable.php',
'PHPUnit\\Framework\\NoChildTestSuiteException' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/Exception/NoChildTestSuiteException.php',
'PHPUnit\\Framework\\OutputError' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/Exception/OutputError.php',

View File

@@ -429,17 +429,17 @@
},
{
"name": "phpdocumentor/type-resolver",
"version": "1.6.0",
"version_normalized": "1.6.0.0",
"version": "1.6.1",
"version_normalized": "1.6.1.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706"
"reference": "77a32518733312af16a44300404e945338981de3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706",
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/77a32518733312af16a44300404e945338981de3",
"reference": "77a32518733312af16a44300404e945338981de3",
"shasum": ""
},
"require": {
@@ -450,7 +450,7 @@
"ext-tokenizer": "*",
"psalm/phar": "^4.8"
},
"time": "2022-01-04T19:58:01+00:00",
"time": "2022-03-15T21:29:03+00:00",
"type": "library",
"extra": {
"branch-alias": {
@@ -476,7 +476,7 @@
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
"support": {
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0"
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.1"
},
"install-path": "../phpdocumentor/type-resolver"
},
@@ -885,17 +885,17 @@
},
{
"name": "phpunit/phpunit",
"version": "9.5.19",
"version_normalized": "9.5.19.0",
"version": "9.5.20",
"version_normalized": "9.5.20.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807"
"reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35ea4b7f3acabb26f4bb640f8c30866c401da807",
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/12bc8879fb65aef2138b26fc633cb1e3620cffba",
"reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba",
"shasum": ""
},
"require": {
@@ -936,7 +936,7 @@
"ext-soap": "*",
"ext-xdebug": "*"
},
"time": "2022-03-15T09:57:31+00:00",
"time": "2022-04-01T12:37:26+00:00",
"bin": [
"phpunit"
],
@@ -975,7 +975,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.19"
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.20"
},
"funding": [
{
@@ -1373,17 +1373,17 @@
},
{
"name": "sebastian/environment",
"version": "5.1.3",
"version_normalized": "5.1.3.0",
"version": "5.1.4",
"version_normalized": "5.1.4.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
"reference": "388b6ced16caa751030f6a69e588299fa09200ac"
"reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/388b6ced16caa751030f6a69e588299fa09200ac",
"reference": "388b6ced16caa751030f6a69e588299fa09200ac",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7",
"reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7",
"shasum": ""
},
"require": {
@@ -1395,7 +1395,7 @@
"suggest": {
"ext-posix": "*"
},
"time": "2020-09-28T05:52:38+00:00",
"time": "2022-04-03T09:37:03+00:00",
"type": "library",
"extra": {
"branch-alias": {
@@ -1427,7 +1427,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/environment/issues",
"source": "https://github.com/sebastianbergmann/environment/tree/5.1.3"
"source": "https://github.com/sebastianbergmann/environment/tree/5.1.4"
},
"funding": [
{

View File

@@ -5,8 +5,8 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => 'b075ee3dc5654a33da9e41fab338edb536695a25',
'name' => 'gullevek/corelibs',
'reference' => NULL,
'name' => 'gullevek/corelibs-dev',
'dev' => true,
),
'versions' => array(
@@ -19,13 +19,13 @@
'reference' => '10dcfce151b967d20fde1b34ae6640712c3891bc',
'dev_requirement' => true,
),
'gullevek/corelibs' => array(
'gullevek/corelibs-dev' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => 'b075ee3dc5654a33da9e41fab338edb536695a25',
'reference' => NULL,
'dev_requirement' => false,
),
'myclabs/deep-copy' => array(
@@ -83,12 +83,12 @@
'dev_requirement' => true,
),
'phpdocumentor/type-resolver' => array(
'pretty_version' => '1.6.0',
'version' => '1.6.0.0',
'pretty_version' => '1.6.1',
'version' => '1.6.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../phpdocumentor/type-resolver',
'aliases' => array(),
'reference' => '93ebd0014cab80c4ea9f5e297ea48672f1b87706',
'reference' => '77a32518733312af16a44300404e945338981de3',
'dev_requirement' => true,
),
'phpspec/prophecy' => array(
@@ -146,12 +146,12 @@
'dev_requirement' => true,
),
'phpunit/phpunit' => array(
'pretty_version' => '9.5.19',
'version' => '9.5.19.0',
'pretty_version' => '9.5.20',
'version' => '9.5.20.0',
'type' => 'library',
'install_path' => __DIR__ . '/../phpunit/phpunit',
'aliases' => array(),
'reference' => '35ea4b7f3acabb26f4bb640f8c30866c401da807',
'reference' => '12bc8879fb65aef2138b26fc633cb1e3620cffba',
'dev_requirement' => true,
),
'sebastian/cli-parser' => array(
@@ -209,12 +209,12 @@
'dev_requirement' => true,
),
'sebastian/environment' => array(
'pretty_version' => '5.1.3',
'version' => '5.1.3.0',
'pretty_version' => '5.1.4',
'version' => '5.1.4.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/environment',
'aliases' => array(),
'reference' => '388b6ced16caa751030f6a69e588299fa09200ac',
'reference' => '1b5dff7bb151a4db11d49d90e5408e4e938270f7',
'dev_requirement' => true,
),
'sebastian/exporter' => array(

View File

@@ -550,7 +550,7 @@ final class TypeResolver
);
}
if (!$minValue || !$maxValue || $tokenCounter > 4) {
if ($minValue === null || $maxValue === null || $tokenCounter > 4) {
throw new RuntimeException(
'int<min,max> has not the correct format'
);

View File

@@ -2,6 +2,18 @@
All notable changes of the PHPUnit 8.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [8.5.26] - 2022-04-01
### Fixed
* [#4938](https://github.com/sebastianbergmann/phpunit/issues/4938): Test Double code generator does not handle `void` return type declaration on `__clone()` methods
## [8.5.25] - 2022-03-16
### Fixed
* [#4934](https://github.com/sebastianbergmann/phpunit/issues/4934): Code Coverage does not work with PHPUnit 8.5.24 PHAR on PHP 7
## [8.5.24] - 2022-03-05 - #StandWithUkraine
### Changed
@@ -207,6 +219,8 @@ All notable changes of the PHPUnit 8.5 release series are documented in this fil
* [#3967](https://github.com/sebastianbergmann/phpunit/issues/3967): Cannot double interface that extends interface that extends `\Throwable`
* [#3968](https://github.com/sebastianbergmann/phpunit/pull/3968): Test class run in a separate PHP process are passing when `exit` called inside
[8.5.26]: https://github.com/sebastianbergmann/phpunit/compare/8.5.25...8.5.26
[8.5.25]: https://github.com/sebastianbergmann/phpunit/compare/8.5.24...8.5.25
[8.5.24]: https://github.com/sebastianbergmann/phpunit/compare/8.5.23...8.5.24
[8.5.23]: https://github.com/sebastianbergmann/phpunit/compare/8.5.22...8.5.23
[8.5.22]: https://github.com/sebastianbergmann/phpunit/compare/8.5.21...8.5.22

Some files were not shown because too many files have changed in this diff Show More