Fixes for more robust dealing with content handlers.
authorStanislav Malyshev <smalyshev@gmail.com>
Thu, 26 Jan 2017 19:18:56 +0000 (11:18 -0800)
committerStanislav Malyshev <smalyshev@gmail.com>
Thu, 26 Jan 2017 20:20:07 +0000 (12:20 -0800)
Change-Id: I12a02da005f4b2bceaa850bd1f41a90ac4e1754a

includes/search/SearchEngine.php

index 0bcb07a..87701cd 100644 (file)
@@ -706,8 +706,21 @@ abstract class SearchEngine {
        public function getSearchIndexFields() {
                $models = ContentHandler::getContentModels();
                $fields = [];
+               $seenHandlers = new SplObjectStorage();
                foreach ( $models as $model ) {
-                       $handler = ContentHandler::getForModelID( $model );
+                       try {
+                               $handler = ContentHandler::getForModelID( $model );
+                       }
+                       catch ( MWUnknownContentModelException $e ) {
+                               // If we can find no handler, ignore it
+                               continue;
+                       }
+                       // Several models can have the same handler, so avoid processing it repeatedly
+                       if ( $seenHandlers->contains( $handler ) ) {
+                               // We already did this one
+                               continue;
+                       }
+                       $seenHandlers->attach( $handler );
                        $handlerFields = $handler->getFieldsForSearchIndex( $this );
                        foreach ( $handlerFields as $fieldName => $fieldData ) {
                                if ( empty( $fields[$fieldName] ) ) {