Problem/Motivation

When you have a webform that doesn't store the submission, the linkchecker_entity_insert fails, because there's no entity_id. The entity_id is used in updateEntityExtractIndex, but there's no check on the entity.

Steps to reproduce

  1. Create a webform and disable the storage of submissions
  2. Submit the webform

This will result in the following error:
Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'entity_id' cannot be null: INSERT INTO {linkchecker_index} (entity_id, entity_type, last_extracted_time) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => webform_submission [:db_insert_placeholder_2] => 1633420538 )

Proposed resolution

Maybe it's an idea to exclude specific entity types from the linkchecker process. Only entities that are allowed are processed.

But the minimal solution would probably to check if the entity is saved (has an id), before processing.

Remaining tasks

  1. Create patch
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

robert-os created an issue. See original summary.

robert-io’s picture

StatusFileSize
new1.04 KB

Basic patch to check if the entity is stored.

eiriksm’s picture

Could you have a look if the patch in #3184613: Wrong calculation of extraction status fixes your issue?

lostkangaroo’s picture

Status: Active » Needs work

Just applied the patch from #3184613 and ran into a different error. The patch from that issue does not fix the issue in the summary.

The patch in this issue does allow the submission to happen but this should at least have tests included.

tedfordgif made their first commit to this issue’s fork.

tedfordgif’s picture

StatusFileSize
new1.04 KB

Add MR that checks for integer IDs, instead of the mere presence of an ID.

tedfordgif’s picture

StatusFileSize
new2.37 KB

Missed a few places in the previous patch.

robert-io’s picture

arnaud-brugnon’s picture

is_int method is not a good solution.
For some unkown reason, entity id is not always an int in the PHP way.

I have weird behaviors on broken link reports if i use is_init.
It s mainly because paragraph id is not recognized as id and then linkcheckerlink entities are not deleted.

arnaud-brugnon’s picture

Here's my solution.

arnaud-brugnon’s picture

Status: Needs work » Needs review

The last submitted patch, 9: 3240788-9-linkchecker-require-integer-ids.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

acbramley’s picture

StatusFileSize
new548 bytes

I don't think we need to cover entity_update or entity_delete, un-saved submissions would never go through these lifecycles as they are never saved.

We can also simply use $entity->isNew() to check for the existence of an id.

imre.horjan’s picture

Status: Needs review » Reviewed & tested by the community

Patch #14 works for me.

abhijith s’s picture

Got different error but with same scenario when I disabled webform submissions.

AssertionError: Cannot load the “webform_submission” entity with NULL ID. in assert() (line 295 of /var/www/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php)
#0 /var/www/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(295): assert(false, 'Cannot load the...')
#1 /var/www/docroot/modules/contrib/linkchecker/src/LinkCleanUp.php(128): Drupal\Core\Entity\EntityStorageBase->load(NULL)
#2 /var/www/docroot/modules/contrib/linkchecker/linkchecker.module(167): Drupal\linkchecker\LinkCleanUp->cleanUpForEntity(Object(Drupal\webform\Entity\WebformSubmission))
#3 /var/www/docroot/modules/contrib/hook_event_dispatcher/src/HookEventDispatcherModuleHandler.php(76): linkchecker_entity_insert(Object(Drupal\webform\Entity\WebformSubmission))
#4 /var/www/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(405): 

Confirming the patch #14 worked for me.

VladimirAus made their first commit to this issue’s fork.

vladimiraus’s picture

✅ Removing patch #11 from MR
✅ Applying patch #14
✅ Hiding files in favour of MR

vladimiraus’s picture

Status: Reviewed & tested by the community » Fixed

Merged MR and committed!
Thank you 🥃

eiriksm’s picture

Can we do a follow up to create tests for this issue?

vladimiraus’s picture

Sounds good @eiriksm. Do you want to start issue and MR?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.