Icons management is not consistent

Created on 27 November 2023, about 1 year ago

Problem/Motivation

When we upload an icon from the PWA config form, it stores a fid for each icons format.

image_fid: 385
image_small_fid: 386
image_very_small_fid: 387

This fid can be different from an environment to another one (local / preprod / prod / etc.) because someone might add a file on an environment that has not been added on another one.

Let say that I took a backup from the prod environment to import it in my local environment.
At this point the last fid known on those 2 environments is the same - let say 120.
If someone adds a file on the prod environment (let say a contributor was writing an article and he added an image to that content) while I am configuring the PWA on my local environment, the last known fid on prod is now 121, but on my local it's still 120.

I am configuring the PWA and add an icon via its config form on my local env.
If I now export my local config I can see, in pwa.config.yml something like :

image_fid: 121
image_small_fid: 122
image_very_small_fid: 123

Now I am deploying my config to the prod environment.
1st problem: The PWA is now enabled and the fid is pointing to the wrong file (cause 121 has been taken by the file that the contributor uploaded during my dev).
2nd problem: If I access the prod PWA config form, I see the wrong icon displayed in the form and, since the good icon has not been uploaded on this environment yet, I need to remove the wrong icon in order to be able to upload the good one.
And there's absolutely no check to see if the file is used somewhere else on the website => the file is physically deleted from the server leading to a missing image on the content where this file has been added by the contributor and I now have to create a settings.local.php to give the good fids

$config['pwa.config']['image_fid'] = 122;
$config['pwa.config']['image_small_fid'] = 123;
$config['pwa.config']['image_very_small_fid'] = 124;

But I still have a 404 image in the contributor's content

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇫🇷France MacSim

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

Comments & Activities

  • Issue created by @MacSim
  • Status changed to Closed: won't fix 10 months ago
  • 🇩🇪Germany Grevil

    Thanks for taking the time, to write this summary! I don't see this as a PWA issue, but more of an issue of synchronizing dev and prod environments in Drupal (and probably in general).

    Instead of deleting the users file and overwriting the pwa.config in your settings.php, just simply export your config, overwrite the "pwa.config.yml" image IDs with the ones you actually want and reimport it again.

    And there's absolutely no check to see if the file is used somewhere else on the website => the file is physically deleted from the server leading to a missing image on the content where this file has been added by the contributor.

    We could check file usage in the validationForm() method, but I doubt that is needed, as the files should only ever be used as the app icons.

  • Status changed to Needs work 10 months ago
  • 🇫🇷France MacSim

    I am sorry I am reopening this issue cause it's a major problem in this module architecture.

    In 14 years using drupal it's the first time that I have such a problem... so it clearly sounds like a PWA issue.
    Storing a fid value based on an upload which is happening on a single environment (the file doesn't even exist on other environment) as a config value which can be deploy in many environments doesn't make sense at all.

    You could store paths instead or ask people to respect some paths you're asking for with specific dimensions.
    People would respect it cause if they don't their icons wouldn't work.

    Please have a look on how favicons and logos config are managed in system.theme.global.yml
    This is exactly how you should manage your PWA icons.

    We could check file usage in the validationForm() method, but I doubt that is needed, as the files should only ever be used as the app icons.

    The summary I wrote however explains the opposite...

  • First commit to issue fork.
  • 🇩🇪Germany Duwid

    @macsim I agree that this is a specific problem of this module.
    Unfortunately, I don't have time for a proper solution. But here is a quick fix: https://git.drupalcode.org/issue/pwa-3404421/-/commit/adbea176cc0ad51a02...
    With this patch, the fallback URLs can be overridden via the settings.php. No icon should be uploaded in the backend for this to work.

    An acceptable solution for me would be to replace the file upload field in the ManifestConfigurationForm with three path fields, similar to the Theme Settings form for the favicon and logo.

Production build 0.71.5 2024