FlagCountManager: Call to a member function id() on null

Created on 27 January 2023, almost 2 years ago
Updated 9 September 2024, 2 months ago

Problem/Motivation

While using patch #52 from πŸ“Œ Implement Migration Paths for Flag 7.x Needs work to migrate flags from D7 to D9 I get the following error:

Error: Call to a member function id() on null in Drupal\flag\FlagCountManager->incrementFlagCounts() (line 202 of FlagCountManager.php)

This problem isn't caused by the migration issue patch itself, but rather, by a missing empty check in FlagCountManager.php

Steps to reproduce

Proposed resolution

Fix the issue, by adding empty checks in the mentioned method.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

4.0

Component

Migration

Created by

πŸ‡©πŸ‡ͺGermany Grevil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Grevil
  • @grevil opened merge request.
  • Status changed to Needs review almost 2 years ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    Please review! The changes helped me to successfully migrate my site!

  • πŸ‡©πŸ‡ͺGermany Grevil

    Here is a patch for the time being.

  • πŸ‡©πŸ‡ͺGermany Grevil

    UPDATE: The problem might only appear, when migrating, and should be handled in this issue's related issue. Nonetheless, the empty check might still be a good idea to make sure we do not work with empty variables.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    46 pass
  • patch-4 only makes the error message not appear during the migration, but the data in the flag_counts table does not update. I've added a new patch which causes behavior when adding a new flag to the database, if there are no related records in the flag_counts table, such a related record will be created.

  • πŸ‡©πŸ‡ͺGermany Grevil

    Here is the diff.

  • πŸ‡©πŸ‡ͺGermany Grevil

    Sorry, the diff seems to be weirdly formatted... @svitlana.miko could you apply your changes to this issue's MR, for better reviewability?

  • Issue was unassigned.
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @svitlana.miko could you please incorporate your changes into the MR as @Grevil suggested? So we could finally review this and fix it?

  • First commit to issue fork.
  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 7 months ago
    Waiting for branch to pass
  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 7 months ago
    Waiting for branch to pass
  • Pipeline finished with Failed
    7 months ago
    Total: 157s
    #138511
  • Status changed to Needs work 4 months ago
  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    Not doing a migration, but getting this error in the log as well.
    #11 failed for me, here is the terminal and .rej info:

    sudo -u www-data patch -p1 < 61.patch
    patching file src/FlagCountManager.php
    Hunk #1 FAILED at 196.
    1 out of 1 hunk FAILED -- saving rejects to file src/FlagCountManager.php.rej
    +      if ($existing_entity) {
    +        $count = $existing_entity->count + 1;
    +
    +        $this->connection->update('flag_counts')
    +          ->fields(['count' => $count])
    +          ->condition('entity_type', $entity_type)
    +          ->condition('entity_id', $entity_id)
    +          ->execute();
    +      } else {
    +        // Entity does not exist, so insert a new row
    +        $this->connection->insert('flag_counts')
    +          ->fields([
    +            'flag_id' => $flag_id,
    +            'entity_type' => $entity_type,
    +            'entity_id' => $entity_id,
    +            'count' => 1
    +          ])
    +          ->execute();
    +      }
    +    }
       }
    
       /**

    Hope this helps.

  • πŸ‡¨πŸ‡¦Canada floydm

    @alfthecat the patch does not apply to beta 4 but it applies to the current dev branch fine.

  • First commit to issue fork.
  • πŸ‡¨πŸ‡­Switzerland exiled_hammer

    Patch file for 8.x-4.0-beta5 from Merge request !61

  • First commit to issue fork.
Production build 0.71.5 2024