From 0624492bcf28308982e4e3116adcfbc8da29799e Mon Sep 17 00:00:00 2001 From: Juha Sippola Date: Mon, 21 Sep 2015 16:20:56 +0300 Subject: Qt Metrics 2 (v0.28): Branch archiving MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added buttons to archive (and restore) a branch on the admin pages. Added field 'archived' to the branch table in the database. Change-Id: Idefddd15df02014ce70c5c4f981eb5938c4bf5f7 Reviewed-by: Tony Sarajärvi --- non-puppet/qtmetrics2/index.php | 50 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'non-puppet/qtmetrics2/index.php') diff --git a/non-puppet/qtmetrics2/index.php b/non-puppet/qtmetrics2/index.php index 02a232f..fc4e3fb 100644 --- a/non-puppet/qtmetrics2/index.php +++ b/non-puppet/qtmetrics2/index.php @@ -34,7 +34,7 @@ /** * Qt Metrics API - * @since 15-09-2015 + * @since 17-09-2015 * @author Juha Sippola */ @@ -712,6 +712,54 @@ $app->delete('/api/branch/:branch', function($branch) use($app) } })->name('delete_branch'); +/** + * API route: /api/branch/archive (PUT) - authenticated + */ + +$app->add(new HttpBasicAuthRoute('Protected Area', 'api/branch/archive')); +$app->put('/api/branch/archive/:branch', function($branch) use($app) +{ + $branch = strip_tags($branch); + $branches = array(); + $query = Factory::db()->getBranches(); + foreach($query as $item) { + $branches[] = $item['name']; + } + if (in_array($branch, $branches)) { + $result = Factory::dbAdmin()->archiveBranch($branch); + if ($result) + $app->response()->status(200); + else + $app->response()->status(404); + } else { + $app->response()->status(404); + } +})->name('archive_branch'); + +/** + * API route: /api/branch/restore (PUT) - authenticated + */ + +$app->add(new HttpBasicAuthRoute('Protected Area', 'api/branch/restore')); +$app->put('/api/branch/restore/:branch', function($branch) use($app) +{ + $branch = strip_tags($branch); + $branches = array(); + $query = Factory::db()->getBranches(); + foreach($query as $item) { + $branches[] = $item['name']; + } + if (in_array($branch, $branches)) { + $result = Factory::dbAdmin()->restoreBranch($branch); + if ($result) + $app->response()->status(200); + else + $app->response()->status(404); + } else { + $app->response()->status(404); + } +})->name('restore_branch'); + /** * API route: /api/data (DELETE) - authenticated */ -- cgit v1.2.3