BUG: Command Line Undefined Variable Warning Notice Flood #2240
Description
When performing a command line sync in blocks of 350 we get the following notice three times:
Warning: Request Entity Too Large
Followed by a warning flood:
PHP Notice: Undefined variable: item in elasticpress/includes/classes/Command.php on line 960
Followed by a further flood:
PHP Notice: Undefined index: type in elasticpress/includes/classes/Command.php on line 1021
PHP Notice: Undefined index: reason in elasticpress/includes/classes/Command.php on line 1022
PHP Notice: Undefined index: type in elasticpress/includes/classes/Command.php on line 1027
We can see that the $attempts for loop is hitting the continue statement on line 941 meaning that we never get to the if/else statement on line 944.
This means that when we get to line 959 $index_objects hasn't been reset (line 951) and $item does not exist (line 945) hence the warning flood.
Whilst the foreach of line 959 could be guarded with a check to see if $item is set, we're not sure whether this is appropriate as we don't understand enough about the code to know what this foreach is doing and why it's using $item.
Steps to Reproduce
-
Visit top level WP directory.
-
Run the command:
wp elasticpress index --setup
-
Observe the warning flood.
Expected behavior
Warning that the Request entity is too large without the flood of "undefined variable" warning messages.
Environment information
- Device: Desktop PC
- OS: Debian 10 buster
- WordPress version: 5.7.2
- ElasticPress version: 3.5.6
- Elasticsearch version: 7.13.2
- Where do you host your Elasticsearch server? localhost