Indicia-Team / warehouse

GNU General Public License v3.0
5 stars 3 forks source link

Update code for PHP 8.1 #431

Closed JimBacon closed 1 year ago

JimBacon commented 2 years ago

Running continuous integration tests with PHP 8.1 results in failure. Some faults originating in Kohana code were noted. All support for PHP 8.0 ends on 26 Nov, 2023

Note that Kohana 3 (we are still on v2) lives on and is being maintained. https://github.com/koseven/koseven

BirenRathod commented 2 years ago

@JimBacon & @johnvanbreda I have upgraded all warehouse to PHP version of 8.0.19.

Info : also, upgraded testwarehouse from 6.12.20 to 8.0 & devwarehouse from 7.1 to 8.0.

BirenRathod commented 2 years ago

@johnvanbreda I have created new site for PHP 8.1 and restored backup from live site to this site. I found below errors. I think that is the start point to resolve errors or warnings for PHP 8.1. The iRecord development site URL is -> https://dev-brc-test-irecord.pantheonsite.io

  1. Deprecated: Optional parameter $parentTitle declared before required parameter $request is implicitly treated as a required parameter in /code/web/modules/custom/iform/src/Controller/IformController.php on line 144
  2. Deprecated function: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in helper_base::apply_replacements_to_template() (line 2887 of /code/web/modules/custom/iform/client_helpers/helper_base.php)
  3. Deprecated function: strcasecmp(): Passing null to parameter #2 ($string2) of type string is deprecated in get_attribute_html() (line 58 of /code/web/modules/custom/iform/client_helpers/prebuilt_forms/includes/form_generation.php)
  4. Deprecated function: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in iform_user_ui_options_preprocess_iform() (line 113 of /code/web/modules/custom/iform/modules/iform_user_ui_options/iform_user_ui_options.module)

There may be more which I will add in due course.

BirenRathod commented 2 years ago

Some more ....

  1. Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in helper_base::mergeParamsIntoTemplate() (line 1882 of /code/web/modules/custom/iform/client_helpers/helper_base.php)
jendrage commented 1 year ago

PHP 8.1 /index.php/setup_check/config_email_save

Error on screen: Email configuration test failed - Passing null to parameter #2 ($subject) of type string is deprecated In log: --- error: #8192: Error converted to exception. preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated at line 384 in file ***/system/vendor/swift/Swift/Message/Encoder.php

JimBacon commented 1 year ago

Hi @jendrage, does the log include the call stack? If so, could you post it. Thanks.

johnvanbreda commented 1 year ago

Looking at the code, is it possible that either of the the following box were not completed on the email test form?

jendrage commented 1 year ago

Hi Jim, no sorry just this:

2023-10-31 09:40:47 +00:00 --- error: #8192: Error converted to exception. preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated at line 384 in file ***/system/vendor/swift/Swift/Message/Encoder.php 2023-10-31 09:40:47 +00:00 --- error: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated I switched back to PHP 7.4 temparility to save the email conifg and that worked fine, test email sent and all good.

Just tested again with PHP 8.1, to double check, all boxes filled in correctly and same error.

Not urgent as I have the email config saved and working, just logging as a PHP 8.1 error.

johnvanbreda commented 1 year ago

In order to get richer logging, the log_threshold setting in application/config/config.php can be set to 4 - then it will include a call stack. I'm not sure if this is too late as you are now set up @jendrage so this may have to wait till Jim or I get a chance to do a test warehouse install.

jendrage commented 1 year ago

Here you go:

2023-10-31 12:46:49 +00:00 --- debug: Global GET, POST and COOKIE data sanitized 2023-10-31 12:46:49 +00:00 --- debug: Session Cookie Driver Initialized 2023-10-31 12:46:49 +00:00 --- debug: Session Library initialized 2023-10-31 12:46:49 +00:00 --- error: #8192: Error converted to exception. preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated at line 384 in file /public_html/system/vendor/swift/Swift/Message/Encoder.php 2023-10-31 12:46:49 +00:00 --- debug: Stack trace: Unknown file - line Unknown - indicia_error_handler /public_html/system/vendor/swift/Swift/Message/Encoder.php - line 384 - preg_match /public_html/system/vendor/swift/Swift/Message/Headers.php - line 286 - isUTF8 /public_html/system/vendor/swift/Swift/Message.php - line 385 - setAttribute /public_html/system/vendor/swift/Swift/Message.php - line 92 - setCharset /public_html/modules/indicia_setup/controllers/setup_check.php - line 188 - __construct Unknown file - line Unknown - config_email_save /public_html/system/core/Kohana.php - line 291 - invokeArgs /public_html/system/core/Event.php - line 209 - instance /public_html/system/core/Bootstrap.php - line 55 - run /public_html/index.php - line 112 - require 2023-10-31 12:46:49 +00:00 --- error: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated

johnvanbreda commented 1 year ago

Thanks @jendrage, I've committed a fix to the core Kohana code to the develop branch.

jendrage commented 1 year ago

@johnvanbreda There are also errors with PHP 8.1 with swift mailer when the cron jobs are run:

2023-11-24 14:50:14 +00:00 --- error: #8192: Error converted to exception. strtolower(): Passing null to parameter #1 ($string) of type string is deprecated at line 209 in file ***/system/vendor/swift/Swift/Message/Mime.php
2023-11-24 14:50:14 +00:00 --- debug: Stack trace:
    Unknown file - line Unknown - indicia_error_handler
    ***/system/vendor/swift/Swift/Message/Mime.php - line 209 - strtolower
    ***/system/vendor/swift/Swift/Message.php - line 94 - setEncoding
    ***/application/controllers/scheduled_tasks.php - line 655 - __construct
    ***/application/controllers/scheduled_tasks.php - line 104 - doRecordOwnerNotifications
    Unknown file - line Unknown - index
    ***/system/core/Kohana.php - line 291 - invokeArgs
    ***/system/core/Event.php - line 209 - instance
    ***/system/core/Bootstrap.php - line 55 - run
    ***/index.php - line 112 - require

That can be fixed with your ?? '' trick. :-) But then we get this one:

2023-11-24 14:53:59 +00:00 --- error: #8192: Error converted to exception. Function gmstrftime() is deprecated at line 168 in file ***/system/vendor/swift/Swift/Message.php
2023-11-24 14:53:59 +00:00 --- debug: Stack trace:
    ***/system/vendor/swift/Swift/Message.php - line 168 - indicia_error_handler
    ***/system/vendor/swift/Swift.php - line 371 - generateId
    ***/application/controllers/scheduled_tasks.php - line 660 - send
    ***/application/controllers/scheduled_tasks.php - line 104 - doRecordOwnerNotifications
    Unknown file - line Unknown - index
    ***/system/core/Kohana.php - line 291 - invokeArgs
    ***/system/core/Event.php - line 209 - instance
    ***/system/core/Bootstrap.php - line 55 - run
    ***/index.php - line 112 - require

Looks like Swift Mailer is no longer maintained. However, according to their website the latest version does support 8.1.

`

JimBacon commented 1 year ago

Hi. Have you pulled the latest version of the code? I did some fixes in this area within the last fortnight.

jendrage commented 1 year ago

@JimBacon Brill, I've done that and emails are sending now :-) Sorry, I had manually applied a couple of your fixes on this thread but hadn't updated the whole codebase before. Sorted now, thank you.