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

  1. Create a content entity type that uses a string ID field
  2. Enable linkchecker scanning on one of the entity's text fields
  3. Create and then delete an entity of this type
  4. Observe the SQL error

Proposed resolution

Change the entity_id column from int to varchar(128) to support both integer and string entity IDs:

  1. Update linkchecker_schema() to use varchar type
  2. 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

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

saidatom created an issue. See original summary.

saidatom’s picture

Status: Active » Needs review
saidatom’s picture

fengtan’s picture

We also ran into this -- thanks for the MR @saidatom, that works on our side.

Attached is a static version of MR !134 for convenience