Problem/Motivation

When you're trying to unpack Zip archive using 'plugin.manager.archiver' service, it will throw this error if PHP Zip extension is not installed.

Steps to reproduce

$archiver_manager = \Drupal::service('plugin.manager.archiver');
$archiver_manager->getInstance(['filepath' => $path_to_zip]);

Since the Drupal CI environment does have the PHP-zip extension installed (See CI-output snippet below), this is untestable (at least without jumping through hoops)

00:00:49.786 As there is no 'unzip' command installed zip files are being unpacked using the PHP zip extension.
00:00:49.786 This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.
00:00:49.786 Installing 'unzip' may remediate them.

Proposed resolution

@larowlan suggests in comment #10 two approaches for the issue:

1) Either the ArchiveInterface plugin system is extented to allow plugins to declare their required extensions

or

2) We make core require the zip extension, this would require patching both system_requirements and composer.json

In #4 @Niklan tried solution #2, but commented in #7:

Even after creating a patch that adds requirement to the extension in comment #4, the error still appearing.

As far as I (=Spokje) can tell an "actual" solution is being done in #2850794: Unable to open Zip archive using ArchiverZip.

This issue is merely to prevent/soften the error, by telling Drupal it hasn't got the capabilities to handle ZIP-files when there's no PHP-Zip extension present.

This is done by implementing the system_archiver_info_alter-hook.

Also, as per @longwave's suggestion in comment #16, we add a suggest entry to composer.json to suggest the user to install/enable the PHP-Zip extension.

Remaining tasks

1. Create patch/MR.
2. Review.
3. Commit.
5. Let unicorns and rainbows rule the universe once more.

Issue fork drupal-3163123

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mxmilkiib created an issue. See original summary.

mxmilkiib’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)

That was me needing to install the php zip dependency!

Niklan’s picture

Project: Google Webfonts Helper » Drupal core
Version: 8.x-1.0-alpha4 » 9.0.x-dev
Component: Code » base system
Status: Closed (works as designed) » Needs work

Hm, It's actually a core bug.

The Drupal Core doesn't require ext-zip in composer.json file. This leads to this problem.

Niklan’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
369 bytes
Niklan’s picture

I believe the System requirements page also needs to be updated to explicitly tells that Drupal needs PHP Zip extension.

Niklan’s picture

Issue summary: View changes
Niklan’s picture

Things going a bit complicated.

PHP 7.4.8, Zip and ZLib extensions enabled. Still got this error. So this is not the only requirements missing problem.

Status: Needs review » Needs work

The last submitted patch, 4: drupal-zip_extension_requirement-3163123-4.patch, failed testing. View results

andypost’s picture

larowlan’s picture

Issue tags: +Bug Smash Initiative

There are two approaches here:

- either the ArchiverInterface plugin system is extended to allow plugins to declare their required extensions and this is used when creating an instance

- OR -

- we make core require the zip extension, this would require patching both system_requirements and composer.json.

andypost’s picture

Status: Needs work » Needs review
FileSize
590 bytes

At least patch to prevent this

andypost’s picture

FileSize
589 bytes
+++ b/core/modules/system/system.module
@@ -1475,3 +1475,13 @@ function system_path_alias_presave(PathAliasInterface $path_alias) {
+  if (!class_exists('\ZipArchive')) {
+    // PHP Zip extension could be missing.
+    unset($info['zip']);

I was wrong

andypost’s picture

11 is the valid patch

andypost’s picture

Since php 5.5 better to use full class name

Hardik_Patel_12’s picture

Last patch failed to apply for 9.0.x , uploading new patch for 9.0.x kindly review.

longwave’s picture

We could add a suggest entry to composer.json as well?

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Can we update the IS? Would be nice to know what the resolution is and what are the remaining tasks.

And #16 needs to be addressed.

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
933 bytes
334 bytes

Addressed #16.
Added suggest in composer.json

Status: Needs review » Needs work

The last submitted patch, 18: 3163123-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
1.69 KB
1.04 KB
anmolgoyal74’s picture

Status: Needs review » Needs work

The last submitted patch, 21: 3163123-21.patch, failed testing. View results

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
1.69 KB

Updated hash.

Version: 9.0.x-dev » 9.1.x-dev

Drupal 9.0.10 was released on December 3, 2020 and is the final full bugfix release for the Drupal 9.0.x series. Drupal 9.0.x will not receive any further development aside from security fixes. Sites should update to Drupal 9.1.0 to continue receiving regular bugfixes.

Drupal-9-only bug reports should be targeted for the 9.1.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.2.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mxmilkiib’s picture

Any chance the patch could be updated please? It fails to apply on 9.1.3.

quietone’s picture

Still needs an issue summary update. In order to review the patch and check that it is doing what is planned the IS needs to have, at least, a proposed resolution section completed.

guilhermevp’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update
quietone’s picture

Issue summary: View changes
Status: Needs review » Needs work

@guilhermevp, thank you very much.

I read the issue and found that the question in #16 has not been answered. Setting to NW for that and the fact that the patch needs a reroll.

guilhermevp’s picture

Re-rolled patch #23

Spokje’s picture

Assigned: Unassigned » Spokje
Spokje’s picture

Version: 9.1.x-dev » 9.3.x-dev

Not quite sure why this issue is still stuck on 9.1.x, updated Version to 9.3.x.

Since only the creator of a MR can change the branch-to-merge-to I'm opening a new MR based on 9.3.x.

Spokje’s picture

Made 4 changes:

1) Moved the suggest bit from composer.json to core/composer.json. This because it seemed to me that all the requiring of PHP extensions is done over there.
2) There's no core/composer.lock, but even if there was, adding a suggest doesn't show up in the corresponding composer.lock file.
2) Did a composer update drupal/core to pull in our changed core/composer.json.
3) The correct capitalisation in the system_archiver_info_alter-hook is Zip.
4) Reworded the suggest bit in core/composer.json.

Spokje’s picture

Issue summary: View changes

Updated the IS with what I believe is going on.

Spokje’s picture

Assigned: Spokje » Unassigned
Status: Needs work » Needs review
quietone’s picture

#16 is now addressed and the solution here is one of the two suggested in #10. Unfortunately, the MR needs an update.

Spokje’s picture

Thanks @quietone.

  • Merged HEAD of 9.3.x into the MR.
  • Did a composer update drupal/core to pull in our changed core/composer.json.

Test currently running.

Spokje’s picture

Rerolled against the latest 9.3.x

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

Version: 9.5.x-dev » 10.0.x-dev

It makes sense to improve as drupal-CI runners mentions in every CI-run

As there is no 'unzip' nor '7z' command installed zip files are being unpacked using the PHP zip extension.
This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.
Installing 'unzip' or '7z' (21.01+) may remediate them.

Spokje’s picture

nod_’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

need a reroll

Spokje’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
1.79 KB
Spokje’s picture

nod_’s picture

Status: Needs review » Reviewed & tested by the community

thanks :)
Feeling luck so RTBC

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Makes sense to not add this if it's not available, and to add the extension to suggestions, but the patch doesn't apply on 10.1

  • longwave committed 7715163 on 10.0.x
    Issue #3163123 by Spokje, anmolgoyal74, andypost, guilhermevp, Niklan,...

  • longwave committed c9c2ee1 on 10.1.x
    Issue #3163123 by Spokje, anmolgoyal74, andypost, guilhermevp, Niklan,...
longwave’s picture

Status: Needs work » Fixed
Issue tags: -Needs reroll

#47 applied to 10.1.x, and #48 to 10.0.x; committed to both branches. Thanks!

Status: Fixed » Closed (fixed)

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