Explorar el Código

Merge pull request #1078 from colinodell/retain-funding-sort-order

Retain original funding sort order on website (fixes #1077)
Jordi Boggiano hace 4 años
padre
commit
5cd36ab2dc
Se han modificado 1 ficheros con 18 adiciones y 11 borrados
  1. 18 11
      src/Packagist/WebBundle/Entity/Version.php

+ 18 - 11
src/Packagist/WebBundle/Entity/Version.php

@@ -271,7 +271,7 @@ class Version
             $data['support'] = $this->getSupport();
         }
         if ($this->getFunding()) {
-            $data['funding'] = $this->getFunding();
+            $data['funding'] = $this->getFundingSorted();
         }
         if ($this->getReleasedAt()) {
             $data['time'] = $this->getReleasedAt()->format('Y-m-d\TH:i:sP');
@@ -631,16 +631,6 @@ class Version
      */
     public function setFunding($funding)
     {
-        // sort records when storing so to help the V2 metadata compression algo
-        if ($funding) {
-            usort($funding, function ($a, $b) {
-                $keyA = ($a['type'] ?? '') . ($a['url'] ?? '');
-                $keyB = ($b['type'] ?? '') . ($b['url'] ?? '');
-                
-                return $keyA <=> $keyB;
-            });
-        }
-
         $this->funding = $funding;
     }
 
@@ -654,6 +644,23 @@ class Version
         return $this->funding;
     }
 
+    /**
+     * Get funding, sorted to help the V2 metadata compression algo
+     */
+    public function getFundingSorted()
+    {
+        if ($this->funding === null) {
+            return null;
+        }
+
+        return usort($this->funding, function ($a, $b) {
+            $keyA = ($a['type'] ?? '') . ($a['url'] ?? '');
+            $keyB = ($b['type'] ?? '') . ($b['url'] ?? '');
+
+            return $keyA <=> $keyB;
+        });
+    }
+
     /**
      * Set createdAt
      *