Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime Composer utility \Composer\InstalledVersions::getInstallPath( 'woocommerce/action-scheduler' ) does not work with jetpack-autoloader #33831

Open
remcotolsma opened this issue Oct 27, 2023 · 3 comments
Labels
[Package] Autoloader [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Low [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! Triaged [Type] Bug When a feature is broken and / or not performing as intended

Comments

@remcotolsma
Copy link

remcotolsma commented Oct 27, 2023

Impacted plugin

None / Other

Quick summary

To load Action Scheduler into one of our plugins we use the following code:

$action_scheduler_path = InstalledVersions::getInstallPath( 'woocommerce/action-scheduler' );

require_once $action_scheduler_path . '/action-scheduler.php';

This works if we use the default Composer autoload file:

require_once __DIR__ . '/vendor/autoload.php';

If we switch to https://github.com/automattic/jetpack-autoloader we get an error:

Fatal error: Uncaught Error: Class "Composer\InstalledVersions" not found

Or:

Fatal error: Uncaught OutOfBoundsException: Package "woocommerce/action-scheduler" is not installed 

Steps to reproduce

I have created a test plugin to reproduce the issue:
https://github.com/remcotolsma/reproduce-composer-utility-issue-with-jetpack-autoloader

A clear and concise description of what you expected to happen.

It would be nice if the runtime Composer utilities still work with the Jetpack autoloader.

What actually happened

The runtime Composer utilities are not available or the utility classes are not aware of the packages loaded via the Jetpack autoloader.

Impact

Some (< 50%)

Available workarounds?

There is no user impact

Platform (Simple and/or Atomic)

No response

Logs or notes

No response

@remcotolsma remcotolsma added [Type] Bug When a feature is broken and / or not performing as intended Needs triage Ticket needs to be triaged labels Oct 27, 2023
@remcotolsma remcotolsma changed the title Runtime Composer utility \Composer\InstalledVersions::getInstallPath( 'woocommerce/action-scheduler' ); does not work with jetpack-autoloader Runtime Composer utility \Composer\InstalledVersions::getInstallPath( 'woocommerce/action-scheduler' ) does not work with jetpack-autoloader Oct 27, 2023
@anomiex
Copy link
Contributor

anomiex commented Oct 27, 2023

At first glance, one way to fix this could involve merging data similar to what Composer stores to vendor/composer/installed.php via Composer\InstalledVersions::reload(). But first we'd need to correctly merge together the data from each jetpack-autoloader-using plugin so the versions and paths are correct and identify a good place to merge the data in.

As a workaround for now, you might try using $jetpack_autoloader_loader->find_class_file() to find a relevant class from the package you're working with.

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! Triaged and removed Needs triage Ticket needs to be triaged labels Oct 27, 2023
@cuemarie cuemarie added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Nov 2, 2023
Copy link
Contributor

github-actions bot commented May 1, 2024

This issue has been marked as stale. This happened because:

  • It has been inactive for the past 6 months.
  • It hasn’t been labeled `[Pri] BLOCKER`, `[Pri] High`, `[Type] Feature Request`, `[Type] Enhancement`, `[Type] Janitorial`, `Good For Community`, `[Type] Good First Bug`, etc.

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.

@remcotolsma
Copy link
Author

As a workaround for now, you might try using $jetpack_autoloader_loader->find_class_file() to find a relevant class from the package you're working with.

I don't think this will work in our use case. We need to include the woocommerce/action-scheduler/action-scheduler.php file. It appears that this file does not contain a class: https://github.com/woocommerce/action-scheduler/blob/cdb3ec83e3b914cdf607b68313e80c80b4566de0/action-scheduler.php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Autoloader [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Low [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! Triaged [Type] Bug When a feature is broken and / or not performing as intended
Projects
Development

No branches or pull requests

4 participants