Files no longer sent to build in fastbuilds

Created on 11 May 2023, over 1 year ago
Updated 2 October 2023, about 1 year ago

Problem/Motivation

Files no longer sent to 'build' in fastbuilds. Files are sent to "preview" during fastbuilds.

I've traced this to gatsby.module, when checking if the entity is published. Files do not have the isPublished method and are therefore never logged for the build server.

Steps to reproduce

Create a media type of "Image" with a file upload field.
Configure Gatsby to send Media and File entities.
Create a media entity and upload an image file, and save the media as published.
View Gatsby Log - 3 entries exist. 2 entries for the Media insert, one each for build and preview. One entry for the File update (as insert happened on the temporary file upload), to preview only.

Proposed resolution

Add "file" to special types. The module is already returning early if `_gatsby_will_process_file` returns false.

Remaining tasks

Add patch.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States lisagodare@gmail.com

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

Comments & Activities

  • Issue created by @lisagodare@gmail.com
  • Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • @lisagodaregmailcom opened merge request.
  • Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • @lisagodaregmailcom opened merge request.
  • Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    @lisagodare, the hook_insert is incorrect in the patch.

  • Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States lisagodare@gmail.com

    Well that's embarrassing. Thanks for calling it out!

  • Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • πŸ‡ΊπŸ‡ΈUnited States steyep

    I'm not sure that having a $special_types array is sufficient. It does allow for the builds to be triggered but the GatsbyEntityLogger still only marks a build as published if it has the isPublished method and that method returns true (https://git.drupalcode.org/project/gatsby/-/blob/2.0.x/src/GatsbyEntityL...). This can prevent the files from being available to Gatsby when builds are triggered.

    I wonder if a more extensible approach might be to dispatch an event that allows other modules to determine if an entity is published. At the very least, I would suggest adding an isEntityPublished method to the GatsbyPreview service that is used instead of relying on a method that doesn't exist for all supported entities. Something like this:

    /**
     * Determine if a given entity is considered "published".
     *
     * @param \Drupal\Core\Entity\EntityInterface $entity
     *   The entity to be tested.
     *
     * @return bool
     *   Returns TRUE if published; FALSE otherwise.
     */
    public function isEntityPublished(EntityInterface $entity) {
      if ($entity->getEntityTypeId() === 'file' && $entity instanceof FileInterface) {
        return $entity->isPermanent();
      }
      if (is_callable([$entity, 'isPublished'])) {
        return call_user_func([$entity, 'isPublished']);
      }
      return FALSE;
    }
    
Production build 0.71.5 2024