Compare commits

...

4 Commits

Author SHA1 Message Date
Clemens Schwaighofer
d070c4e461 phan min php set to 8.2 2024-12-05 13:59:20 +09:00
Clemens Schwaighofer
e57c336dba Clean up to use session methods and not _SESSION directly
Add session_unset for unsetAll and rename this method to "clear"
2024-12-05 13:52:45 +09:00
Clemens Schwaighofer
075fe967d5 Merge branch 'NewFeatures' into Feature-FixSessionClass 2024-12-05 12:18:51 +09:00
Clemens Schwaighofer
0e5f637052 Update Serial to Identity function
Return status as varchar from change.

clean up edit table SQL files with too many empty lines
2024-12-05 12:11:07 +09:00
10 changed files with 69 additions and 58 deletions

View File

@@ -27,7 +27,7 @@ use Phan\Config;
return [ return [
// "target_php_version" => "8.2", // "target_php_version" => "8.2",
"minimum_target_php_version" => "8.1", "minimum_target_php_version" => "8.2",
// turn color on (-C) // turn color on (-C)
"color_issue_messages_if_supported" => true, "color_issue_messages_if_supported" => true,
// If true, missing properties will be created when // If true, missing properties will be created when

View File

@@ -6,7 +6,8 @@
-- @param name col The column to be changed -- @param name col The column to be changed
-- @param varchar identity_type [default=a] Allowed a, d, assigned, default -- @param varchar identity_type [default=a] Allowed a, d, assigned, default
-- @param varchar col_type [default=''] Allowed smallint, int, bigint, int2, int4, int8 -- @param varchar col_type [default=''] Allowed smallint, int, bigint, int2, int4, int8
-- @raises EXCEPTON on column not found, no linked sequence, more than one linked sequence found -- @returns varchar status tring
-- @raises EXCEPTON on column not found, no linked sequence, more than one linked sequence found, invalid col type
-- --
CREATE OR REPLACE FUNCTION upgrade_serial_to_identity( CREATE OR REPLACE FUNCTION upgrade_serial_to_identity(
tbl regclass, tbl regclass,
@@ -14,17 +15,18 @@ CREATE OR REPLACE FUNCTION upgrade_serial_to_identity(
identity_type varchar = 'a', identity_type varchar = 'a',
col_type varchar = '' col_type varchar = ''
) )
RETURNS void RETURNS varchar
LANGUAGE plpgsql LANGUAGE plpgsql
AS $$ AS $$
DECLARE DECLARE
colnum smallint; colnum SMALLINT;
seqid oid; seqid OID;
count int; count INT;
col_type_oid int; col_type_oid INT;
col_type_len int; col_type_len INT;
current_col_atttypid oid; current_col_atttypid OID;
current_col_attlen int; current_col_attlen INT;
status_string VARCHAR;
BEGIN BEGIN
-- switch between always (default) or default identiy type -- switch between always (default) or default identiy type
IF identity_type NOT IN ('a', 'd', 'assigned', 'default') THEN IF identity_type NOT IN ('a', 'd', 'assigned', 'default') THEN
@@ -59,6 +61,10 @@ BEGIN
RAISE EXCEPTION 'more than one linked sequence found'; RAISE EXCEPTION 'more than one linked sequence found';
END IF; END IF;
IF col_type <> '' AND col_type NOT IN ('smallint', 'int', 'bigint', 'int2', 'int4', 'int8') THEN
RAISE EXCEPTION 'Invalid col type: %', col_type;
END IF;
-- drop the default -- drop the default
EXECUTE 'ALTER TABLE ' || tbl || ' ALTER COLUMN ' || quote_ident(col) || ' DROP DEFAULT'; EXECUTE 'ALTER TABLE ' || tbl || ' ALTER COLUMN ' || quote_ident(col) || ' DROP DEFAULT';
@@ -74,34 +80,31 @@ BEGIN
SET attidentity = identity_type SET attidentity = identity_type
WHERE attrelid = tbl WHERE attrelid = tbl
AND attname = col; AND attname = col;
RAISE NOTICE 'Update to identity for table "%" and columen "%" with type "%"', tbl, col, identity_type; status_string := 'Updated to identity for table "' || tbl || '" and columen "' || col || '" with type "' || identity_type || '"';
-- set type if requested and not empty -- set type if requested and not empty
IF col_type <> '' THEN IF col_type <> '' THEN
IF col_type IN ('smallint', 'int', 'bigint', 'int2', 'int4', 'int8') THEN -- rewrite smallint, int, bigint
-- rewrite smallint, int, bigint IF col_type = 'smallint' THEN
IF col_type = 'smallint' THEN col_type := 'int2';
col_type := 'int2'; ELSIF col_type = 'int' THEN
ELSIF col_type = 'int' THEN col_type := 'int4';
col_type := 'int4'; ELSIF col_type = 'bigint' THEN
ELSIF col_type = 'bigint' THEN col_type := 'int8';
col_type := 'int8'; END IF;
END IF; -- get the length and oid for selected
-- get the length and oid for selected SELECT oid, typlen INTO col_type_oid, col_type_len FROM pg_type WHERE typname = col_type;
SELECT oid, typlen INTO col_type_oid, col_type_len FROM pg_type WHERE typname = col_type; -- set only if diff or hight
-- set only if diff or hight IF current_col_atttypid <> col_type_oid AND col_type_len > current_col_attlen THEN
IF current_col_atttypid <> col_type_oid AND col_type_len > current_col_attlen THEN status_string := status_string || '. Change col type: ' || col_type;
RAISE NOTICE 'Change col type: %', col_type; -- update type
-- update type UPDATE pg_attribute
UPDATE pg_attribute SET
SET atttypid = col_type_oid, attlen = col_type_len
atttypid = col_type_oid, attlen = col_type_len WHERE attrelid = tbl
WHERE attrelid = tbl AND attname = col;
AND attname = col;
END IF;
ELSE
RAISE NOTICE 'Invalid col type: %', col_type;
END IF; END IF;
END IF; END IF;
RETURN status_string;
END; END;
$$; $$;

View File

@@ -12,5 +12,3 @@ CREATE TABLE edit_menu_group (
flag VARCHAR, flag VARCHAR,
order_number INT NOT NULL order_number INT NOT NULL
) INHERITS (edit_generic) WITHOUT OIDS; ) INHERITS (edit_generic) WITHOUT OIDS;

View File

@@ -16,5 +16,3 @@ CREATE TABLE edit_page_access (
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE, 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 enabled SMALLINT NOT NULL DEFAULT 0
) INHERITS (edit_generic) WITHOUT OIDS; ) INHERITS (edit_generic) WITHOUT OIDS;

View File

@@ -444,7 +444,7 @@ final class CoreLibsCreateSessionTest extends TestCase
); );
} }
// unset all // unset all
$session->unsetAll(); $session->clear();
// check unset // check unset
foreach (array_keys($test_values) as $name) { foreach (array_keys($test_values) as $name) {
$this->assertEquals( $this->assertEquals(

View File

@@ -16,6 +16,8 @@ define('USE_DATABASE', false);
require 'config.php'; require 'config.php';
// define log file id // define log file id
$LOG_FILE_ID = 'classTest-lang'; $LOG_FILE_ID = 'classTest-lang';
$SET_SESSION_NAME = EDIT_SESSION_NAME;
$session = new CoreLibs\Create\Session($SET_SESSION_NAME);
ob_end_flush(); ob_end_flush();
$PAGE_NAME = 'TEST CLASS: LANG'; $PAGE_NAME = 'TEST CLASS: LANG';
@@ -70,10 +72,12 @@ print "[OVERRIDE]: " . Support::printAr($get_locale) . "<br>";
// DEFAULT_DOMAIN // DEFAULT_DOMAIN
// DEFAULT_CHARSET (should be set from DEFAULT_LOCALE) // DEFAULT_CHARSET (should be set from DEFAULT_LOCALE)
// LOCALE_PATH // LOCALE_PATH
$_SESSION['DEFAULT_LOCALE'] = 'ja_JP.UTF-8'; $session->setMany([
$_SESSION['DEFAULT_CHARSET'] = 'UTF-8'; 'DEFAULT_LOCALE' => 'ja_JP.UTF-8',
$_SESSION['DEFAULT_DOMAIN'] = 'admin'; 'DEFAULT_CHARSET' => 'UTF-8',
$_SESSION['LOCALE_PATH'] = BASE . INCLUDES . LOCALE; 'DEFAULT_DOMAIN' => 'admin',
'LOCALE_PATH' => BASE . INCLUDES . LOCALE,
]);
$get_locale = Language\GetLocale::setLocaleFromSession( $get_locale = Language\GetLocale::setLocaleFromSession(
SITE_LOCALE, SITE_LOCALE,
SITE_DOMAIN, SITE_DOMAIN,
@@ -86,10 +90,12 @@ print "[SESSION SET]: " . Support::printAr($get_locale) . "<br>";
// DEFAULT_DOMAIN // DEFAULT_DOMAIN
// DEFAULT_CHARSET (should be set from DEFAULT_LOCALE) // DEFAULT_CHARSET (should be set from DEFAULT_LOCALE)
// LOCALE_PATH // LOCALE_PATH
$_SESSION['DEFAULT_LOCALE'] = '00000#####'; $session->setMany([
$_SESSION['DEFAULT_CHARSET'] = ''; 'DEFAULT_LOCALE' => '00000#####',
$_SESSION['DEFAULT_DOMAIN'] = 'admin'; 'DEFAULT_CHARSET' => '',
$_SESSION['LOCALE_PATH'] = BASE . INCLUDES . LOCALE; 'DEFAULT_DOMAIN' => 'admin',
'LOCALE_PATH' => BASE . INCLUDES . LOCALE,
]);
$get_locale = Language\GetLocale::setLocaleFromSession( $get_locale = Language\GetLocale::setLocaleFromSession(
SITE_LOCALE, SITE_LOCALE,
SITE_DOMAIN, SITE_DOMAIN,

View File

@@ -205,8 +205,8 @@ print "HOST: " . HOST_NAME . " => DB HOST: " . DB_CONFIG_NAME . " => " . Support
print "DS is: " . DIRECTORY_SEPARATOR . "<br>"; print "DS is: " . DIRECTORY_SEPARATOR . "<br>";
print "SERVER HOST: " . $_SERVER['HTTP_HOST'] . "<br>"; print "SERVER HOST: " . $_SERVER['HTTP_HOST'] . "<br>";
print "ECUID: " . $_SESSION['ECUID'] . "<br>"; print "ECUID: " . $session->get('ECUID') . "<br>";
print "ECUUID: " . $_SESSION['ECUUID'] . "<br>"; print "ECUUID: " . $session->get('ECUUID') . "<br>";
print "</body></html>"; print "</body></html>";

View File

@@ -2534,13 +2534,12 @@ HTML;
{ {
if ( if (
$edit_access_id !== null && $edit_access_id !== null &&
isset($_SESSION['UNIT']) && is_array($this->session->get('UNIT')) &&
is_array($_SESSION['UNIT']) && !array_key_exists($edit_access_id, $this->session->get('UNIT'))
!array_key_exists($edit_access_id, $_SESSION['UNIT'])
) { ) {
$edit_access_id = null; $edit_access_id = null;
if (is_numeric($_SESSION['UNIT_DEFAULT'])) { if (is_numeric($this->session->get('UNIT_DEFAULT'))) {
$edit_access_id = (int)$_SESSION['UNIT_DEFAULT']; $edit_access_id = (int)$this->session->get('UNIT_DEFAULT');
} }
} }
return $edit_access_id; return $edit_access_id;

View File

@@ -294,11 +294,15 @@ class Session
* - unset session_name and session_id internal vars * - unset session_name and session_id internal vars
* - destroy session * - destroy session
* *
* @return bool * @return bool True on successful session destroy
*/ */
public function sessionDestroy(): bool public function sessionDestroy(): bool
{ {
$this->unsetAll(); // abort to false if not unsetable
if (!session_unset()) {
return false;
}
$this->clear();
if ( if (
ini_get('session.use_cookies') && ini_get('session.use_cookies') &&
!ini_get('session.use_strict_mode') !ini_get('session.use_strict_mode')
@@ -331,9 +335,12 @@ class Session
* *
* @return void * @return void
*/ */
public function unsetAll(): void public function clear(): void
{ {
$this->restartSession(); $this->restartSession();
if (!session_unset()) {
throw new \RuntimeException('[SESSION] Cannot unset session vars', 1);
}
if (!empty($_SESSION)) { if (!empty($_SESSION)) {
$_SESSION = []; $_SESSION = [];
} }

View File

@@ -2,7 +2,7 @@
/* /*
* sets a form token in the _SESSION variable * sets a form token in the _SESSION variable
* session must be started for this to work * session must be started and running for this to work
*/ */
declare(strict_types=1); declare(strict_types=1);