Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Bug Reports » Cannot delete audit data
Cannot delete audit data [message #7749] Tue, 05 July 2022 18:17 Go to next message
divico is currently offline  divico
Messages: 16
Registered: August 2008
Junior Member
Greetings,
Potentially this issue exists for some time in my environment. For whatever reasons I cannot delete the audit data. Not a general problem of running batch jobs, I have a few which I use regularly. Also no issues anywhere else in the framework. The issue occurs in versions 2.19 as well as 2.22.
Stack trace (taken from version 2.19) says:
1: array =
file: string = /var/www/html/radicore/includes/include.session.inc
line: integer = 985
function: string = trigger_error
args: array =
0: string = unserialize(): Error at offset 0 of 50214 bytes
1: integer = 256
2: array =
file: string = /var/www/html/radicore/includes/std.delete3.inc
line: integer = 22
function: string = initSession
args: array =
3: array =
file: string = /var/www/html/radicore/audit/audit_ssn(batch)delete.php
line: integer = 19
args: array =
0: string = /var/www/html/radicore/includes/std.delete3.inc
function: string = require

This is the corresponding code block from include.session.inc:

// session could not be created, so find out why
$dbobject = RDCsingleton::getInstance('php_session');
$string = $dbobject->read(session_id());
$_SESSION = unserialize(trim($string), array());
if (!is_array($_SESSION)) {
trigger_error($GLOBALS['php_errormsg'], E_USER_ERROR);
} // if

Any instant idea, why this one is failing?

Kind regards, Divico
Re: Cannot delete audit data [message #7750 is a reply to message #7749] Wed, 06 July 2022 05:45 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2369
Registered: April 2006
Location: Surrey, UK
Senior Member
I have tried this task on my system and I cannot reproduce this error.

That stack trace points to line #985 in file includes/include.session.inc which is the call to session_start() BEFORE the lines you quoted. This should mean that it would fail for *ALL* calls to session_start() and not just the one within this particular task.

After reading the session data from the database PHP automatically calls unserialize() to turn it from a string into an array, but it appears to be failing for some unknown reason. Can you provide a copy of the first 80 bytes of that session data record?


Re: Cannot delete audit data [message #7751 is a reply to message #7750] Sat, 09 July 2022 10:52 Go to previous messageGo to next message
divico is currently offline  divico
Messages: 16
Registered: August 2008
Junior Member
Thanks for trying to recreate. Unfortuantely I figured out that I have issues with batches in general in my new environment. I am migrating from PHP 7.4 to PHP 8.1.7. Resolving this is of a higher priority for me.

1.) Refering to https://www.tonymarston.net/php-mysql/infrastructure-faq.htm l item #56: "In the radicore directory create file batch.ini from batch.ini.default"

Placing the batch.ini in the radicore directory creates the following exception in my environment:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function errorHandlerBatch(), 4 passed and exactly 5 expected in /var/www/html/radicore/mysubsys/std.batch.inc on line 343

ArgumentCountError: Too few arguments to function errorHandlerBatch(), 4 passed and exactly 5 expected in /var/www/html/radicore/mysubsys/std.batch.inc on line 343

Call Stack:
0.0001 392976 1. {main}() /var/www/html/radicore/mysubsys/mybatch(batch).php:0
0.0005 443864 2. batchInit($batchfile = '/var/www/html/radicore/mysubsys/mybatch(batch).php') /var/www/html/radicore/mysubsys/mybatch(batch).php:12
0.0005 444768 3. parse_ini_file($filename = 'batch.ini.default') /var/www/html/radicore/mysubsys/std.batch.inc:32
0.0006 445144 4. errorHandlerBatch($errno = 2, $errstr = 'parse_ini_file(batch.ini.default): Failed to open stream: No such file or directory', $errfile = '/var/www/html/radicore/mysubsys/std.batch.inc', $errline = 32, $errcontext = ???) /var/www/html/radicore/mysubsys/std.batch.inc:32

Looks like radicore is not happy with my batch.ini in the radicore directory and tries to open batch.ini.default. Can you confirm that the radicore directory is the right directory, or adjust the documentation accordingly?

2.) Moving the batch.ini to the subsys-directory resolves the issue above. Still my batch fails with the same exception but issued from an another line of code:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function errorHandlerBatch(), 4 passed and exactly 5 expected in /var/www/html/radicore/mysubsys/std.batch.inc on line 343

ArgumentCountError: Too few arguments to function errorHandlerBatch(), 4 passed and exactly 5 expected in /var/www/html/radicore/mysubsys/std.batch.inc on line 343

Call Stack:
0.0001 392976 1. {main}() /var/www/html/radicore/mysubsys/mybatch(batch).php:0
0.0005 443864 2. batchInit($batchfile = '/var/www/html/radicore/mysubsys/mybatch(batch).php') /var/www/html/radicore/mysubsys/mybatch(batch).php:12
0.0162 477656 3. require_once('/var/www/html/radicore/includes/include.genera l.inc') /var/www/html/radicore/mysubsys/std.batch.inc:158
0.0162 477656 4. fopen($filename = 'config.local.inc', $mode = 'r', $use_include_path = TRUE) /var/www/html/radicore/includes/include.general.inc:19
0.0163 478056 5. errorHandlerBatch($errno = 2, $errstr = 'fopen(config.local.inc): Failed to open stream: No such file or directory', $errfile = '/var/www/html/radicore/includes/include.general.inc', $errline = 19, $errcontext = ???) /var/www/html/radicore/includes/include.general.inc:19

I don't have a config.local.inc and didn't find any reference to it in the documentation. Changing the signature of the errorhandler function to "errorHandlerBatch ($errno, $errstr, $errfile, $errline, $errcontext = null)" temporarily resolved the issue. But you may want to check if all arguments are passed in the right order in all circumstances when calling the errorhandler.

3.) Still my batch does not run. Now getting:

