georgringer / news

TYPO3 Extension news
GNU General Public License v2.0
264 stars 358 forks source link

Undefined array key "single" in NewsRepository v10.0.3 #2190

Closed paptikant closed 1 year ago

paptikant commented 1 year ago

Bug Report

Current Behavior If the search returns no result (searching for a rubish string, eg. "slkxcsdf") an Exception is thrown: PHP Warning: Undefined array key "single" in /var/www/html/public/typo3conf/ext/news/Classes/Domain/Repository/NewsRepository.php line 411

Expected behavior/output no exception

Environment

Possible Solution Wrap the code from line 411 to 419 into another if checking if the array key is defined:

   if ($data['single'] ?? false) {
        if (is_array($data['single'])) {
            foreach ($data['single'] as $year => $months) {
                $countOfYear = 0;
                foreach ($months as $month) {
                    $countOfYear += $month;
                }
                $data['total'][$year] = $countOfYear;
            }
        }
    }

Additional context I assume the problem has to do with: In PHP < 8.1 undefined array key was a notice and usually not displayed as error (depending on your PHP/TYPO3 configuration). Since PHP 8.1 it's a warning and is usually displayed as an error.

I have not checked if the issue is fixed in a higher version, ie. v11.0 upwards. Would be nice to get this patched for the people still using v10, though.

paptikant commented 1 year ago

or if (array_key_exists('single', $data)) { ... }

georgringer commented 1 year ago

this is fixed in v11 and I don't plan to provide updates to 10x branch, especially not for such stuff - patch it yourself with composer or update to v11. hope you understand

paptikant commented 1 year ago

Yah, looks like you would have to fix more than one of those: PHP Warning: Undefined array key "l10n_mode" in /var/www/html/public/typo3conf/ext/news/Classes/Service/AccessControlService.php line 98

georgringer commented 1 year ago

this has been fixed with https://github.com/georgringer/news/commit/2c2417e2d9282ef122c0b0905aeeba385f87a52d

just update to v11 ;)

paptikant commented 1 year ago

The comment was meant to mean, that I understand your position; - I do keep falling over those issues in v10, though, and I undestand that you are not keen to fix them twice, assuming that you fixed them for v11. "Just update" is sometimes easier typed than done, though. Anyway, thank you for your time and work. It's appreciated.

georgringer commented 1 year ago

i fully understand that - as a "solution" you could supress such warnings btw