Skip to content

content_import: Fix crash in post handler.

The condition would call count($j['item']) if $j['item'] was null, which will throw a TypeError in php 8.0 and later. (It's been a warning since php 7.2!) This breaks the import.

Also used isset() to check if the variable is set and not null before calling count. Again, it avoids a warning in case the variable is not set.

Also removed an unnecesaary continue statement at the end of the loop.

Note: I'm unsure if this code snippet is actually necessary:

				$j = json_decode($x['body'],true);

				if(! (isset($j['item']) && count($j['item'])))
					break;

The $j variable is never used after this, but it may still be correct by the protocol to check whether there are any items before proceeding to the next lines. If they are not necessary, it would be better to have them removed altogether.

Merge request reports