Deprecated: Automatic conversion of false to array is deprecated in /var/www/html/radicore/includes/language_detection.inc on line 279

Call Stack:
0.0001 392976 1. {main}() /var/www/html/radicore/mysubsys/mybatch(batch).php:0
0.0005 443864 2. batchInit($batchfile = '/var/www/html/radicore/mysubsys/mybatch(batch).php') /var/www/html/radicore/mysubsys/mybatch(batch).php:12
0.0533 4015656 3. initSession($save_session_data = ???, $argv = ???) /var/www/html/radicore/mysubsys/std.batch.inc:173
0.0662 4681272 4. trigger_error($message = 'strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated', $error_level = 256) /var/www/html/radicore/includes/include.session.inc:993
0.0662 4681600 5. errorHandler($errno = 256, $errstr = 'strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated', $errfile = '/var/www/html/radicore/includes/include.session.inc', $errline = 993) /var/www/html/radicore/includes/include.session.inc:993
0.0662 4684712 6. getLanguageText($id = 'sys0063', $arg1 = 'strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated', $arg2 = ???, $arg3 = ???, $arg4 = ???, $arg5 = ???) /var/www/html/radicore/includes/error.inc:185
0.0662 4685424 7. getLanguageFile($filename = 'sys.language_text.inc', $directory = '/var/www/html/radicore/menu/text', $ignore_if_not_found = TRUE) /var/www/html/radicore/includes/include.library.inc:4160
0.0662 4685424 8. getBrowserLanguage($directory = '/var/www/html/radicore/menu/text') /var/www/html/radicore/includes/include.library.inc:4068

This is where I am at now.

Can you have a look at those issues?
Re: Cannot delete audit data [message #7752 is a reply to message #7751] Sun, 10 July 2022 05:37 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2369
Registered: April 2006
Location: Surrey, UK
Senior Member
The correct location for script batch.ini is in the radicore <root> directory.

The version of errorHandlerBatch() in the RADICORE download already contains the correct five arguments. The version which you are using must be incorrect.

The file config.local.inc is entirely optional so it is not an error if it is not there. If it exists it is used instead of config.inc.

The error reported at includes/language_detection.inc on line 279 is wrong as that line does not try to convert FALSE to array. On my system the command is:
$_SESSION['user_language_array'] = get_user_languages($_SERVER["HTTP_ACCEPT_LANGUAGE"]);

The error reported at /includes/include.session.inc line 993 is wrong as that command does not contain a call to 'strtoupper()'. On my system the command is:
trigger_error($GLOBALS['php_errormsg'], E_USER_ERROR);
In case the variable $GLOBALS['php_errormsg'] is empty I have amended the code to use a default value. See the attached file.


Re: Cannot delete audit data [message #7753 is a reply to message #7752] Wed, 13 July 2022 18:35 Go to previous messageGo to next message
divico is currently offline  divico
Messages: 16
Registered: August 2008
Junior Member
Thanks for your response. I don't give up. I use the latest version 2.22.

1.) The correct location for script batch.ini is in the radicore <root> directory.

I inserted the following echo statements into the code:

function batchInit ($batchfile)
// initialisation for a batch process
{
global $stdout, $stdouth, $argv;

error_reporting(-1); // report everything
ini_set('display_errors', true); // display everything

$result = ini_set('max_execution_time', 0); // no time limit

set_error_handler('errorHandlerBatch');

echo $batchfile . PHP_EOL;
// get fully-qualified name of current file
$curr_file = str_replace("\\", "/", $batchfile);
echo $curr_file . PHP_EOL;
$curr_dir = dirname($curr_file); // extract directory
echo $curr_dir . PHP_EOL;
chdir($curr_dir); // set current working directory to this

// retrieve variables from file
if (file_exists('batch.ini')) {
echo "Use custom file" . PHP_EOL;
$ini_array = parse_ini_file('batch.ini'); // use custom file
} else {
echo "Use default file" . PHP_EOL;
$ini_array = parse_ini_file('batch.ini.default'); // use default file
} // if

This results in:
[$batchfile = ]/var/www/html/radicore/mysubsys/mybatch(batch).php
[$curr_file = ]/var/www/html/radicore/mysubsys/mybatch(batch).php
[$curr_dir = ]/var/www/html/radicore/mysubsys
Use default file

file_exists("batch.ini") looks in the subsys directory ("/var/www/html/radicore/mysubsys") and not in the root directory. It doesn't find it there, hence batch.ini.default is used. If the documentation is correct $curr_dir must be changed to point to the radicore root directory ("/var/www/html/radicore") in my case.

2.) The version of errorHandlerBatch() in the RADICORE download already contains the correct five arguments. The version which you are using must be incorrect.

I have the correct version with the correct signature. I found this in the documentation:

See https://www.php.net/manual/en/function.set-error-handler.php

errcontext:
"Warning
This parameter has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. If your function defines this parameter without a default, an error of "too few arguments" will be raised when it is called."

I think this is the issue. As a matter of fact the errcontext may be removed or at least a default value has to be defined, as suggested by myself.

3.) The error reported at includes/language_detection.inc on line 279 is wrong as that line does not try to convert FALSE to array. On my system the command is:

