PluginProbe
Packeta / 2.3.2
Packeta v2.3.2
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 +26 -40 1.4.22.3.2 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 *
@@ -36,42 +36,30 @@
36 36 $this->logRepository = $logRepository;
37 37 }
38 38
39 39 /**
40 - * Registers logger.
41 - *
42 - * @return void
40 + * @return int|false The number of rows inserted, or false on error.
43 41 */
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 - public function add( Record $record ): void {
56 - if ( null === $record->date ) {
57 - $record->date = Helper::now();
42 + public function add( Record $record ) {
43 + if ( $record->date === null ) {
44 + $record->date = CoreHelper::now();
58 45 }
59 46
60 - $this->logRepository->save( $record );
47 + return $this->logRepository->save( $record );
61 48 }
62 49
63 50 /**
64 51 * Gets records.
65 52 *
66 - * @param mixed $orderId Order ID.
67 - * @param array $sorting Sorting config.
68 - * @param int $limit Limit.
53 + * @param int|null $orderId Order ID.
54 + * @param string|null $action Action.
55 + * @param array<string, string> $sorting Sorting config.
56 + * @param int $limit Limit.
69 57 *
70 - * @return iterable|Record[]
58 + * @return \Generator<Record>|array{}
71 59 * @throws \Exception From DateTimeImmutable.
72 60 */
73 - public function getRecords( $orderId, array $sorting = [], int $limit = 100 ): iterable {
61 + public function getRecords( ?int $orderId, ?string $action, array $sorting = [], int $limit = 100 ): iterable {
74 62 $arguments = [
75 63 'orderby' => $sorting,
76 64 'limit' => $limit,
77 65 ];
@@ -78,11 +66,14 @@
78 66
79 67 if ( is_numeric( $orderId ) ) {
80 68 $arguments['order_id'] = $orderId;
81 69 }
70 + if ( $action !== null ) {
71 + $arguments['action'] = $action;
72 + }
82 73
83 74 $logs = $this->logRepository->find( $arguments );
84 - if ( ! $logs ) {
75 + if ( ! $logs instanceof \Generator ) {
85 76 return [];
86 77 }
87 78
88 79 return $logs;
@@ -90,31 +81,26 @@
90 81
91 82 /**
92 83 * Counts records.
93 84 *
94 - * @param int|null $orderId Order ID.
85 + * @param int|null $orderId Order ID.
86 + * @param string|null $action Action.
95 87 *
96 88 * @return int
97 89 */
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 - }
90 + public function countRecords( ?int $orderId = null, ?string $action = null ): int {
91 + return $this->logRepository->countRows( $orderId, $action );
106 92 }
107 93
108 94 /**
109 95 * Gets logs for given period as array.
110 96 *
111 - * @param array $dateQuery Date_query compatible array.
97 + * @param array<array<string, string>> $dateQuery Date_query compatible array.
112 98 *
113 - * @return array
99 + * @return \Generator<Record>|array{}
114 100 * @throws \Exception From DateTimeImmutable.
115 101 */
116 - public function getForPeriodAsArray( array $dateQuery ): iterable {
102 + public function getForPeriodAsArray( array $dateQuery ) {
117 103 $arguments = [
118 104 'orderby' => [ 'date' => 'ASC' ],
119 105 'date_query' => $dateQuery,
120 106 ];
@@ -119,9 +105,9 @@
119 105 'date_query' => $dateQuery,
120 106 ];
121 107
122 108 $logs = $this->logRepository->find( $arguments );
123 - if ( ! $logs ) {
109 + if ( ! $logs instanceof \Generator ) {
124 110 return [];
125 111 }
126 112
127 113 return $logs;