ext-solr icon indicating copy to clipboard operation
ext-solr copied to clipboard

Argument 1 passed to ApacheSolrForTypo3\Solr\System\Solr\Schema\Schema::setManagedResourceId() must be of the type string, null given, called in SchemaParser.php on line 59

Open georgringer opened this issue 4 years ago • 5 comments

TYPO3 10 with ext:solr 11.1.2 and solr version 8.2.0

I currently get the following error in the reports module

Argument 1 passed to ApacheSolrForTypo3\Solr\System\Solr\Schema\Schema::setManagedResourceId() must be of the type string, null given, called in /var/www/html/typo3conf/ext/solr/Classes/System/Solr/Parser/SchemaParser.php on line 59

which might be because I am using a too old solr version but that is a different topic. just by reading the code it is easy to discover that this will break with an exception:

SchemaParser

    public function parseJson($jsonString)
    {
        ....
        $language = $this->parseManagedResourceId($schemaResponse);
        $schema->setManagedResourceId($language);
        ...
    }

    /**
     * Extracts the language from a solr schema response.
     *
     * @param stdClass $schema
     * @return ?string
     */
    protected function parseManagedResourceId(stdClass $schema): ?string
    {
    }

Schema

    public function setManagedResourceId(string $managedResourceId)
    {
        $this->managedResourceId = $managedResourceId;
    }

Problem is that SchemaParser::parseManagedResourceId might return null but Schema::setManagedResourceId expects a string.

I don't know what the correct solution is:

  • Allow null for setManagedResourceId or only call it if $language is a string
  • Return a proper exception if no language can be retrieved.

If the 1st one is used, it seems everything works fine?

georgringer avatar Oct 18 '21 08:10 georgringer

@georgringer Thanks for reporting. Since EXT:solr 9.0 with https://github.com/TYPO3-Solr/ext-solr/commit/2920d46906a3145eb9c0bb990587098457a1a265 change, we do not get proper resource ID aka language. With proper schemas, the managedResourceId should never lead to null value. The old schema is the single case, which leads to managedResourceId = null. IMHO we should handle that as early as possible, since the indexing as well the search will not work anyway, because of breaking changes in Schemas and Apache Solr versions.

I would propose to let the reports module fail a bit earlier with message, that the version of Apache Solr schemas is incompatible with current version of EXT:solr.

dkd-kaehm avatar Oct 18 '21 09:10 dkd-kaehm

Don't know if this is linked or not, but in TYPO3 11.5.10 and solr 11.5.0-rc-1 I got this error related to schema parser when trying to load the core optimisation module PHP Warning: Invalid argument supplied for foreach() in typo3conf/ext/solr/Classes/System/Solr/Parser/SchemaParser.php line 73 my schema gives a $fieldtype->analyzer but no queryAnalyzer, if I switch the code to use analyzer instead then I fall on this error Argument 1 passed to ApacheSolrForTypo3\Solr\System\Solr\Schema\Schema::setManagedResourceId() must be of the type string, null given, which is the same as the one encountered in this issue.

lucmuller avatar May 12 '22 14:05 lucmuller

Don't know if this is linked or not, but in TYPO3 11.5.10 and solr 11.5.0-rc-1 I got this error related to schema parser when trying to load the core optimisation module PHP Warning: Invalid argument supplied for foreach() in typo3conf/ext/solr/Classes/System/Solr/Parser/SchemaParser.php line 73 my schema gives a $fieldtype->analyzer but no queryAnalyzer, if I switch the code to use analyzer instead then I fall on this error Argument 1 passed to ApacheSolrForTypo3\Solr\System\Solr\Schema\Schema::setManagedResourceId() must be of the type string, null given, which is the same as the one encountered in this issue.

@lucmuller I can't reproduce this issue. Please try https://github.com/TYPO3-Solr/ext-solr/releases/tag/11.5.0-rc-2 and by-side of that you must use the right Apache Solr Version with appropriated schema.

dkd-kaehm avatar May 12 '22 14:05 dkd-kaehm

I can confirm the same error message with TYPO3 11.5.15 and EXT:solr 11.5.0

rrohaczek avatar Aug 30 '22 08:08 rrohaczek

I would propose to catch this error and print "Not supported Apache Solr Version."

dkd-kaehm avatar Feb 08 '24 09:02 dkd-kaehm