backdrop-contrib / coder_upgrade

Helps automate some/most of the work required to upgrade a module from Drupal to Backdrop 1.x
GNU General Public License v2.0
4 stars 7 forks source link

Fix PHP 8.1 errors #82

Closed docwilmot closed 1 year ago

docwilmot commented 1 year ago

Fixes https://github.com/backdrop-contrib/coder_upgrade/issues/81.

docwilmot commented 1 year ago

@bugfolder this makes PHP 8.1 usage possible. Could you test please? And merge if OK.

bugfolder commented 1 year ago

Tested. I set my local site to PHP 8.1.13, downloaded the modified module from the branch https://github.com/backdrop-contrib/coder_upgrade/tree/php-8.1, and ran CU on an old D7 module I had. Unfortunately, it resulted in these errors:

Warning: Undefined array key 0 in /mysite/modules/contrib/coder_upgrade/grammar_parser/parser.inc on line 443

Warning: Undefined array key "line" in /mysite/modules/contrib/coder_upgrade/grammar_parser/parser.inc on line 376

Warning: Undefined array key "file" in /mysite/modules/contrib/coder_upgrade/grammar_parser/parser.inc on line 376 ERROR: Invalid callback PGPWriter::exceptionHandler, cannot access protected method PGPWriter::exceptionHandler() on line in (Warning) Fatal error: Uncaught Error: Attempt to modify property "container" on bool in /mysite/modules/contrib/coder_upgrade/conversions/end.inc:333 Stack trace: #0 /mysite/modules/contrib/coder_upgrade/conversions/end.inc(246): coder_upgrade_create_update_install('ousa_class_atte...', Object(PGPReader), Array, Array) #1 /mysite/modules/contrib/coder_upgrade/conversions/end.inc(53): coder_upgrade_install_file('ousa_class_atte...', '/Users/rjlang/S...', Object(Config)) #2 /mysite/core/includes/module.inc(1200): coder_upgrade_upgrade_end_alter('/Users/rjlang/S...', NULL, NULL, NULL) #3 /mysite/modules/contrib/coder_upgrade/includes/main.inc(175): backdrop_alter('upgrade_end', '/Users/rjlang/S...') #4 /mysite/modules/contrib/coder_upgrade/includes/main.inc(89): coder_upgrade_convert_end('/Users/rjlang/S...') #5 /mysite/modules/contrib/coder_upgrade/includes/conversion.inc(318): coder_upgrade_start(Array, Array, Array) #6 /mysite/modules/contrib/coder_upgrade/includes/conversion.inc(274): coder_upgrade_conversions_apply(Array) #7 /mysite/core/includes/form.inc(1558): coder_upgrade_conversions_form_submit(Array, Array) #8 /mysite/core/includes/form.inc(928): form_execute_handlers('submit', Array, Array) #9 /mysite/core/includes/form.inc(385): backdrop_process_form('coder_upgrade_c...', Array, Array) #10 /mysite/core/includes/form.inc(131): backdrop_build_form('coder_upgrade_c...', Array) #11 /mysite/core/modules/system/system.module(2558): backdrop_get_form('coder_upgrade_c...') #12 /mysite/core/includes/module.inc(942): system_block_view('main', Array, Array) #13 /mysite/core/modules/layout/includes/block_legacy.class.inc(24): module_invoke('system', 'block_view', 'main', Array, Array) #14 /mysite/core/modules/layout/includes/block_legacy.class.inc(50): BlockLegacy->buildBlock() #15 /mysite/core/modules/layout/plugins/renderers/layout_renderer_standard.inc(509): BlockLegacy->getContent() #16 /mysite/core/modules/layout/plugins/renderers/layout_renderer_standard.inc(463): LayoutRendererStandard->renderBlock(Object(BlockLegacy)) #17 /mysite/core/modules/layout/plugins/renderers/layout_renderer_standard.inc(370): LayoutRendererStandard->renderBlocks() #18 /mysite/core/modules/layout/plugins/renderers/layout_renderer_standard.inc(350): LayoutRendererStandard->renderLayout() #19 /mysite/core/modules/layout/layout.module(667): LayoutRendererStandard->render() #20 /mysite/core/includes/menu.inc(531): layout_route_handler(Array) #21 /mysite/index.php(21): menu_execute_active_handler() #22 {main} thrown in /mysite/modules/contrib/coder_upgrade/conversions/end.inc on line 333

I have to run out for several hours, but will check back later.

docwilmot commented 1 year ago

Drat. Can you let me know which module please? My test one runs without error.

bugfolder commented 1 year ago

It was a fairly large custom module from a site I'd converted (I just grabbed something big for the exercise). Tomorrow I'll try it on some more modules to see if I can either find a contrib module that causes it, or at least narrow down what happened to a smaller module.

docwilmot commented 1 year ago

Same fix as previous 😃.

This $reader->addTokenNames() renames the Reader tokens array from a PHP token value (like 394) to the PHP token value with its name in parentheses (like 394 (T_WHATEVER)) which seemed not to be a problem until PHP 8. Could be a clue that some calls to this function say "// @todo This is unnecessary." and the function comment itself says "Note: Not called by this code". Hopefully this doesn't uncover more errors.

bugfolder commented 1 year ago

OK, I ran some more tests with D7 contrib modules. Here's the results:

https://www.drupal.org/project/entityreference/releases/7.x-1.6 - crashes https://www.drupal.org/project/http_response_headers/releases/7.x-1.2 - crashes https://www.drupal.org/project/node_clone_tab/releases/7.x-1.1 - works https://www.drupal.org/project/masquerade/releases/7.x-1.x-dev - crashes

The crashes all started with

Warning: Undefined array key 0 in /mysite/modules/contrib/coder_upgrade/grammar_parser/parser.inc on line 443

docwilmot commented 1 year ago

Even with the additional commit from https://github.com/backdrop-contrib/coder_upgrade/pull/82/commits/bfccd9d1e820a67ea8c718d60cd7fc0110cd55c0 ?

docwilmot commented 1 year ago

I've just testd the above and all convert error free on PHP 8.1.14

bugfolder commented 1 year ago

Ah, with the new commit, all of those pass! So LGTM.