@@ 13-88 (lines=76) @@ | ||
10 | * @author Luke Adamczewski |
|
11 | * @package Tworzenieweb\SqlProvisioner\Database |
|
12 | */ |
|
13 | class HasDbDeployCheck implements CheckInterface |
|
14 | { |
|
15 | const SQL = <<<SQL |
|
16 | SELECT `id` |
|
17 | FROM `%s` |
|
18 | WHERE `%s` = ? |
|
19 | SQL; |
|
20 | const ERROR_STATUS = 'ALREADY_DEPLOYED'; |
|
21 | ||
22 | /** @var Connection */ |
|
23 | private $connection; |
|
24 | ||
25 | ||
26 | ||
27 | /** |
|
28 | * @param Connection $connection |
|
29 | */ |
|
30 | public function __construct(Connection $connection) |
|
31 | { |
|
32 | $this->connection = $connection; |
|
33 | } |
|
34 | ||
35 | ||
36 | ||
37 | /** |
|
38 | * @param Candidate $candidate |
|
39 | * @return bool |
|
40 | */ |
|
41 | public function execute(Candidate $candidate) |
|
42 | { |
|
43 | $statement = $this->getConnection()->prepare($this->getSqlStatement()); |
|
44 | $statement->execute([$candidate->getNumber()]); |
|
45 | ||
46 | return (boolean) $statement->fetchColumn(); |
|
47 | } |
|
48 | ||
49 | ||
50 | ||
51 | /** |
|
52 | * @return string |
|
53 | */ |
|
54 | public function getErrorCode() |
|
55 | { |
|
56 | return self::ERROR_STATUS; |
|
57 | } |
|
58 | ||
59 | ||
60 | ||
61 | /** |
|
62 | * @return PDO |
|
63 | */ |
|
64 | private function getConnection() |
|
65 | { |
|
66 | return $this->connection->getCurrentConnection(); |
|
67 | } |
|
68 | ||
69 | ||
70 | ||
71 | /** |
|
72 | * @return null |
|
73 | */ |
|
74 | public function getLastErrorMessage() |
|
75 | { |
|
76 | return null; |
|
77 | } |
|
78 | ||
79 | ||
80 | ||
81 | /** |
|
82 | * @return string |
|
83 | */ |
|
84 | private function getSqlStatement() |
|
85 | { |
|
86 | return sprintf(self::SQL, $this->connection->getProvisioningTable(), $this->connection->getCriteriaColumn()); |
|
87 | } |
|
88 | } |
@@ 13-88 (lines=76) @@ | ||
10 | * @author Luke Adamczewski |
|
11 | * @package Tworzenieweb\SqlProvisioner\Database |
|
12 | */ |
|
13 | class HasDbDeployCheckInterface implements CheckInterface |
|
14 | { |
|
15 | const SQL = <<<SQL |
|
16 | SELECT `id` |
|
17 | FROM `%s` |
|
18 | WHERE `%s` = ? |
|
19 | SQL; |
|
20 | const ERROR_STATUS = 'ALREADY_DEPLOYED'; |
|
21 | ||
22 | /** @var Connection */ |
|
23 | private $connection; |
|
24 | ||
25 | ||
26 | ||
27 | /** |
|
28 | * @param Connection $connection |
|
29 | */ |
|
30 | public function __construct(Connection $connection) |
|
31 | { |
|
32 | $this->connection = $connection; |
|
33 | } |
|
34 | ||
35 | ||
36 | ||
37 | /** |
|
38 | * @param Candidate $candidate |
|
39 | * @return bool |
|
40 | */ |
|
41 | public function execute(Candidate $candidate) |
|
42 | { |
|
43 | $statement = $this->getConnection()->prepare($this->getSqlStatement()); |
|
44 | $statement->execute([$candidate->getNumber()]); |
|
45 | ||
46 | return (boolean) $statement->fetchColumn(); |
|
47 | } |
|
48 | ||
49 | ||
50 | ||
51 | /** |
|
52 | * @return string |
|
53 | */ |
|
54 | public function getErrorCode() |
|
55 | { |
|
56 | return self::ERROR_STATUS; |
|
57 | } |
|
58 | ||
59 | ||
60 | ||
61 | /** |
|
62 | * @return PDO |
|
63 | */ |
|
64 | private function getConnection() |
|
65 | { |
|
66 | return $this->connection->getCurrentConnection(); |
|
67 | } |
|
68 | ||
69 | ||
70 | ||
71 | /** |
|
72 | * @return null |
|
73 | */ |
|
74 | public function getLastErrorMessage() |
|
75 | { |
|
76 | return null; |
|
77 | } |
|
78 | ||
79 | ||
80 | ||
81 | /** |
|
82 | * @return string |
|
83 | */ |
|
84 | private function getSqlStatement() |
|
85 | { |
|
86 | return sprintf(self::SQL, $this->connection->getProvisioningTable(), $this->connection->getCriteriaColumn()); |
|
87 | } |
|
88 | } |