creecros / Customizer

Kanboard - Customizer adds GUI for logo, favicon and themes
MIT License
198 stars 27 forks source link

PHP 8.2 Uncaught TypeError: array_diff() #150

Closed svennest closed 4 months ago

svennest commented 4 months ago

When Customizer is installed on Debian 12/Apache2/PHP 8.2, it throws the following errors because /Customizer/Assets/css/userthemes does not exist and cannot be created with the permissions in the plugins directory. Shouldn't the path be 'DATA_DIR' . /files/customizer/themes so it is writable and changes are not lost during Customizer upgrades?

[Tue Jun 04 13:29:47.592637 2024] [php:warn] [pid 156] [client 192.168.1.7:54950] PHP Warning: mkdir(): Permission denied in /var/www/html/kanboard-1.2.36/plugins/Customizer/Plugin.php on line 22 [Tue Jun 04 13:29:47.592692 2024] [php:warn] [pid 156] [client 192.168.1.7:54950] PHP Warning: scandir(plugins/Customizer/Assets/css/userthemes): Failed to open directory: No such file or directory in /var/www/html/kanboard-1.2.36/plugins/Customizer/Plugin.php on line 27 [Tue Jun 04 13:29:47.592705 2024] [php:warn] [pid 156] [client 192.168.1.7:54950] PHP Warning: scandir(): (errno 2): No such file or directory in /var/www/html/kanboard-1.2.36/plugins/Customizer/Plugin.php on line 27 [Tue Jun 04 13:29:47.592747 2024] [php:error] [pid 156] [client 192.168.1.7:54950] PHP Fatal error: Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, bool given in /var/www/html/kanboard-1.2.36/plugins/Customizer/Plugin.php:27\nStack trace:\n#0 /var/www/html/kanboard-1.2.36/plugins/Customizer/Plugin.php(27): array_diff()\n#1 /var/www/html/kanboard-1.2.36/app/Core/Plugin/Loader.php(127): Kanboard\\Plugin\\Customizer\\Plugin->initialize()\n#2 /var/www/html/kanboard-1.2.36/app/Core/Plugin/Loader.php(67): Kanboard\\Core\\Plugin\\Loader->initializePlugin()\n#3 /var/www/html/kanboard-1.2.36/app/ServiceProvider/PluginProvider.php(27): Kanboard\\Core\\Plugin\\Loader->scan()\n#4 /var/www/html/kanboard-1.2.36/vendor/pimple/pimple/src/Pimple/Container.php(297): Kanboard\\ServiceProvider\\PluginProvider->register()\n#5 /var/www/html/kanboard-1.2.36/app/common.php(58): Pimple\\Container->register()\n#6 /var/www/html/kanboard-1.2.36/index.php(6): require('...')\n#7 {main}\n thrown in /var/www/html/kanboard-1.2.36/plugins/Customizer/Plugin.php on line 27

creecros commented 4 months ago

Your first error is the cause of all preceding errors.

Permission denied

creecros commented 4 months ago

Your subject didn't match your content.

But to answer your question, the paths are not static as you are attempting to suggest. Or maybe you are suggesting that they are reversed paths, or something, which I assure you is not the case.

We uses DATA_DIR and basename(PLUGINS_DIR) respectively and appropriately https://github.com/creecros/Customizer/blob/02ed177291a2aa51be22c6f17c7f9f4e478ccfdb/Plugin.php#L39

https://github.com/creecros/Customizer/blob/02ed177291a2aa51be22c6f17c7f9f4e478ccfdb/Plugin.php#L19

Your issue however, is permissions.

Also, files are not lost in upgrades.

svennest commented 4 months ago

Thanks for your quick reply. Apologies if I misinterpreted the error.

This Kanboard configuration with Customizer runs without errors on a Debian 11 server that has PHP 7.4

Upon moving the kanboard directory to a Debian 12 server with PHP 8.2 it produces the "PHP Fatal error: Uncaught TypeError: array_diff()" on line 27 unless I chown www-data /kanboard/plugins/Customizer/Assets/css/

Then it creates /kanboard/plugins/Customizer/Assets/css/userthemes and no longer fails on line 27.

I noticed that /kanboard/data/files/customizer/themes exists and wondered why it requires write permissions to /kanboard/plugins on the newer version of PHP.

creecros commented 4 months ago

I dont really know how to exactly answer the question other than saying, it does not just require write permissions in kanboard/plugins on the newer version of PHP.

It requires write permissions in that folder, period. Regardless of what php you use or Debian or alpine, or anything.

So the answer as to why it doesnt work on your new server exists in my original response.

Permission denied

creecros commented 4 months ago

If you are trying to understand, why it does what it does and how, look at the plugin.php.

I wrote this years ago, is there a better way? Maybe. There may have been a time where I constantly improved everything on this plugin, but that time has passed for me. Maybe one day I'll renew interest, maybe not.

I challenge you to improve upon it. Then, make a PR, and I'll merge it, but you then own all issues preceded by it. 😆

All that said, I have no issues using the latest php. That's definitely not your problem.

svennest commented 4 months ago

Thanks for your replies, when running on PHP 8, making the plugins directory writable fixes the exception and allows the plugin to run. On PHP 7, if plugins is not writable it throws a warning, not an exception.

For background in case anyone else runs into this, it caused by stricter type checking in PHP 8, https://php.watch/versions/8.0/internal-function-exceptions

Also, since Kanboard v1.2.8, installing plugins from the web interface is disabled by default for security reasons, so the plugin directory is not normally writable, https://docs.kanboard.org/v1/admin/plugins/