Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted February 20Feb 20 Hello! A client on the forum (IPS 4.7.20, PHP 8.1.31) has a search configured via ElasticSeach, a situation occurred when his separate server with ElasticSeach crashed. Search, profiles and various functions began to give the following errors:TypeError: array_map(): Argument #2 ($array) must be of type array, null given (0)#0 /public_html/forum/system/Content/Search/Elastic/Query.php(1320): array_map(Object(Closure), NULL)#1 /public_html/forum/applications/core/modules/front/members/profile.php(256): IPS\Content\Search\Elastic\_Query->search()#2 /public_html/forum/system/Dispatcher/Controller.php(118): IPS\core\modules\front\members\_profile->manage()#3 /public_html/forum/applications/core/modules/front/members/profile.php(84): IPS\Dispatcher\_Controller->execute()#4 /public_html/forum/system/Dispatcher/Dispatcher.php(153): IPS\core\modules\front\members\_profile->execute()#5 /public_html/forum/index.php(13): IPS\_Dispatcher->run()#6 {main}Error handling if ElasticSeach does not respond, i.e. the response is NULL - missing, as a temporary solution I made an edit in /system/Content/Search/Elastic/Query.phpAfter if ( isset( $return['error'] ) ) { \IPS\Log::log( print_r( array_merge( $array, ['error' => $return['error'] ] ), TRUE ), 'elasticsearch' ); return new \IPS\Content\Search\Results( array(), 0 ); }Pasted if ( empty( $return ) ) { // We have configured ElasticSearch autostart on the server, but it would be better to add Email sending in this case \IPS\Log::log( print_r( array_merge( $array, ['error' => 'Empty response ElasticSearch' ] ), TRUE ), 'elasticsearch' ); return new \IPS\Content\Search\Results( array(), 0 ); }It might also make sense to add to array_map !empty($return['hits']['hits']) ? $return['hits']['hits'] : []