Problem/Motivation
The `linkchecker_index` table schema defines the `entity_id` column as an integer:
'entity_id' => [
'type' => 'int',
'not null' => TRUE,
'description' => 'Entity ID.',
],However, Drupal supports entities with string-based IDs (using BaseFieldDefinition::create('string') for the ID field). When such entities are processed by linkchecker (either during link extraction or deletion), the module fails with SQL errors:
SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: 'SOME_STRING_ID': DELETE FROM "linkchecker_index" WHERE ("entity_id" = :db_condition_placeholder_0) AND ("entity_type" = :db_condition_placeholder_1)
This happens in LinkCleanUp::cleanUpForEntity() and LinkExtractorService::updateEntityExtractIndex() when they attempt to insert/query/delete using string entity IDs.
Steps to reproduce
- Create a content entity type that uses a string ID field
- Enable linkchecker scanning on one of the entity's text fields
- Create and then delete an entity of this type
- Observe the SQL error
Proposed resolution
Change the entity_id column from int to varchar(128) to support both integer and string entity IDs:
- Update linkchecker_schema() to use varchar type
- Add an update hook to alter the existing column for sites upgrading
Remaining tasks
- Create patch with schema change and update hook
- Add test coverage for entities with string IDs
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | linkchecker-support-entities-string-id-3567956-MR134.patch | 4.63 KB | fengtan |
Issue fork linkchecker-3567956
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
Comment #3
saidatomComment #4
saidatomComment #5
fengtanWe also ran into this -- thanks for the MR @saidatom, that works on our side.
Attached is a static version of MR !134 for convenience