I'm writing a module that loops over lines in a CSV file to save them as entries. For every entry I save with elements->saveElement($element);
, SEOMatic will queue a job that regenerates the sitemap for this type of entries. I'm importing more than 1000 lines this way, so there'd be more than 1000 jobs in the queue, all doing the same thing.
Is there a way to disable this hook so it wouldn't get triggered for every entry?
Here's a part of the code right now:
while (($csv = fgetcsv($handle)) !== false) {
$entry = Entry::find()->siteId($siteId)->section('products')->where(['content.field_productId' => $csv[0]])->one();
if (!$entry) {
$entry = new Entry();
$entry->sectionId = Craft::$app->sections->getSectionByHandle('products')->id;
$entry->typeId = 1;
$entry->siteId = $siteId;
}
...
...
...
try {
Craft::$app->elements->saveElement($entry, true, true, false);
} catch (Throwable $e) {
throw new RuntimeException($e);
}
}
try {
Craft::$app->elements->resaveElements(Entry::find()->siteId($siteId)->section('products'), false, true, true);
} catch (Throwable $e) {
throw new RuntimeException($e);
}
regenerateSitemapsAutomatically
to false in the beginning of the job. At the end of the job I set it back to true and then resave the first element inside the same section. – Joorren Mar 6 '20 at 8:07