Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CO-2736_Fix_php_8.1_deprecation_errors #567

Draft
wants to merge 8 commits into
base: hotfix-4.3.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Console/Command/JobShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected function validateParameters($format, $args) {

// For attributes of type int, is the value an integer?
if($format[$attr]['type'] == 'int') {
if(!preg_match('/^[0-9.+-]*$/', $val)) {
if(!preg_match('/^[0-9.+-]*$/', $val ?? '')) {
throw new InvalidArgumentException("Value for " . $attr . " is not an integer"); // XXX I18n
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static function ($route) use ($rparams) {
// Perform the IP Address check
$ipregex = $this->Session->read('Auth.User.remote_ip');

if(!empty($ipregex) && !preg_match($ipregex, $_SERVER['REMOTE_ADDR'])) {
if(!empty($ipregex) && !preg_match($ipregex, $_SERVER['REMOTE_ADDR'] ?? '')) {
$this->Api->restResultHeader(401, "Unauthorized");
// We force an exit here to prevent any views from rendering, but also
// to prevent Cake from dumping the default layout
Expand Down
2 changes: 1 addition & 1 deletion app/Controller/CoLocalizationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function beforeRender() {
foreach(array_keys($cm_texts_orig[$cm_lang]) as $k) {
if(!is_array($cm_texts_orig[$cm_lang][$k])
// Also skip strings that can already be dynamically changed
&& !preg_match('/^em\./', $k)) {
&& !preg_match('/^em\./', $k ?? '')) {
$texts[$k] = $cm_texts_orig[$cm_lang][$k];
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/Controller/CoPetitionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ protected function execute_redirectOnConfirm($id) {
$found = false;

foreach(preg_split('/\R/', $allowList) as $u) {
if(preg_match($u, $targetUrl)) {
if(preg_match($u, $targetUrl ?? '')) {
$found = true;
break;
}
Expand Down Expand Up @@ -1874,7 +1874,7 @@ protected function execute_redirectOnFinalize($id) {
$found = false;

foreach(preg_split('/\R/', $allowList) as $u) {
if(preg_match($u, $targetUrl)) {
if(preg_match($u, $targetUrl ?? '')) {
$found = true;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions app/Controller/Component/ApiComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function checkRestPost($coId) {
}

foreach(array_keys($this->reqModel->validate) as $field) {
if(preg_match('/_id$/', $field)) {
if(preg_match('/_id$/', $field ?? '')) {
// Add additional validation rules for foreign keys. These checks are
// handled differently in v5, as application rules.

Expand Down Expand Up @@ -231,7 +231,7 @@ public function convertRestResponse($res) {
$rr[$m][Inflector::camelize($k)] = $r[$m][$k];
}
}
} elseif(preg_match('/Co[0-9]+PersonExtendedAttribute/', $m)) {
} elseif(preg_match('/Co[0-9]+PersonExtendedAttribute/', $m ?? '')) {
// Extended Attributes need to be handled specially. Currently, extended
// attributes are NOT inflected to keep them consistent with their
// database definitions.
Expand Down
12 changes: 6 additions & 6 deletions app/Model/AppModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,16 @@ protected function changesForModel($model, $newdata, $olddata, $coId, $attrs) {
continue;
}

if(preg_match('/.*_id$/', $attr)) {
if(preg_match('/.*_id$/', $attr ?? '')) {
// Foreign keys need to be handled specially. Start by figuring out the model.

if(preg_match('/.*_co_person_id$/', $attr)) {
if(preg_match('/.*_co_person_id$/', $attr ?? '')) {
// This is a foreign key to a CO Person (eg: sponsor_co_person)

// Chop off _co_person_id
$afield = substr($attr, 0, strlen($attr)-13);
$amodel = "CoPerson";
} elseif(preg_match('/.*_co_group_id$/', $attr)) {
} elseif(preg_match('/.*_co_group_id$/', $attr ?? '')) {
// This is a foreign key to a CO Group (eg: admins_co_group)

// Chop off _co_group_id
Expand Down Expand Up @@ -886,7 +886,7 @@ public function filterRelatedModels($data) {
$ret['hasOne'][$k] = $data[$k];
} elseif(isset($this->hasMany[$k])) {
$ret['hasMany'][$k] = $data[$k];
} elseif(preg_match('/Co[0-9]+PersonExtendedAttribute/', $k)) {
} elseif(preg_match('/Co[0-9]+PersonExtendedAttribute/', $k ?? '')) {
$ret['extended'][$k] = $data[$k];
}
}
Expand Down Expand Up @@ -1144,7 +1144,7 @@ public function findCoForRecord($id) {
if(!empty($srvr['Server']['co_id'])) {
return $srvr['Server']['co_id'];
}
} elseif(preg_match('/Co[0-9]+PersonExtendedAttribute/', $this->alias)) {
} elseif(preg_match('/Co[0-9]+PersonExtendedAttribute/', $this->alias ?? '')) {
// Extended attributes need to be handled specially, as usual, since there
// are no explicit validation rules. Find the CO via the CO Person Role ID.
// (ie: We don't trust the Model name in order to follow the general pattern
Expand Down Expand Up @@ -1802,7 +1802,7 @@ public function validateInput($a, $d) {
}

// We require at least one non-whitespace character (CO-1551)
if(!preg_match('/\S/', $v)) {
if(!preg_match('/\S/', $v ?? '')) {
return _txt('er.input.blank');
}

Expand Down
2 changes: 1 addition & 1 deletion app/Model/Behavior/ProvisionerBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ private function invokePlugins($model, $provisioningData, $action, $actorCoPerso

public function manualProvision(Model $model,
$coProvisioningTargetId=null,
$coPersonId,
$coPersonId = null,
$coGroupId=null,
$provisioningAction=ProvisioningActionEnum::CoPersonReprovisionRequested,
$coEmailListId=null,
Expand Down
4 changes: 2 additions & 2 deletions app/Model/CoEnrollmentAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive
// For date types, convert to an actual date

if(preg_match("/^[0-2][0-9]\-[0-9]{2}$/",
$efAttr['CoEnrollmentAttributeDefault'][0]['value'])) {
$efAttr['CoEnrollmentAttributeDefault'][0]['value'] ?? '')) {
// MM-DD indicates next MM-DD. Rather than muck around with PHP date parsing,
// we'll see if {THISYEAR}-MM-DD is before now(). If it is, we'll increment
// the year.
Expand All @@ -469,7 +469,7 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive

$attr['default'] = $curyear . "-" . $efAttr['CoEnrollmentAttributeDefault'][0]['value'];
} elseif(preg_match("/^\+[0-9]+$/",
$efAttr['CoEnrollmentAttributeDefault'][0]['value'])) {
$efAttr['CoEnrollmentAttributeDefault'][0]['value'] ?? '')) {
// Format +## indicates days from today

$attr['default'] = strftime("%F",
Expand Down
2 changes: 1 addition & 1 deletion app/Model/CoGroupOisMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function compare($value, $comparison, $pattern) {
return (strcasecmp($value, $pattern) !== 0);
break;
case ComparisonEnum::Regex:
return (preg_match($pattern, $value));
return (preg_match($pattern, $value ?? ''));
break;
default:
// Ignore anything unexpected
Expand Down
6 changes: 3 additions & 3 deletions app/Model/CoPetition.php
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ protected function flattenAttributes($enrollmentFlowID, $coPetitionID, $orgData,
);
}
}
} elseif(preg_match('/Co[0-9]+PersonExtendedAttribute/', $m)) {
} elseif(preg_match('/Co[0-9]+PersonExtendedAttribute/', $m ?? '')) {
// Extended Attribute

foreach(array_keys($coRoleData[$m]) as $a) {
Expand Down Expand Up @@ -3756,15 +3756,15 @@ private function validateRelated($primaryModel, $requestData, $validatedData, $e
}
}

if(preg_match('/.*CoPersonRole$/', $primaryModel)) {
if(preg_match('/.*CoPersonRole$/', $primaryModel ?? '')) {
// Handle Extended Attributes specially, as usual. To find them, we have to walk
// the configured attributes.

foreach($efAttrs as $efAttr) {
$m = explode('.', $efAttr['model'], 3);

if(count($m) == 2
&& preg_match('/Co[0-9]+PersonExtendedAttribute/', $m[1])) {
&& preg_match('/Co[0-9]+PersonExtendedAttribute/', $m[1] ?? '')) {
$model = $m[1];

// First, dynamically bind the extended attribute to the model if we haven't already.
Expand Down
2 changes: 1 addition & 1 deletion app/Vendor/adodb5/adodb-csvlib.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ function _rs2serialize(&$rs,$conn=false,$sql='')

$savefetch = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode;
$class = $rs->connection->arrayClass;
/** @var ADORecordSet $rs2 */
$rs2 = new $class(ADORecordSet::DUMMY_QUERY_ID);
$rs2->timeCreated = $rs->timeCreated; # memcache fix
$rs2->sql = $rs->sql;
$rs2->oldProvider = $rs->dataProvider;
$rs2->InitArrayFields($rows,$flds);
$rs2->fetchMode = $savefetch;
return $line.serialize($rs2);
Expand Down
6 changes: 6 additions & 0 deletions app/Vendor/adodb5/adodb-datadict.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ class ADODB_DataDict {
*/
public $blobAllowsDefaultValue;


/**
* @var string String to use to quote identifiers and names
*/
public $quote;

function getCommentSQL($table,$col)
{
return false;
Expand Down
9 changes: 8 additions & 1 deletion app/Vendor/adodb5/adodb-errorhandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@
*/
function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)
{
if (error_reporting() == 0) return; // obey @ protocol
// Do not throw if errors are suppressed by @ operator
// error_reporting() value for suppressed errors changed in PHP 8.0.0
$suppressed = version_compare(PHP_VERSION, '8.0.0', '<')
? 0
: E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE;
if (error_reporting() == $suppressed) {
return;
}
switch($fn) {
case 'EXECUTE':
$sql = $p1;
Expand Down
10 changes: 9 additions & 1 deletion app/Vendor/adodb5/adodb-errorpear.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ function ADODB_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
{
global $ADODB_Last_PEAR_Error;

if (error_reporting() == 0) return; // obey @ protocol
// Do not throw if errors are suppressed by @ operator
// error_reporting() value for suppressed errors changed in PHP 8.0.0
$suppressed = version_compare(PHP_VERSION, '8.0.0', '<')
? 0
: E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE;
if (error_reporting() == $suppressed) {
return;
}

switch($fn) {
case 'EXECUTE':
$sql = $p1;
Expand Down
19 changes: 15 additions & 4 deletions app/Vendor/adodb5/adodb-exceptions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class ADODB_Exception extends Exception {
var $host = '';
var $database = '';

/** @var string A message text. */
var $msg = '';

function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
{
switch($fn) {
Expand Down Expand Up @@ -78,10 +81,18 @@ function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)

function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
{
global $ADODB_EXCEPTION;
global $ADODB_EXCEPTION;

// Do not throw if errors are suppressed by @ operator
// error_reporting() value for suppressed errors changed in PHP 8.0.0
$suppressed = version_compare(PHP_VERSION, '8.0.0', '<')
? 0
: E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE;
if (error_reporting() == $suppressed) {
return;
}

$errfn = is_string($ADODB_EXCEPTION) ? $ADODB_EXCEPTION : 'ADODB_EXCEPTION';

if (error_reporting() == 0) return; // obey @ protocol
if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION;
else $errfn = 'ADODB_EXCEPTION';
throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection);
}
60 changes: 42 additions & 18 deletions app/Vendor/adodb5/adodb-lib.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,32 +508,38 @@ function _adodb_getcount($zthis, $sql,$inputarr=false,$secs2cache=0)
return $qryRecs;
}

/*
Code originally from "Cornel G" <[email protected]>

This code might not work with SQL that has UNION in it

Also if you are using CachePageExecute(), there is a strong possibility that
data will get out of synch. use CachePageExecute() only with tables that
rarely change.
*/
function _adodb_pageexecute_all_rows($zthis, $sql, $nrows, $page,
$inputarr=false, $secs2cache=0)
/**
* Execute query with pagination including record count.
*
* This code might not work with SQL that has UNION in it.
* Also if you are using cachePageExecute(), there is a strong possibility that
* data will get out of sync. cachePageExecute() should only be used with
* tables that rarely change.
*
* @param ADOConnection $zthis Connection
* @param string $sql Query to execute
* @param int $nrows Number of rows per page
* @param int $page Page number to retrieve (1-based)
* @param array $inputarr Array of bind variables
* @param int $secs2cache Time-to-live of the cache (in seconds), 0 to force query execution
*
* @return ADORecordSet|bool
*
* @author Cornel G <[email protected]>
*/
function _adodb_pageexecute_all_rows($zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0)
{
$atfirstpage = false;
$atlastpage = false;

// If an invalid nrows is supplied,
// we assume a default value of 10 rows per page
// If an invalid nrows is supplied, assume a default value of 10 rows per page
if (!isset($nrows) || $nrows <= 0) $nrows = 10;

$qryRecs = _adodb_getcount($zthis,$sql,$inputarr,$secs2cache);
$lastpageno = (int) ceil($qryRecs / $nrows);
$zthis->_maxRecordCount = $qryRecs;

// ***** Here we check whether $page is the last page or
// whether we are trying to retrieve
// a page number greater than the last page number.
// Check whether $page is the last page or if we are trying to retrieve
// a page number greater than the last one.
if ($page >= $lastpageno) {
$page = $lastpageno;
$atlastpage = true;
Expand Down Expand Up @@ -565,7 +571,25 @@ function _adodb_pageexecute_all_rows($zthis, $sql, $nrows, $page,
return $rsreturn;
}

// Iván Oliva version
/**
* Execute query with pagination without last page information.
*
* This code might not work with SQL that has UNION in it.
* Also if you are using cachePageExecute(), there is a strong possibility that
* data will get out of sync. cachePageExecute() should only be used with
* tables that rarely change.
*
* @param ADOConnection $zthis Connection
* @param string $sql Query to execute
* @param int $nrows Number of rows per page
* @param int $page Page number to retrieve (1-based)
* @param array $inputarr Array of bind variables
* @param int $secs2cache Time-to-live of the cache (in seconds), 0 to force query execution
*
* @return ADORecordSet|bool
*
* @author Iván Oliva
*/
function _adodb_pageexecute_no_last_page($zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0)
{
$atfirstpage = false;
Expand Down
12 changes: 6 additions & 6 deletions app/Vendor/adodb5/adodb-loadbalancer.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ class ADOdbLoadBalancer
/**
* @var bool|array All connections to each database.
*/
protected $connections = false;
protected $connections = [];

/**
* @var bool|array Just connections to the write capable database.
*/
protected $connections_write = false;
protected $connections_write = [];

/**
* @var bool|array Just connections to the readonly database.
*/
protected $connections_readonly = false;
protected $connections_readonly = [];

/**
* @var array Counts of all connections and their types.
Expand All @@ -73,12 +73,12 @@ class ADOdbLoadBalancer
/**
* @var bool Session variables that must be maintained across all connections, ie: SET TIME ZONE.
*/
protected $session_variables = false;
protected $session_variables = [];

/**
* @var bool Called immediately after connecting to any DB.
*/
protected $user_defined_session_init_sql = false;
protected $user_defined_session_init_sql = [];


/**
Expand Down Expand Up @@ -403,7 +403,7 @@ public function setSessionVariable($name, $value, $execute_immediately = true)
*/
private function executeSessionVariables($adodb_obj = false)
{
if (is_array($this->session_variables)) {
if (is_array($this->session_variables) && count($this->session_variables) > 0) {
$sql = '';
foreach ($this->session_variables as $name => $value) {
// $sql .= 'SET SESSION '. $name .' '. $value;
Expand Down
Loading