Problem/Motivation

When importing a file entity whose URI points to an external URL, such as an HTTPS URL containing an image, the PhysicalFile processor attempts to retrieve a Drupal stream wrapper for the URI.

StreamWrapperManagerInterface::getViaUri() returns FALSE when no registered stream wrapper can handle the URI. The processor then calls dirname() on that value, causing the following fatal error:

Error: Call to a member function dirname() on false in Drupal\entity_share_client\Plugin\EntityShareClient\Processor\PhysicalFile->processEntity()

External file URLs may intentionally remain remote and therefore may not have a Drupal stream wrapper or a physical file destination on the client.

Steps to reproduce

  1. Configure an Entity Share server containing a file entity.
  2. Set the file URI to an external URL, for example:
    https://example.com/images/example.jpg
  3. Configure the Entity Share client to import physical files.
  4. Import an entity that references the external file.
  5. Observe that the import fails in the PhysicalFile processor because getViaUri() returns FALSE and dirname() is called on that value.

Proposed resolution

Check the return value of getViaUri() before using the stream wrapper.

If no stream wrapper is available, keep the external URI unchanged and skip the physical file download instead of causing a fatal error.

$stream_wrapper = $this->streamWrapperManager->getViaUri($remote_file_uri);

// External file URLs, such as images stored on another website, may not
// have a registered Drupal stream wrapper on the client. In that case,
// there is no physical file destination that Entity Share can determine.
// Keep the remote URI unchanged and skip the file download instead of
// calling dirname() on FALSE.
if ($stream_wrapper === FALSE) {
  return;
}

It may also be appropriate to only skip known external schemes, such as http and https, while throwing a descriptive exception for invalid or unsupported local schemes.

Remaining tasks

  • Add automated test coverage for an external HTTPS file URI without a registered stream wrapper.
  • Confirm that the external URI remains unchanged after the import.
  • Confirm that the parent entity import completes successfully.
  • Confirm that no physical file download is attempted.
  • Decide whether unsupported non-external schemes should be skipped or produce a descriptive exception.

User interface changes

None.

API changes

No public API changes are expected.

The behavior of the PhysicalFile processor will change so that external file URIs without a registered stream wrapper do not cause a fatal error.

Data model changes

None.

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

charlliequadros created an issue. See original summary.

charlliequadros’s picture

Status: Active » Needs review