We are currently running D8.7.8 and Embed version 8.x-1.1, trying to update to Embed 1.2 is throwing an error with the update:

-------- ----------- --------------- ----------------------------------------------------------------------------
Module Update ID Type Description
-------- ----------- --------------- ----------------------------------------------------------------------------
embed 8101 hook_update_n Update embed button icons to use encoded data instead of file references.
-------- ----------- --------------- ----------------------------------------------------------------------------

Do you wish to run the specified pending updates? (yes/no) [yes]:
> y

[notice] Update started: embed_update_8101
[error] Call to a member function getFileUri() on bool
[error] Update failed: embed_update_8101
[error] Update aborted by: embed_update_8101
[error] Finished performing updates.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jldust created an issue. See original summary.

brtamas’s picture

pnagornyak’s picture

FileSize
701 bytes
319 bytes

I have same issue, but I believe that we need some logging.

keboca’s picture

@pnagornyak your patch works perfectly! thanks man!

cameron prince’s picture

I can confirm the patch in #3 resolves the errors applying updates.

damontgomery’s picture

I did some digging in the module and I think the behavior is a bit confusing, but #3 should work for now.

It looks like the module is assuming that all icons are stored in the file system, but if you don't set one, you get the default image.

See

  public function getIconUrl() {
    if (!empty($this->icon)) {
      $uri = $this->icon['uri'];
      if (!is_file($uri) && !UrlHelper::isExternal($uri)) {
        static::convertEncodedDataToImage($this->icon);
      }
      $uri = file_create_url($uri);
    }
    else {
      $uri = $this->getTypePlugin()->getDefaultIconUrl();
    }

    return file_url_transform_relative($uri);
  }

I'm not sure why a UUID that doesn't point to anything is stored in these configuration files.

So, with #3
- File can't be loaded
- Config isn't updated
- Config still has the broken icon_uuid that doesn't point to anything
- Config doesn't have the icon value
- When the icon is fetched it falls back to the default

The error message is accurate, but a bit misleading. The most likely case for sites is that they are using the default, but I don't know of an easy way to distinguish between the default being used and a file that exists (maybe on prod) and cannot be loaded (maybe on local).

Thanks for #3 and hopefully this information is helpful if people want to take it in another direction.

eric.chenchao’s picture

In this patch if $file is empty, we assume default plugin icon is in use. So we will get base64 data from plugin default icon.

eric.chenchao’s picture

Status: Active » Needs review
Dave Reid’s picture

Version: 8.x-1.1 » 8.x-1.x-dev
FileSize
2.78 KB

We don't need to fetch the default button image data, that is handled for us as long as we save empty data to the 'icon' config key correctly. This should help clean up some of the data and adds a warning when an Embed button did have an uploaded file, but the file no longer exists.

Dave Reid’s picture

Some more improvements and some better handling in case they have already have the embedded icon data, this will not overwrite that data.

Dave Reid’s picture

Because we're interacting with saving entities, we should move this to a post_update hook, and then we can get rid of the dependency calculation entirely since it gets handled for us by $button->save().

  • Dave Reid committed 5640563 on 8.x-1.x
    Issue #3100972 by Dave Reid, pnagornyak, eric.chenchao, brtamas: Fixed...
Dave Reid’s picture

Status: Needs review » Fixed

Tested and committed #11 to 8.x-1.x. Will release 8.x-1.3 shortly.

pookmish’s picture

This change is now producing an error for me during the button save method call.
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3ed72229-7529-4cf5-b679-1d7a86b1030a' for key 'file_field__uuid__value': INSERT INTO {file_managed} (uuid, langcode, uid, filename, uri, filemime, filesize, status, created, changed)

EDIT:
Nevermind. it was a presave hook on my side.

Status: Fixed » Closed (fixed)

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