com web/rmtools: simplify data structs, give flat arrays for tags and providers: client/include/PickleDb.php client/include/PickleWeb.php
| From: | Anatol Belski | Date: | Tue, 12 May 2015 13:22:28 +0000 |
| Subject: | com web/rmtools: simplify data structs, give flat arrays for tags and providers: client/include/PickleDb.php client/include/PickleWeb.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-25972@lists.php.net to get a copy of this message | ||
Commit: 33efad48308cdc8c9e92449557bca3b60001e945
Author: Anatol Belski <ab@php.net> Tue, 12 May 2015 15:22:28 +0200
Parents: 5c6479d2383365ecff2d97f82ee632de196f3757
Branches: master pecl_legacy
Link: http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=33efad48308cdc8c9e92449557bca3b60001e945
Log:
simplify data structs, give flat arrays for tags and providers
all the necessary data is contained in a tag array itself,
so there's no real need to return the 1:1 data fro mjson
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 600cd01..59c9358 100644
--- a/client/include/PickleDb.php
+++ b/client/include/PickleDb.php
@@ -45,7 +45,7 @@ class PickleDb extends \SQLite3
public function saveUriJson($uri, $data)
{
- $json = json_encode($data);
+ $json = json_encode($data, JSON_PRETTY_PRINT);
return $this->saveUri($uri, $json);
}
diff --git a/client/include/PickleWeb.php b/client/include/PickleWeb.php
index a6b0ca6..b9217a7 100644
--- a/client/include/PickleWeb.php
+++ b/client/include/PickleWeb.php
@@ -98,10 +98,10 @@ class PickleWeb
{
$ret = array();
- if (empty($remote)) {
+ if (!isset($remote["providers"]) || !is_array($remote["providers"]) ||
empty($remote["providers"])) {
return array();
- } else if (empty($local)) {
- return $remote;
+ } else if (!isset($llocal["providers"]) || !is_array($local["providers"]) ||
empty($local["providers"])) {
+ return $remote["providers"];
}
foreach ($remote as $vendor => $sha) {
@@ -118,42 +118,59 @@ class PickleWeb
$ret = array();
foreach ($this->info["provider-includes"] as $uri => $hash) {
- $pkgs_new = $this->fetchUriJson($uri);
- if (!is_array($pkgs_new) || !isset($pkgs_new["providers"]) ||
!is_array($pkgs_new["providers"]) || empty($pkgs_new["providers"])) {
- continue;
- }
-
- $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;
- }
+ $pkgs_new = (array)$this->fetchUriJson($uri);
+ $pkgs = (array)$this->db->getUriJson($uri);
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"]));
+ $ret = array_merge($ret, $this->diffProviders($pkgs_new, $pkgs));
}
return $ret;
}
+ protected function isUniqueTag($name, $version, array $tags)
+ {
+ foreach ($tags as $tag) {
+ if ($tag["name"] == $name && $tag["version"] == $version) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
public function diffTags(array $remote, array $local)
{
$ret = array();
- if (empty($remote)) {
+ if (empty($remote) || !isset($remote["packages"])) {
return array();
- } else if (empty($local)) {
- return $remote;
+ } else if (empty($local) || !isset($local["packages"])) {
+ foreach ($remote["packages"] as $name => $tags) {
+ foreach ($tags as $version => $data) {
+ /* $version is from the tag name, be strict and use the oone from the actual tag data*/
+ if ($this->isUniqueTag($name, $data["version"], $ret)) {
+ $ret[] = $data;
+ }
+ }
+ }
+
+ return $ret;
}
- foreach ($remote as $tag => $data) {
- if (!isset($local[$tag])) {
- $ret[$tag] = $data;
+ foreach ($remote["packages"] as $name => $tags) {
+ if (!isset($local["packages"][$name])) {
+ $ret[$name] = $data;
+ break;
+ }
+
+ foreach ($tags as $version => $data) {
+ if (!isset($local["packages"][$name][$version]) &&
$this->isUniqueTag($name, $data["version"], $ret)) {
+ $ret[] = $data;
+ }
}
}