PluginProbe
Packeta / 2.1
Packeta v2.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | src/Packetery/Module/Log/DbLogger.php +23 -40 1.42.1 View file →
@@ -6,12 +6,12 @@
6 6 */
7 7
8 8 declare( strict_types=1 );
9 9
10 -
11 10 namespace Packetery\Module\Log;
12 11
13 -use Packetery\Core\Helper;
12 +use Packetery\Core\CoreHelper;
13 +use Packetery\Core\Log\ILogger;
14 14 use Packetery\Core\Log\Record;
15 15
16 16 /**
17 17 * Class DbLogger
@@ -17,9 +17,9 @@
17 17 * Class DbLogger
18 18 *
19 19 * @package Packetery\Module\Log
20 20 */
21 -class DbLogger implements \Packetery\Core\Log\ILogger {
21 +class DbLogger implements ILogger {
22 22
23 23 /**
24 24 * Log repository.
25 25 *
@@ -35,27 +35,11 @@
35 35 public function __construct( Repository $logRepository ) {
36 36 $this->logRepository = $logRepository;
37 37 }
38 38
39 - /**
40 - * Registers logger.
41 - *
42 - * @return void
43 - */
44 - public function register(): void {
45 - }
46 -
47 - /**
48 - * Adds record.
49 - *
50 - * @param Record $record Record.
51 - *
52 - * @return void
53 - * @throws \Exception From DateTimeImmutable.
54 - */
55 39 public function add( Record $record ): void {
56 - if ( null === $record->date ) {
57 - $record->date = Helper::now();
40 + if ( $record->date === null ) {
41 + $record->date = CoreHelper::now();
58 42 }
59 43
60 44 $this->logRepository->save( $record );
61 45 }
@@ -62,16 +46,17 @@
62 46
63 47 /**
64 48 * Gets records.
65 49 *
66 - * @param mixed $orderId Order ID.
67 - * @param array $sorting Sorting config.
68 - * @param int $limit Limit.
50 + * @param int|null $orderId Order ID.
51 + * @param string|null $action Action.
52 + * @param array<string, string> $sorting Sorting config.
53 + * @param int $limit Limit.
69 54 *
70 - * @return iterable|Record[]
55 + * @return \Generator<Record>|array{}
71 56 * @throws \Exception From DateTimeImmutable.
72 57 */
73 - public function getRecords( $orderId, array $sorting = [], int $limit = 100 ): iterable {
58 + public function getRecords( ?int $orderId, ?string $action, array $sorting = [], int $limit = 100 ): iterable {
74 59 $arguments = [
75 60 'orderby' => $sorting,
76 61 'limit' => $limit,
77 62 ];
@@ -78,11 +63,14 @@
78 63
79 64 if ( is_numeric( $orderId ) ) {
80 65 $arguments['order_id'] = $orderId;
81 66 }
67 + if ( $action !== null ) {
68 + $arguments['action'] = $action;
69 + }
82 70
83 71 $logs = $this->logRepository->find( $arguments );
84 - if ( ! $logs ) {
72 + if ( ! $logs instanceof \Generator ) {
85 73 return [];
86 74 }
87 75
88 76 return $logs;
@@ -90,31 +78,26 @@
90 78
91 79 /**
92 80 * Counts records.
93 81 *
94 - * @param int|null $orderId Order ID.
82 + * @param int|null $orderId Order ID.
83 + * @param string|null $action Action.
95 84 *
96 85 * @return int
97 86 */
98 - public function countRecords( $orderId ): int {
99 - if ( is_numeric( $orderId ) ) {
100 - return $this->logRepository->countByOrderId( (int) $orderId );
101 - }
102 -
103 - if ( null === $orderId ) {
104 - return $this->logRepository->countAll();
105 - }
87 + public function countRecords( ?int $orderId = null, ?string $action = null ): int {
88 + return $this->logRepository->countRows( $orderId, $action );
106 89 }
107 90
108 91 /**
109 92 * Gets logs for given period as array.
110 93 *
111 - * @param array $dateQuery Date_query compatible array.
94 + * @param array<array<string, string>> $dateQuery Date_query compatible array.
112 95 *
113 - * @return array
96 + * @return \Generator<Record>|array{}
114 97 * @throws \Exception From DateTimeImmutable.
115 98 */
116 - public function getForPeriodAsArray( array $dateQuery ): iterable {
99 + public function getForPeriodAsArray( array $dateQuery ) {
117 100 $arguments = [
118 101 'orderby' => [ 'date' => 'ASC' ],
119 102 'date_query' => $dateQuery,
120 103 ];
@@ -119,9 +102,9 @@
119 102 'date_query' => $dateQuery,
120 103 ];
121 104
122 105 $logs = $this->logRepository->find( $arguments );
123 - if ( ! $logs ) {
106 + if ( ! $logs instanceof \Generator ) {
124 107 return [];
125 108 }
126 109
127 110 return $logs;