-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Categories not updating when resaving entries view CLI #4672
Comments
Categories fields only self-correct their selected relations when their field value changes, which is why This shouldn’t have been a problem for you to begin with though. When you move a category under another one, there’s code in place to ensure that every Categories field that relates the moved category will also relate its new ancestors. I did notice that it wasn’t working as expected when the new ancestors were disabled, though, and I’ve fixed that for the next release. Could that have been the case here? |
Ah OK. That's why I was confused. None of the cats were disabled so I was assuming that they should automatically update. |
Hm, in that case I’m not able to reproduce. How did you go about changing the category hierarchy? Just from the Control Panel UI, or did you do it programmatically?
Yeah, you could write a script that does it. Since this is just a one-time thing, you could copy your $app->run(); Then add this to the end: $section = 'yourSectionHandle';
$entryType = 'yourEntryTypeHandle';
$catField = 'yourCategoriesFieldHandle';
$query = craft\elements\Entry::find()
->section($section)
->type($entryType)
->siteId('*')
->unique();
foreach ($query->each() as $entry) {
/** @var craft\elements\Entry $entry */
$entry->setFieldValue($catField, $entry->$catField->anyStatus()->ids());
$entry->setScenario(craft\base\Element::SCENARIO_ESSENTIALS);
$entry->resaving = true;
$app->elements->saveElement($entry);
}
echo 'Done resaving entries'; Replace Then access |
Awesome. I'll give it a try this evening. For info, the categories hierarchy was done via the CP. |
Can you check if you are able to reliably reproduce the original issue – that new ancestors are not automatically added to existing relations? If so, can you please send a database backup and your |
Will do. |
It is possible to have multiple job workers, especially if you are using the CLI to create them, but I suppose a race condition could occur where multiple could be started by the browser as well. |
Description
Have a strange issue. I had a category group which consisted of a mix of 1 and 2 level categories. I updated the categories so that every category had a parent and it's a max of two levels.
When viewing an entry with a categories field for this group, if the original category was a (previously) single level category, it would just show that one. When I resave on the entry it updates to show the new parent for that category.
When I run a
resave/entries
from the cli it doesn't update these and the entry still doesn't recognise the parent category. (Query for the parent on the front end showsnull
until the entry is directly saved.)Additional info
The text was updated successfully, but these errors were encountered: