Problem/Motivation

Exception: Warning: file_get_contents(/tmp/site/app/libraries/photoswipe/photoswipe.json): Failed to open stream: No such file or directory photoswipe_library_info_alter()()

Steps to reproduce

Once you upgrade to PHP 8.0, Issue starts appearing

Proposed resolution

Reaplce file_get_contents(DRUPAL_ROOT . '/libraries/photoswipe/photoswipe.json')
With '/' . libraries_get_path('photoswipe') . '/photoswipe.json'

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork photoswipe-3326509

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

abhijityadav created an issue. See original summary.

anybody’s picture

Issue tags: -failed to open stream +PHP8.0

Very unsure if the proposed resolution is correct.

Is /tmp/site/app/ really your Drupal installation path?
Does photoswipe/photoswipe.json exist in your drupal libraries folder?

abhijityadav’s picture

StatusFileSize
new2.75 KB

Patch created by replacing file_get_contents(DRUPAL_ROOT . '/libraries/photoswipe/photoswipe.json')
With '/' . libraries_get_path('photoswipe') . '/photoswipe.json'

liam morland’s picture

Issue tags: -PHP8.0 +PHP 8.0
anybody’s picture

Status: Active » Needs review
anybody’s picture

Status: Needs review » Postponed

I guess this might be fixed by: #3330747: Replace libraries_get_path with the new Core API

Still, I think the patch is not a really good and clean solution here.

anybody’s picture

Version: 3.x-dev » 4.x-dev

3.x is now 4.x - could someone please check, if the issue still exists with PHP >=8.0?

@abhijityadav?

anybody’s picture

adamevertsson’s picture

I just started using Photoswipe and yes, the error is there, filling the log.

Warning: file_get_contents(/Applications/XAMPP/xamppfiles/htdocs/web/libraries/photoswipe/photoswipe.json): Failed to open stream: No such file or directory in photoswipe_library_info_alter() (line 120 of /Applications/XAMPP/xamppfiles/htdocs/web/modules/contrib/photoswipe/photoswipe.module)

PHP: 8.1.17
Drupal: 10.1.4

Note: I do not have a photoswipe.json file in my libraries folder. I followed the instructions for manual installation:

- Download the "PhotoSwipe-5.3.8" zip file
- Unzip and place the contents of the unzipped "PhotoSwipe-5.3.8" folder into "library/photoswipe" folder so that the folder structure is: library/photoswipe/dist/photoswipe.esm.js
- (Optional) See how to manually require the photoswipe dynamic caption plugin here
- Check the status report for errors

weres’s picture

Yes, I see the same as #9. Same error, same conditions

anybody’s picture

Assigned: Unassigned » grevil
Status: Postponed » Active
anybody’s picture

Version: 4.x-dev » 5.x-dev
Issue tags: +Needs backport

@AdamEvertsson and @Weres what's the correct folder structure in your case, if
/Applications/XAMPP/xamppfiles/htdocs/web/libraries/photoswipe/photoswipe.json is wrong?
Where can we find the photoswipe.json in your case?

Let's first fix this in 5.x and afterwards in 4.x

grevil’s picture

Issue tags: -PHP 8.0, -Needs backport

@AdamEvertsson and @Weres please take a closer look at the versions on the site! My guess is, your composer.json doesn't contain
minimum-stability": "beta" and therefore, composer will automatically require photoswipe v4 (because photoswipe v5 is still in beta), but you are following the installation instructions for photoswipe 5, which causes the issue:

I do not have a photoswipe.json file in my libraries folder. I followed the instructions for manual installation:

- Download the "PhotoSwipe-5.3.8" zip file

That's why Photoswipe 5 doesn't have a photoswipe.json.

grevil’s picture

Though I understand your troubles, as you wouldn't expect the first installation instruction on the module page to be a beta release (although photoswipe 5 is pretty much stable).

But thanks to you guys I found a message issue!

grevil’s picture

Assigned: grevil » anybody
Status: Active » Needs review

grevil’s picture

Adjusted the status report message for 5.x. Please review.

For everyone else running into this issue, either enable minimum-stability": "beta" in your composer.json and require the photoswipe 5 module OR follow the "Photoswipe 4 library installation" on the module page.

I'll update the page text, so it will be more obvious.

anybody’s picture

Assigned: anybody » grevil
Status: Needs review » Needs work

Nice one @Grevil! Left some final comments. Afterwards we should merge this into dev and ask the others here, if the message appears for them and (indirectly) solves the issue.

grevil’s picture

Status: Needs work » Needs review

Afterwards we should merge this into dev and ask the others here, if the message appears for them and (indirectly) solves the issue.

No, this won't fix their issue, as the changes were not done in 4.x. 4.x is minimally maintained, and I don't see, that such an issue would be important enough. If you disagree, I can create another branch and make a different implementation for 4.x.

Resolved your comments. Please ignore the failing pipeline in https://git.drupalcode.org/project/photoswipe/-/pipelines/24170. Since the switch to Gitlab CI, @dinazaur's custom "drupalci.yml" doesn't apply anymore.

anybody’s picture

Assigned: grevil » Unassigned
Status: Needs review » Postponed (maintainer needs more info)

As sorry I didn't see that!

So let's merge this one and for the reporters here, back to #13. So this is then fixed by documentation for 5.x and "won't fix" (user error) for 4.x, if #13 is the issue.

Anyway I hope for 5.x to become rc or even stable soon.

  • Anybody committed 99ea723a on 5.x authored by Grevil
    Issue #3326509 by abhijityadav: Failed to open stream: No such file or...
anybody’s picture

agoradesign’s picture

After updating from beta1 to rc1 I see errors on the status report page:

"Photoswipe v5 currently only supports photoswipe library version minimum: 5.2.1
You need to install a compatible version!"

Indeed I've the latest Photoswipe 5.4.1 (and $library_version is indeed "5.4.1")

On looking at the latest commit (https://git.drupalcode.org/project/photoswipe/-/commit/99ea723a66fc90e10...), I see that the version_compare() was changed, from:

if (version_compare($library_version, $min_req_version, '<')) {

to

if (version_compare($library_version, $min_req_version) >= 0) {

And this checks the opposite of what we want. see example 1 here: https://www.php.net/manual/en/function.version-compare.php

Proposed resolution

Revert the concerning line to

if (version_compare($library_version, $min_req_version, '<')) {

anybody’s picture

Thanks @agoradesign we had a discussion about that line before :D We'll take a look soon and fix it! Thanks!

(But it's unrelated to this issue)

agoradesign’s picture

you're welcome... yeah, I know - but I felt it's ok to leave a comment here about this tiny problem. at least it was caused by this issue's commit :D

anybody’s picture

Assigned: Unassigned » grevil
Status: Postponed (maintainer needs more info) » Needs work

Sorry YES my fault! I thought it was a different issue where it happened! Then it's right here!
@Grevil: Please resolve by reverting that line.

  • Grevil committed 0a22095e on 5.x
    Follow up quick fix to Issue #3326509: Failed to open stream: No such...
grevil’s picture

Assigned: grevil » Unassigned
Status: Needs work » Fixed

Thanks, @agoradesign! Indeed, an unwise change, my apologies.

agoradesign’s picture

Such things may happen... version_compare() can be quite confusing to read

Status: Fixed » Closed (fixed)

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