From 25b99959b9e66d00681092977c23b5df32ead5f4 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 11 May 2015 11:38:17 +0200 Subject: [PATCH] fix saveToCache() usage; move hook controllers around --- app/Controller/Github.php | 2 +- app/Controller/Github/{Hook.php => Hook/Receive.php} | 6 +++--- .../Github/{Repo/Hook.php => RepoHook.php} | 12 +++++++----- app/Github/API/Call.php | 4 ++-- app/Github/API/Repos/ReadContents.php | 2 +- app/Github/API/Repos/ReadRepo.php | 2 +- app/Github/API/Users/ReadAuthUser.php | 2 +- app/views/github/repo.phtml | 4 ++-- config/routes.ini | 4 ++-- 9 files changed, 20 insertions(+), 18 deletions(-) rename app/Controller/Github/{Hook.php => Hook/Receive.php} (96%) rename app/Controller/Github/{Repo/Hook.php => RepoHook.php} (88%) diff --git a/app/Controller/Github.php b/app/Controller/Github.php index 5933fcd..0c38bd7 100644 --- a/app/Controller/Github.php +++ b/app/Controller/Github.php @@ -58,7 +58,7 @@ abstract class Github implements Controller if ($repo->hooks) { foreach ($repo->hooks as $hook) { if ($hook->name === "web" && $hook->config->url === $this->github->getConfig()->hook->url) { - return $hook->id; + return $hook; } } } diff --git a/app/Controller/Github/Hook.php b/app/Controller/Github/Hook/Receive.php similarity index 96% rename from app/Controller/Github/Hook.php rename to app/Controller/Github/Hook/Receive.php index bbfab2a..48e10ae 100644 --- a/app/Controller/Github/Hook.php +++ b/app/Controller/Github/Hook/Receive.php @@ -1,6 +1,6 @@ checkToken()) { @@ -14,7 +14,8 @@ class Hook extends Github "path" => "./github/repo/" . $args["owner"] ."/". $args["name"], "query" => "modal=hook&hook=" . $args["action"] ])); - } else switch ($args["action"]) { + } else { + switch ($args["action"]) { case "upd": $this->updateHook($args["owner"], $args["name"]); break; @@ -26,6 +27,7 @@ class Hook extends Github case "del": $this->delHook($args["owner"], $args["name"]); break; + } } } } @@ -48,8 +50,8 @@ class Hook extends Github $this->github->fetchRepo("$owner/$repo", function($repo) { $this->github->fetchHooks($repo->full_name, function($hooks) use($repo) { $repo->hooks = $hooks; - if (($id = $this->checkRepoHook($repo))) { - $this->github->deleteRepoHook($repo->full_name, $id, function() use($repo) { + if (($hook = $this->checkRepoHook($repo))) { + $this->github->deleteRepoHook($repo->full_name, $hook->id, function() use($repo) { if (($cache = $this->github->getCacheStorage())) { $cache->del($this->github->getCacheKey("hooks:" . $repo->full_name)); } diff --git a/app/Github/API/Call.php b/app/Github/API/Call.php index f40e486..3615851 100644 --- a/app/Github/API/Call.php +++ b/app/Github/API/Call.php @@ -96,7 +96,7 @@ abstract class Call new QueryString($this->args)); } - function readFromCache(&$cached = null, &$ttl = null) { + function readFromCache(array &$cached = null, &$ttl = null) { if (empty($this->args["fresh"]) && ($cache = $this->api->getCacheStorage())) { $key = $this->getCacheKey(); return $cache->get($key, $cached, $ttl); @@ -104,7 +104,7 @@ abstract class Call return false; } - function saveToCache($fresh) { + function saveToCache(array $fresh) { if (($cache = $this->api->getCacheStorage())) { if (isset($this->config->storage->cache->{$this}->ttl)) { $ttl = $this->config->storage->cache->{$this}->ttl; diff --git a/app/Github/API/Repos/ReadContents.php b/app/Github/API/Repos/ReadContents.php index 02b28fb..fde19b8 100644 --- a/app/Github/API/Repos/ReadContents.php +++ b/app/Github/API/Repos/ReadContents.php @@ -18,7 +18,7 @@ class ReadContents extends Call if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) { throw new RequestException($response); } - $this->saveToCache($json); + $this->saveToCache([$json]); $callback($json); return true; }); diff --git a/app/Github/API/Repos/ReadRepo.php b/app/Github/API/Repos/ReadRepo.php index e432d2a..775a9ee 100644 --- a/app/Github/API/Repos/ReadRepo.php +++ b/app/Github/API/Repos/ReadRepo.php @@ -18,7 +18,7 @@ class ReadRepo extends Call if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) { throw new RequestException($response); } - $this->saveToCache($json); + $this->saveToCache([$json]); $callback($json); return true; }); diff --git a/app/Github/API/Users/ReadAuthUser.php b/app/Github/API/Users/ReadAuthUser.php index 5feb7c8..6cb6de0 100644 --- a/app/Github/API/Users/ReadAuthUser.php +++ b/app/Github/API/Users/ReadAuthUser.php @@ -18,7 +18,7 @@ class ReadAuthUser extends Call if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) { throw new RequestException($response); } - $this->saveToCache($json); + $this->saveToCache([$json]); $callback($json); return true; }); diff --git a/app/views/github/repo.phtml b/app/views/github/repo.phtml index 1b7a640..6000cf7 100644 --- a/app/views/github/repo.phtml +++ b/app/views/github/repo.phtml @@ -120,13 +120,13 @@
diff --git a/config/routes.ini b/config/routes.ini index ad01201..cb28b1e 100644 --- a/config/routes.ini +++ b/config/routes.ini @@ -7,7 +7,7 @@ GET[] = /pages/{page} [Github\Callback] GET[] = /github/callback -[Github\Hook] +[Github\Hook\Receive] POST[] = /github/hook [Github\Index] @@ -17,7 +17,7 @@ GET[] = /github GET[] = /github/repo/{owner}/{name} GET[] = /github/repo/{owner}/{name}/{page} -[Github\Repo\Hook] +[Github\RepoHook] POST[] = /github/repo/{owner}/{name}/hook/{action} ; if the user has to re-authenticate, we'll receive a GET because of a redirect GET[] = /github/repo/{owner}/{name}/hook/{action} -- 2.30.2