Groups:
Now that we have changed
timestamp on the groups, it seems reasonable to set it to the existing created
timestamp value as that is the default behavior when creating a new entity.
Group items:
Now that we have created
and changed
timestamps, the existing group items will not get updates on the changed
timestamp without a created
timestamp.
It seems reasonable here to base a group items initial timestamps based on the group created
timestamp.
Come up with a plan, either to leave old entities as is, or update the ones without the proper values.
Ideally we could do this in an update hook, but for those comfortable with Drush, below is a snippet that could be executed by Drush from a custom module for an example:
/**
* Post process to set created and changed times.
*/
function MY_MODULE_migration_group_post_save() {
$group_storage = \Drupal::entityTypeManager()->getStorage('commerce_vado_group');
$groups = $group_storage->loadMultiple();
/** @var \Drupal\commerce_vado\Entity\VadoGroupInterface $group */
foreach ($groups as $group) {
$timestamp = $group->getCreatedTime();
if ($timestamp && $group->getChangedTime() == NULL) {
$group->setChangedTime($timestamp);
$group->save();
}
/** @var \Drupal\commerce_vado\Entity\VadoGroupItemInterface $group_item */
foreach ($group->getItems() as $group_item) {
if ($timestamp && $group_item->getCreatedTime() == NULL) {
$group_item->setCreatedTime($timestamp);
$group_item->setChangedTime($timestamp);
$group_item->save();
}
}
}
}
You could then run this via Drush:
drush ev "MY_MODULE_migration_group_post_save();"
Active
3.0
Documentation