From 45b4bf6382ad1c9245e9859bea0b26b24fac8459 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 20 Mar 2017 14:08:55 -0700 Subject: [PATCH] Expose category totals in API response Instead of just including the error category names, include the number of errors each category has, to make it easier to collect aggregate stats. This changes the structure from an array to an object, in JSON, but I'm not aware of any clients using these specific fields yet. Change-Id: Iaf942b923a0f4047721055ad9cb48aacc5aa6784 --- includes/Hooks.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/includes/Hooks.php b/includes/Hooks.php index 5626e1e7..69c63681 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -97,10 +97,15 @@ class Hooks { */ public static function onAPIQuerySiteInfoGeneralInfo( ApiQuerySiteInfo $api, array &$data ) { $catManager = new CategoryManager(); - $data['linter'] = [ - 'errors' => $catManager->getErrors(), - 'warnings' => $catManager->getWarnings(), - ]; + $totals = ( new Database( 0 ) )->getTotals(); + $info = []; + foreach ( $catManager->getErrors() as $error ) { + $info['errors'][$error] = $totals[$error]; + } + foreach ( $catManager->getWarnings() as $warning ) { + $info['warnings'][$warning] = $totals[$warning]; + } + $data['linter'] = $info; } /**