vaersaagod/seomate

Sitemap for section generates error Call to undefined method vaersaagod\seomate\SEOMate::find()

timbertens opened this issue · 3 comments

Application Info
PHP version 7.3.1
Craft edition & version Craft Pro 3.2.5.1
SEOMate 1.0.7

When calling the sitemap url of a specific section when the elementType is not supplied in the config, I get the error Call to undefined method vaersaagod\seomate\SEOMate::find()
This does not work (as in the basic example in readme):

'elements' => [
  'nieuwsItems' => ['changefreq' => 'weekly', 'priority' => 1],
 ],

However when supplying the elementType is does work

'elements' => [
  'nieuwsItems' => [
     'elementType' => \craft\elements\Entry::class,
     'criteria' => [
	'section' => ['nieuwsItems']
      ],
     'params' => ['changefreq' => 'weekly', 'priority' => 1],
 ],

@timbertens, thanks for reporting. I'm unable to reproduce this – are you able to share your entire config/seomate.php file, and a full stack trace for this error (there should be a handy button for copying the full stack trace at the top right of the Yii error page, assuming you've got devMode set to true)?

I'd also appreciate a list of any other plugins you might have installed, if possible.

This is a weird one, because assuming the example config you pasted, the only way I can see that error even occurring is if this reference to the craft\elements\Entry class somehow resolves to the vaersaagod\seomate\SEOMate class. Not sure how that can even happen, and again – not able to reproduce.

no problem, I'm on holiday at this moment so a bit slow on email ...
It appear that the problem is there when

'cacheEnabled' => false,

When I take this line out, everything works as expected. I used it in my dev environment while building the seomate config file.

This is the full non-working config file (but the clue is as said in the cacheEnabled setting)

`<?php

return [

	'defaultProfile' => 'standard',
    
    'fieldProfiles' => [
        'standard' => [
            'title' => ['title'],
            'description' => ['metaDescription', 'introTekst'],
            'keywords' => ['keywords'],
            'image' => ['seoImage'],
            'og:image' => ['seoImage'],
            'twitter:image' => ['seoImage'],
        ]
    ],


	'sitemapEnabled' => true,
	'sitemapLimit' => 100,
	'sitemapConfig' => [
		'elements' => [
		    'nieuwsItems' => ['changefreq' => 'weekly', 'priority' => 1],
		],
	],
	

	'defaultMeta' => [
	    'description' => ['defaultSeo.metaDescription'],
	    'keywords' => ['defaultSeo.keywords'],
	    'image' => ['defaultSeo.seoImage'],
	   	'og:image' => ['defaultSeo.seoImage'],
        'twitter:image' => ['defaultSeo.seoImage'],
	],

	'cacheEnabled' => false,

];`

Full stack trace

Error: Call to undefined method vaersaagod\seomate\SEOMate::find() in /home/vagrant/Code/bootstrap.kbc-agent.test/vendor/vaersaagod/seomate/src/helpers/SitemapHelper.php:129
Stack trace:
#0 /home/vagrant/Code/bootstrap.kbc-agent.test/vendor/vaersaagod/seomate/src/services/SitemapService.php(153): vaersaagod\seomate\helpers\SitemapHelper::getElementsSitemapUrls('nieuwsItems', Array, '1')
#1 /home/vagrant/Code/bootstrap.kbc-agent.test/vendor/vaersaagod/seomate/src/controllers/SitemapController.php(58): vaersaagod\seomate\services\SitemapService->elements('nieuwsItems', '1')
#2 [internal function]: vaersaagod\seomate\controllers\SitemapController->actionElement()
#3 /home/vagrant/Code/bootstrap.kbc-agent.test/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#4 /home/vagrant/Code/bootstrap.kbc-agent.test/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#5 /home/vagrant/Code/bootstrap.kbc-agent.test/vendor/craftcms/cms/src/web/Controller.php(187): yii\base\Controller->runAction('element', Array)
#6 /home/vagrant/Code/bootstrap.kbc-agent.test/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('element', Array)
#7 /home/vagrant/Code/bootstrap.kbc-agent.test/vendor/craftcms/cms/src/web/Application.php(299): yii\base\Module->runAction('seomate/sitemap...', Array)
#8 /home/vagrant/Code/bootstrap.kbc-agent.test/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('seomate/sitemap...', Array)
#9 /home/vagrant/Code/bootstrap.kbc-agent.test/vendor/craftcms/cms/src/web/Application.php(284): yii\web\Application->handleRequest(Object(craft\web\Request))
#10 /home/vagrant/Code/bootstrap.kbc-agent.test/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#11 /home/vagrant/Code/bootstrap.kbc-agent.test/web/index.php(21): yii\base\Application->run()
#12 {main}

The full list of plugins:
Activity Log 1.0.1
CodeMirror 1.0.1
CP Field Inspect 1.0.6
Field Manager 2.1.0
GeoField 1.0.0
Matrix Toolbar 1.0.6
Migration Assistant 3.1.3
Redactor 2.3.3.2
SEOMate 1.0.7
Stamp 2.1.0
Table Maker 2.0.1
Two-Factor Authentication 2.1.2
Typed link field 1.0.19
Wheel Form 2.2.1
Wordsmith 3.0.5

Thank you for the additional info @timbertens.

This is truly a weird one. From looking at the Stack Trace, it's clear that my assumption was right – the \craft\elements\Entry class (which is what SEOMate falls back on if the elementType property isn't set in the config) – is somehow resolved to \vaersaagod\seomate\SEOMate. Again, I'm not sure how that can even happen.

Your config file looks fine. The cacheEnabled thing is indeed a clue – the fact that the error goes away when you remove this line, might mean that you had working sitemaps at some point, which are cached. Which, in turn, might mean that this error was introduced recently.

In any case, I'm still not able to reproduce – even tested with all of the plugins you've installed (except GeoField, which I couldn't find in the Plugin Store). Do you have any custom modules bootstrapped for this project?

Finally, just a shot in the dark – can you try and regenerate your Composer autoload files? Maybe something is messed up in that department. In your console, type

cd /path/to/your/project/root && composer dump-autoload -o

That will make Composer regenerate your autoload configuration, which might correct any errors related to that.

Another thing to try is to delete the entire /vendor folder, and then run

composer install --no-interaction --prefer-dist --optimize-autoloader

...which will basically re-install all your Composer dependencies (at the same versions as you've currently installed).