Commit:    a1e9fe6f6a7750b008dfe92cf8ecd9ab877b3f67
Author:    Peter Kokot <peterko...@gmail.com>         Wed, 19 Dec 2018 02:49:59 
+0100
Parents:   ad8bc2d5ab343733e57622d0ca063ce96570509d
Branches:  master

Link:       
http://git.php.net/?p=web/bugs.git;a=commitdiff;h=a1e9fe6f6a7750b008dfe92cf8ecd9ab877b3f67

Log:
Move docs comments to repository

Changed paths:
  M  src/Repository/CommentRepository.php
  M  www/api.php


Diff:
diff --git a/src/Repository/CommentRepository.php 
b/src/Repository/CommentRepository.php
index 8f28c4b..18c6944 100644
--- a/src/Repository/CommentRepository.php
+++ b/src/Repository/CommentRepository.php
@@ -39,4 +39,27 @@ class CommentRepository
 
         return $statement->fetchAll();
     }
+
+    /**
+     * Find all log comments for documentation.
+     * TODO: Check if this method is still used in the api.php endpoint.
+     */
+    public function findDocsComments(int $interval): array
+    {
+        $sql = "SELECT bugdb_comments.reporter_name, COUNT(*) as count
+                FROM bugdb_comments, bugdb
+                WHERE comment_type =  'log'
+                    AND (package_name IN ('Doc Build problem', 'Documentation 
problem', 'Translation problem', 'Online Doc Editor problem') OR bug_type = 
'Documentation Problem')
+                    AND comment LIKE  '%+Status:      Closed</span>%'
+                    AND date_sub(curdate(), INTERVAL ? DAY) <= ts
+                    AND bugdb.id = bugdb_comments.bug
+                GROUP BY bugdb_comments.reporter_name
+                ORDER BY count DESC
+        ";
+
+        $statement = $this->dbh->prepare($sql);
+        $statement->execute([$interval]);
+
+        return $statement->fetchAll();
+    }
 }
diff --git a/www/api.php b/www/api.php
index 4a07baf..4fbf5bc 100644
--- a/www/api.php
+++ b/www/api.php
@@ -5,6 +5,9 @@
        The API itself will probably be abandoned in the future, but here's the 
current URL:
        - https://bugs.php.net/api.php?type=docs&action=closed&interval=7
 */
+
+use App\Repository\CommentRepository;
+
 require_once '../include/prepend.php';
 
 $type     = isset($_GET['type'])     ? $_GET['type']           : 'unknown';
@@ -12,22 +15,10 @@ $action   = isset($_GET['action'])   ? $_GET['action']      
   : 'unknown';
 $interval = isset($_GET['interval']) ? (int) $_GET['interval'] : 7;
 
 if ($type === 'docs' && $action === 'closed' && $interval) {
-
-       $query =
-       "
-               SELECT bugdb_comments.reporter_name, COUNT(*) as count
-               FROM bugdb_comments, bugdb
-               WHERE comment_type =  'log'
-               AND (package_name IN ('Doc Build problem', 'Documentation 
problem', 'Translation problem', 'Online Doc Editor problem') OR bug_type = 
'Documentation Problem')
-               AND comment LIKE  '%+Status:      Closed</span>%'
-               AND date_sub(curdate(), INTERVAL {$interval} DAY) <= ts
-               AND bugdb.id = bugdb_comments.bug
-               GROUP BY bugdb_comments.reporter_name
-               ORDER BY count DESC
-       ";
+       $commentRepository = new CommentRepository($dbh);
+       $rows = $commentRepository->findDocsComments($interval);
 
        //@todo add error handling
-       $rows = $dbh->prepare($query)->execute([])->fetchAll();
        if (!$rows) {
                echo 'The fail train has arrived.';
                exit;


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

Reply via email to