- Issue created by @andreadruiz
- Status changed to Needs review
3 months ago 6:31pm 17 September 2024
After upgrading from 3.0.4 to 3.1.2, when trying to visit a course, an error is displayed:
Drupal\Core\Entity\Query\QueryException: 'lp_status' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable() (line 369 of core/lib/Drupal/Core/Entity/Query/Sql/Tables.php).
After reviewing the .install file of the module, I see that it was included in the hook_install of the module if the lp_status definition exists:
// Checking if the lp_status fields definition is not exist.
// In case of the fresh install, according to order of the modules
// installation, the opigno_module can be enabled before this one.
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
if (!($definition_update_manager->getFieldStorageDefinition('lp_status', 'user_module_status'))) {
// Add a reference to LP status entity.
$definition = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Learning path status'))
->setDescription(t('The learning path status entity the current module attempt belongs to'))
->setSetting('target_type', 'user_lp_status')
->setSetting('target_bundles', ['user_lp_status' => 'user_lp_status']);
$definition_update_manager->installFieldStorageDefinition('lp_status', 'user_module_status', 'opigno_module', $definition);
Here: https://git.drupalcode.org/project/opigno_learning_path/-/compare/3.0.4....
And this can only happen if I uninstall and install the module but not for cases where the module is already installed and has content in it. I add a patch that checks the same thing.
Move the code from the hook install to a hook_update.
TBC
Needs review
3.1
Code