Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michael Iseard
Kudos-Donations
Commits
47474f53
Commit
47474f53
authored
Oct 14, 2021
by
Michael Iseard
Browse files
Fix truncating logic and using dependency injection for LoggerService
parent
dd3c6fcd
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/Controller/Admin.php
View file @
47474f53
...
...
@@ -56,6 +56,10 @@ class Admin {
* @var \Kudos\Service\Vendor\MollieVendor
*/
private
$mollie
;
/**
* @var \Kudos\Service\LoggerService
*/
private
$logger
;
/**
* Initialize the class and set its properties.
...
...
@@ -69,15 +73,17 @@ class Admin {
PaymentService
$payment
,
ActivatorService
$activator
,
Settings
$settings
,
MollieVendor
$mollie_vendor
MollieVendor
$mollie_vendor
,
LoggerService
$logger
)
{
$this
->
version
=
$version
;
$this
->
mapper
=
$mapper
;
$this
->
twig
=
$twig
;
$this
->
payment
=
$payment
;
$this
->
activator
=
$activator
;
$this
->
settings
=
$settings
;
$this
->
mollie
=
$mollie_vendor
;
$this
->
version
=
$version
;
$this
->
mapper
=
$mapper
;
$this
->
twig
=
$twig
;
$this
->
payment
=
$payment
;
$this
->
activator
=
$activator
;
$this
->
settings
=
$settings
;
$this
->
mollie
=
$mollie_vendor
;
$this
->
logger
=
$logger
;
}
/**
...
...
@@ -268,7 +274,7 @@ class Admin {
wp_register_style
(
'kudos-donations-public'
,
Assets
::
get_asset_url
(
'/public/kudos-public.css'
),
[
'kudos-donations-root'
],
[
'kudos-donations-root'
],
$this
->
version
);
...
...
@@ -536,9 +542,9 @@ class Admin {
break
;
case
'kudos_sync_payments'
:
$mollie
=
$this
->
mollie
;
$mollie
=
$this
->
mollie
;
$updated
=
$mollie
->
sync_transactions
();
if
(
$updated
)
{
if
(
$updated
)
{
new
AdminNotice
(
sprintf
(
/* translators: %s: Number of records. */
...
...
@@ -551,7 +557,7 @@ class Admin {
);
break
;
}
new
AdminNotice
(
__
(
'No transactions need updating'
,
'kudos-donations'
)
);
new
AdminNotice
(
__
(
'No transactions need updating'
,
'kudos-donations'
)
);
}
do_action
(
'kudos_admin_actions_extra'
,
$action
);
...
...
@@ -564,7 +570,7 @@ class Admin {
* Length defined by LoggerService::TRUNCATE_AT const.
*/
public
function
truncate_log
()
{
LoggerService
::
truncate
();
$this
->
logger
->
truncate
();
}
/**
...
...
app/Service/LoggerService.php
View file @
47474f53
...
...
@@ -17,11 +17,18 @@ class LoggerService extends Logger {
* @var string
*/
public
const
TABLE
=
'kudos_log'
;
/**
* @var \Kudos\Helpers\WpDb|\wpdb
*/
private
$wpdb
;
/**
* @param \Kudos\Helpers\WpDb $wpdb
*/
public
function
__construct
(
WpDb
$wpdb
)
{
$this
->
wpdb
=
$wpdb
;
parent
::
__construct
(
'kudos'
,
[
new
DatabaseHandler
(
$wpdb
)
],
...
...
@@ -80,13 +87,14 @@ class LoggerService extends Logger {
*
* @return bool|int
*/
public
static
function
truncate
()
{
/** @var \wpdb $wpdb */
$wpdb
=
new
WpDb
();
public
function
truncate
()
{
$wpdb
=
$this
->
wpdb
;
$table
=
self
::
get_table_name
();
// Get ID of the oldest row to keep.
$last_row
=
$wpdb
->
get_row
(
$wpdb
->
prepare
(
"
SELECT `id` FROM
{
$table
}
ORDER BY `id` DESC
LIMIT %d,1
"
,
(
self
::
TRUNCATE_AT
-
1
)
)
);
...
...
@@ -94,9 +102,8 @@ class LoggerService extends Logger {
$last_id
=
$last_row
->
id
;
return
$wpdb
->
query
(
$wpdb
->
prepare
(
"
DELETE FROM
{
$table
}
WHERE `id`
>
%d
WHERE `id`
<
%d
"
,
$last_id
));
}
return
false
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment