[PHP-WEBMASTER] [web-downloads] main: Fix copying in php command

Author: Shivam Mathur (shivammathur)
Date: 2025-01-30T09:29:13+05:30

Commit: Fix copying in php command · php/web-downloads@d36c52d · GitHub
Raw diff: https://github.com/php/web-downloads/commit/d36c52d32ef4121a15b6b15b2450a5308633173e.diff

Fix copying in php command

Changed paths:
  M src/Console/Command/PhpCommand.php

Diff:

diff --git a/src/Console/Command/PhpCommand.php b/src/Console/Command/PhpCommand.php
index 6ed8a42..5eae612 100644
--- a/src/Console/Command/PhpCommand.php
+++ b/src/Console/Command/PhpCommand.php
@@ -135,7 +135,7 @@ private function copyBuildsToArchive(string $directory, string $version): void
         foreach ($files as $file) {
             $fileVersion = $this->getFileVersion($file);
             if ($fileVersion) {
- copy($directory . '/' . basename($file), $directory . '/archive/' . basename($file));
+ copy($directory . '/' . basename($file), $directory . '/archives/' . basename($file));
                 if (version_compare($fileVersion, $version) < 0) {
                     unlink($file);
                 }
@@ -252,17 +252,14 @@ private function updateLatestBuilds($releases, $directory): void
             mkdir($directory . '/latest', 0755, true);
         }
         foreach ($releases as $versionShort => $release) {
- foreach ($release as $value) {
- $filePath = $value['path'] ?? $value['zip']['path'] ?? null;
- if($filePath === null) {
- continue;
- } else {
- $filePath = basename($filePath);
+ array_walk_recursive($release, function ($value, $key) use($directory, $versionShort, $release) {
+ if ($key === 'path') {
+ $filePath = basename($value);
+ $latestFileName = str_replace($release['version'], $versionShort, $filePath);
+ $latestFileName = str_replace('.zip', '-latest.zip', $latestFileName);
+ copy($directory . '/' . $filePath, $directory . '/latest/' . $latestFileName);
                 }
- $latestFileName = str_replace($release['version'], $versionShort, $filePath);
- $latestFileName = str_replace('.zip', '-latest.zip', $latestFileName);
- copy($directory . '/' . $filePath, $directory . '/latest/' . $latestFileName);
- }
+ });
         }
     }