$_SESSION['user_language_array'] = get_user_languages($_SERVER["HTTP_ACCEPT_LANGUAGE"]);

I have the same statement on this line. I think the issue is that $_SESSION is not defined, resp. is of type bool.

I changed the code as follows:

$a = get_user_languages($_SERVER["HTTP_ACCEPT_LANGUAGE"]);
echo "About to print the result of get_user_languages" . PHP_EOL;
echo gettype($a) . PHP_EOL;
var_dump($a);
echo "After print of the result of get_user_languages" . PHP_EOL;
//$_SESSION['user_language_array'] = get_user_languages($_SERVER["HTTP_ACCEPT_LANGUAGE"]);
echo "About to print the result of SESSION" . PHP_EOL;
echo gettype($_SESSION) . PHP_EOL;
var_dump($_SESSION);
echo "After print of the result of SESSION" . PHP_EOL;
$_SESSION = array();
$_SESSION['user_language_array'] = $a;

Results in:

About to print the result of get_user_languages
array
/var/www/html/radicore/includes/language_detection.inc:282:
array(1) {
[0] =>
array(4) {
[0] =>
string(5) "en-gb"
[1] =>
string(2) "en"
[2] =>
string(32) "English (United Kingdom) [en_GB]"
[3] =>
string(7) "English"
}
}
After print of the result of get_user_languages
About to print the result of SESSION
boolean
/var/www/html/radicore/includes/language_detection.inc:287:
bool(false)
After print of the result of SESSION

$_SESSION is of type bool. Therefore the error is raised. Potentially this change in PHP 8.1 applies here:
https://wiki.php.net/rfc/autovivification_false

Declaring $_SESSION as an array removes the error on my system.

4.) The error reported at /includes/include.session.inc line 993 is wrong as that command does not contain a call to 'strtoupper()'. On my system the command is:

trigger_error($GLOBALS['php_errormsg'], E_USER_ERROR);

I have the same code on this line and currently no idea why I receive the error. But I get what I get.

btw: I cannot download your zip file, receiving

Access to forum.radicore.org was denied
You don't have authorization to view this page.
HTTP ERROR 403

when I click on it.

I think I have a better understanding what happens re my issues 1-3. Would it be possible to consider my suggestions? I'm sure there must be a reasonable explanation for issue no 4 as well. Maybe something comes to your mind.
Re: Cannot delete audit data [message #7754 is a reply to message #7753] Thu, 14 July 2022 05:50 Go to previous message
AJM is currently offline  AJM
Messages: 2369
Registered: April 2006
Location: Surrey, UK
Senior Member
It would appear that you are running PHP 8.1 whereas I have only tested it against 8.0. I cannot use 8.1 yet as my IDE does not yet support it. You can get rid of that notice with the errorHandlerBatch() function inside file include.batch.inc simply by removing the $errcontext argument, just as it has already been removed from the errorHandler() function inside file error.inc.

The documentation states that you should create your own version of file batch.ini from batch.ini.default. If you do not then the contents of batch.ini.default will be used. The code inside file include.batch.inc uses the following code:
if (file_exists('../batch.ini')) {
    $ini_array = parse_ini_file('../batch.ini');           // use custom file
    $ini_file  = '../batch.ini';
} elseif (file_exists('../batch.ini.default')) {
    $ini_array = parse_ini_file('../batch.ini.default');   // use default file
} // if
This means that it looks in the directory which is one level HIGHER than the current subsystem directory.

I cannot understand the error being reported with language_detection.inc as there is no call to strtoupper() on that line, or anywhere near it.

You are getting the 403 error when you try to download that file because my forum software accidentally adds an '&' character at the end of the URL. Just remove this character and try again.

For some reason the call to session_start() is failing. The call to ->read(session_id()) is supposed to return either an empty string or a non-empty string. If you look in the read() method inside file audit/classes/php_session.class.inc you will see the exact code. Can you debug this method to see what is actually happening?


Previous Topic: Frequent file juggling woes
Next Topic: PHP 8 - ListViewPrintAfter()
Goto Forum:
  


Current Time: Mon Nov 25 09:22:33 EST 2024

Total time taken to generate the page: 0.01197 seconds