1<?php
2
3namespace App\Repository;
4
5/**
6 * Repository for retrieving data from the bugdb_obsoletes_patches database table.
7 */
8class ObsoletePatchRepository
9{
10    /**
11     * Database handler.
12     * @var \PDO
13     */
14    private $dbh;
15
16    /**
17     * Class constructor.
18     */
19    public function __construct(\PDO $dbh)
20    {
21        $this->dbh = $dbh;
22    }
23
24    /**
25     * Retrieve patches that obsoleted given patch.
26     */
27    public function findObsoletingPatches(int $bugId, string $patch, int $revision): array
28    {
29        $sql = 'SELECT bugdb_id, patch, revision
30                FROM bugdb_obsoletes_patches
31                WHERE bugdb_id = ? AND obsolete_patch = ? AND obsolete_revision = ?
32        ';
33
34        $statement = $this->dbh->prepare($sql);
35        $statement->execute([$bugId, $patch, $revision]);
36
37        return $statement->fetchAll();
38    }
39
40    /**
41     * Retrieve obsolete patches by bug, patch and revision.
42     */
43    public function findObsoletePatches(int $bugId, string $patch, int $revision): array
44    {
45        $sql = 'SELECT bugdb_id, obsolete_patch, obsolete_revision
46                FROM bugdb_obsoletes_patches
47                WHERE bugdb_id = ? AND patch = ? AND revision = ?
48        ';
49
50        $statement = $this->dbh->prepare($sql);
51        $statement->execute([$bugId, $patch, $revision]);
52
53        return $statement->fetchAll();
54    }
55}
56