Commit:    5c6479d2383365ecff2d97f82ee632de196f3757
Author:    Anatol Belski <[email protected]>         Tue, 12 May 2015 14:42:57 +0200
Parents:   cb5a1222926758f5c2a70bf280bd77934116a4d3
Branches:  master pecl_legacy

Link:       
http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=5c6479d2383365ecff2d97f82ee632de196f3757

Log:
basic fetching /json/vendor/foo.json

Changed paths:
  M  client/include/PickleDb.php
  M  client/include/PickleWeb.php


Diff:
diff --git a/client/include/PickleDb.php b/client/include/PickleDb.php
index 621e387..600cd01 100644
--- a/client/include/PickleDb.php
+++ b/client/include/PickleDb.php
@@ -71,6 +71,10 @@ class PickleDb extends \SQLite3
        {
                $fname = $this->buildUriLocalPath($uri);
 
+               if (!file_exists($fname)) {
+                       return true;
+               }
+
                return unlink($fname);
        }
 
diff --git a/client/include/PickleWeb.php b/client/include/PickleWeb.php
index 8a3c5f9..a6b0ca6 100644
--- a/client/include/PickleWeb.php
+++ b/client/include/PickleWeb.php
@@ -59,6 +59,7 @@ class PickleWeb
                        throw new \Exception("No provider includes found");
                }
 
+               $this->db->delUri($uri); /* XXX pure dev stuff, remove in prod 
*/
                if (!$this->db->uriExists($uri)) {
                        $this->updatesAvailableFlag = true;
                } else {
@@ -93,10 +94,16 @@ class PickleWeb
        }
 
 
-       protected function diffProviders($remote, $local)
+       protected function diffProviders(array $remote, array $local)
        {
                $ret = array();
 
+               if (empty($remote)) {
+                       return array();
+               } else if (empty($local)) {
+                       return $remote;
+               }
+
                foreach ($remote as $vendor => $sha) {
                        if (isset($local[$vendor]) && $local[$vendor] != $sha) {
                                $ret[$vendor] = $sha;
@@ -105,6 +112,7 @@ class PickleWeb
 
                return $ret;
        }
+
        public function fetchProviderUpdates()
        {
                $ret = array();
@@ -117,12 +125,15 @@ class PickleWeb
 
                        $pkgs = $this->db->getUriJson($uri);
                        if (!is_array($pkgs) || !isset($pkgs["providers"]) || 
!is_array($pkgs["providers"]) || empty($pkgs["providers"])) {
+                               /* local doesn't exist, just take the remote 
version*/
                                $this->db->saveUriJson($uri, $pkgs_new);
                                $ret = array_merge($ret, 
$pkgs_new["providers"]);
                                continue;
                        }
 
-                       $this->db->saveUriJson($uri, $pkgs_new);
+                       if (!$this->db->saveUriJson($uri, $pkgs_new)) {
+                               throw new \Exception("Failed to save '$uri'");
+                       }
 
                        $ret = array_merge($ret, 
$this->diffProviders($pkgs_new["providers"], $pkgs["providers"]));
                }
@@ -130,12 +141,45 @@ class PickleWeb
                return $ret;
        }
 
+       public function diffTags(array $remote, array $local)
+       {
+               $ret = array();
+
+               if (empty($remote)) {
+                       return array();
+               } else if (empty($local)) {
+                       return $remote;
+               }
+
+               foreach ($remote as $tag => $data) {
+                       if (!isset($local[$tag])) {
+                               $ret[$tag] = $data;
+                       }
+               }
+
+               return $ret;
+       }
+
        public function getNewTags()
        {
                $provs = $this->fetchProviderUpdates();
+               $ret = array();
+
+               /* $name the ext name is, vendor/foo it looks like */
+               foreach ($provs as $name => $sha) {
+                       $uri = "/json/$name.json";
 
+                       $remote = (array)$this->fetchUriJson($uri);
+                       $local = (array)$this->db->getUriJson($uri);
 
-               return $provs;
+                       if (!$this->db->saveUriJson($uri, $remote)) {
+                               throw new \Exception("Failed to save '$uri'");
+                       }
+
+                       $ret = array_merge($ret, $this->diffTags($remote, 
$local));
+               }
+
+               return $ret;
        }
 
        public function pingBack($data)


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to