Merge branch 'MDL-73520-M311_replace-deprecated-php_errormsg-with-error_get_last' of https://github.com/ziegenberg/moodle into MOODLE_311_STABLE

This commit is contained in:
Jun Pataleta 2022-03-10 12:28:20 +08:00
commit e40b7928c9
5 changed files with 29 additions and 17 deletions

View file

@ -134,11 +134,19 @@ function sendOAuthParamsPOST($method, $endpoint, $oauth_consumer_key, $oauth_con
$ctx = stream_context_create($params); $ctx = stream_context_create($params);
$fp = @fopen($endpoint, 'rb', false, $ctx); $fp = @fopen($endpoint, 'rb', false, $ctx);
if (!$fp) { if (!$fp) {
throw new \Exception("Problem with $endpoint, $php_errormsg"); $message = "(No error message provided.)";
if ($error = error_get_last()) {
$message = $error["message"];
}
throw new \Exception("Problem with $endpoint, $message");
} }
$response = @stream_get_contents($fp); $response = @stream_get_contents($fp);
if ($response === false) { if ($response === false) {
throw new \Exception("Problem reading data from $endpoint, $php_errormsg"); $message = "(No error message provided.)";
if ($error = error_get_last()) {
$message = $error["message"];
}
throw new \Exception("Problem reading data from $endpoint, $message");
} }
return $response; return $response;
} }

View file

@ -208,11 +208,19 @@ function do_post_request($url, $data, $optional_headers = null)
$fp = @fopen($url, 'rb', false, $ctx); $fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) { if (!$fp) {
echo @stream_get_contents($fp); echo @stream_get_contents($fp);
throw new Exception("Problem with $url, $php_errormsg"); $message = "(No error message provided.)";
if ($error = error_get_last()) {
$message = $error["message"];
}
throw new Exception("Problem with $url, $message");
} }
$response = @stream_get_contents($fp); $response = @stream_get_contents($fp);
if ($response === false) { if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg"); $message = "(No error message provided.)";
if ($error = error_get_last()) {
$message = $error["message"];
}
throw new Exception("Problem reading data from $url, $message");
} }
return $response; return $response;
} }

View file

@ -5,3 +5,4 @@ In future releases we should look into using a supported library.
2022-01-05 - MDL-73502 - Removed get_magic_quotes_gpc() use, was returning false since ages ago. 2022-01-05 - MDL-73502 - Removed get_magic_quotes_gpc() use, was returning false since ages ago.
2022-01-20 - MDL-73523 - Conditional openssl_free_key() use, deprecated by PHP 8.0 2022-01-20 - MDL-73523 - Conditional openssl_free_key() use, deprecated by PHP 8.0
2022-03-05 - MDL-73520 - replace deprecated php_errormsg with error_get_last(), deprecated by PHP 8.0

View file

@ -109,7 +109,6 @@ class ADODB_db2 extends ADOConnection {
private function doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasename, $persistent=false) private function doDB2Connect($argDSN, $argUsername, $argPassword, $argDatabasename, $persistent=false)
{ {
global $php_errormsg;
if (!function_exists('db2_connect')) { if (!function_exists('db2_connect')) {
ADOConnection::outp("DB2 extension not installed."); ADOConnection::outp("DB2 extension not installed.");
@ -181,8 +180,6 @@ class ADODB_db2 extends ADOConnection {
null, null,
$db2Options); $db2Options);
$php_errormsg = '';
$this->_errorMsg = @db2_conn_errormsg(); $this->_errorMsg = @db2_conn_errormsg();
if ($this->_connectionID && $this->connectStmt) if ($this->_connectionID && $this->connectStmt)
@ -205,8 +202,6 @@ class ADODB_db2 extends ADOConnection {
private function unpackParameters($argDSN, $argUsername, $argPassword, $argDatabasename) private function unpackParameters($argDSN, $argUsername, $argPassword, $argDatabasename)
{ {
global $php_errormsg;
$connectionParameters = array('dsn'=>'', $connectionParameters = array('dsn'=>'',
'uid'=>'', 'uid'=>'',
'pwd'=>'', 'pwd'=>'',
@ -256,7 +251,6 @@ class ADODB_db2 extends ADOConnection {
$errorMessage = 'Supply uncatalogued connection parameters '; $errorMessage = 'Supply uncatalogued connection parameters ';
$errorMessage.= 'in either the database or DSN arguments, '; $errorMessage.= 'in either the database or DSN arguments, ';
$errorMessage.= 'but not both'; $errorMessage.= 'but not both';
$php_errormsg = $errorMessage;
if ($this->debug) if ($this->debug)
ADOConnection::outp($errorMessage); ADOConnection::outp($errorMessage);
return null; return null;
@ -281,7 +275,6 @@ class ADODB_db2 extends ADOConnection {
{ {
$errorMessage = 'For uncatalogued connections, provide '; $errorMessage = 'For uncatalogued connections, provide ';
$errorMessage.= 'both UID and PWD in the connection string'; $errorMessage.= 'both UID and PWD in the connection string';
$php_errormsg = $errorMessage;
if ($this->debug) if ($this->debug)
ADOConnection::outp($errorMessage); ADOConnection::outp($errorMessage);
return null; return null;
@ -316,7 +309,6 @@ class ADODB_db2 extends ADOConnection {
{ {
$errorMessage = 'Uncatalogued connection parameters '; $errorMessage = 'Uncatalogued connection parameters ';
$errorMessage.= 'must contain a database= argument'; $errorMessage.= 'must contain a database= argument';
$php_errormsg = $errorMessage;
if ($this->debug) if ($this->debug)
ADOConnection::outp($errorMessage); ADOConnection::outp($errorMessage);
return null; return null;
@ -1579,10 +1571,6 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2
function _query(&$sql,$inputarr=false) function _query(&$sql,$inputarr=false)
{ {
GLOBAL $php_errormsg;
if (isset($php_errormsg))
$php_errormsg = '';
$this->_error = ''; $this->_error = '';
$db2Options = array(); $db2Options = array();
@ -1621,7 +1609,12 @@ See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/db2/htm/db2
if ($stmtid == false) if ($stmtid == false)
{ {
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; $this->_errorMsg = @db2_stmt_errormsg();
$this->_errorCode = @db2_stmt_error();
if ($this->debug)
ADOConnection::outp($this->_errorMsg);
return false; return false;
} }
} }

View file

@ -26,3 +26,5 @@ Added:
Our changes (to be checked on next update if they are already applied upstream):: Our changes (to be checked on next update if they are already applied upstream)::
* https://github.com/ADOdb/ADOdb/issues/711 * https://github.com/ADOdb/ADOdb/issues/711
Our changes (to be checked on next update if they are already applied upstream):
* https://github.com/ADOdb/ADOdb/issues/791