From 7a430c39df616625f8c84c99b257f369f1043878 Mon Sep 17 00:00:00 2001 From: Jack5 <32806494+jack5github@users.noreply.github.com> Date: Sat, 9 Dec 2023 06:39:54 +1100 Subject: [PATCH] fix: Uninitialised zip and missing file size error in Native Data Loads (#7081) * Fix zip and missing error in Native Data Loads * Fix PHPCBF violation --- interface/super/load_codes.php | 42 ++++++++++++++-------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/interface/super/load_codes.php b/interface/super/load_codes.php index d4c743d7e80..9bea7da6e07 100644 --- a/interface/super/load_codes.php +++ b/interface/super/load_codes.php @@ -14,8 +14,8 @@ set_time_limit(0); -require_once('../globals.php'); -require_once($GLOBALS['fileroot'] . '/custom/code_types.inc.php'); +require_once '../globals.php'; +require_once $GLOBALS['fileroot'] . '/custom/code_types.inc.php'; use OpenEMR\Common\Acl\AclMain; use OpenEMR\Common\Csrf\CsrfUtils; @@ -124,27 +124,16 @@ } $seen_codes[$code] = 1; - ++$inscount; if (!$form_replace) { - $tmp = sqlQuery( - "SELECT id FROM codes WHERE code_type = ? AND code = ? LIMIT 1", - array($code_type_id, $code) - ); - if ($tmp['id']) { - sqlStatementNoLog( - "UPDATE codes SET code_text = ? WHERE code_type = ? AND code = ?", - array($a[14], $code_type_id, $code) - ); - ++$repcount; - continue; + $tmp = sqlQuery("SELECT id FROM codes WHERE code_type = ? AND code = ? LIMIT 1", array($code_type_id, $code)); + if (!empty($tmp)) { + sqlStatementNoLog("UPDATE codes SET code_text = ? WHERE code_type = ? AND code = ?", array($a[14], $code_type_id, $code)); + ++$repcount; + continue; } } - sqlStatementNoLog( - "INSERT INTO codes SET code_type = ?, code = ?, code_text = ?, " . - "fee = 0, units = 0", - array($code_type_id, $code, $a[14]) - ); + sqlStatementNoLog("INSERT INTO codes SET code_type = ?, code = ?, code_text = ?, fee = 0, units = 0", array($code_type_id, $code, $a[14])); ++$inscount; } @@ -156,13 +145,16 @@ sqlStatementNoLog("SET autocommit=1"); fclose($eres); - $zipin->close(); - } + // Cannot close ZIP object if not initialised, catch and do nothing + try { + $zipin->close(); + } catch (ValueError $e) { + } - echo "
" . - xlt('LOAD SUCCESSFUL. Codes inserted') . ": " . text($inscount) . ", " . - xlt('replaced') . ": " . text($repcount) . - "
\n"; + echo "" . xlt('LOAD SUCCESSFUL. Codes inserted') . ": " . text($inscount) . ", " . xlt('replaced') . ": " . text($repcount) . "
\n"; + } else { + echo "" . xlt('ERROR. Could not open') . ". " . (php_ini_loaded_file() ?? "Server") . " upload_max_filesize: " . xlt('Your file is too large') . ". " . xlt('Set To') . " ≥ post_max_size."; + } } ?>