Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/sc-31614 #71

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 29 additions & 22 deletions htdocs/wp-content/themes/hollandskroon/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

defined('ABSPATH') || exit;

try {
(new HK\Providers\CommandServiceProvider())->boot();
} catch (Exception $e) {
// Log error.
error_log('Error booting CommandServiceProvider: ' . $e->getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dit is denk ik niet wat je wilt. Exceptions vang je alleen af wanneer je de error situatie kunt oplossen waarna je veilig door kunt. Ik zou zeggen: Laat die exception lekker over aan de exception handler van Fusion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...en bij gebrek aan Fusion... aan de exception handler van WP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik zou hem dit geval wel afvangen omdat anders de hele site eruit ligt. Aan de andere kant zie ik de serviceprovider in deze opzet geen exceptie gooien.

De afhandeling zou wel beter in serviceprovider passen.

Wellicht zit hier nog een oplossing in en anders in de package/plugin die Dik aan het maken is?

}

/**
* If the browser of the visitor is not Chrome or Edge.
* Display message,
Expand Down Expand Up @@ -34,17 +41,17 @@

add_action('init', function () {
$labels = [
'name' => _x('Owner', 'taxonomy general name', 'hoekschewaard'),
'singular_name' => _x('Owner', 'taxonomy singular name', 'hoekschewaard'),
'search_items' => __('Search owners', 'hoekschewaard'),
'all_items' => __('All owners', 'hoekschewaard'),
'parent_item' => __('Parent owner', 'hoekschewaard'),
'parent_item_colon' => __('Parent owner:', 'hoekschewaard'),
'edit_item' => __('Edit owner', 'hoekschewaard'),
'update_item' => __('Update owner', 'hoekschewaard'),
'add_new_item' => __('Add new owner', 'hoekschewaard'),
'new_item_name' => __('New owner name', 'hoekschewaard'),
'menu_name' => __('Owner', 'hoekschewaard'),
'name' => _x('Owner', 'taxonomy general name', 'hollandskroon'),
'singular_name' => _x('Owner', 'taxonomy singular name', 'hollandskroon'),
'search_items' => __('Search owners', 'hollandskroon'),
'all_items' => __('All owners', 'hollandskroon'),
'parent_item' => __('Parent owner', 'hollandskroon'),
'parent_item_colon' => __('Parent owner:', 'hollandskroon'),
'edit_item' => __('Edit owner', 'hollandskroon'),
'update_item' => __('Update owner', 'hollandskroon'),
'add_new_item' => __('Add new owner', 'hollandskroon'),
'new_item_name' => __('New owner name', 'hollandskroon'),
'menu_name' => __('Owner', 'hollandskroon'),
];

register_taxonomy('form-owner', 'page', [
Expand All @@ -60,17 +67,17 @@

add_action('init', function () {
$labels = [
'name' => _x('Link', 'taxonomy general name', 'hoekschewaard'),
'singular_name' => _x('Link', 'taxonomy singular name', 'hoekschewaard'),
'search_items' => __('Search Links', 'hoekschewaard'),
'all_items' => __('All Links', 'hoekschewaard'),
'parent_item' => __('Parent Link', 'hoekschewaard'),
'parent_item_colon' => __('Parent Link:', 'hoekschewaard'),
'edit_item' => __('Edit Link', 'hoekschewaard'),
'update_item' => __('Update Link', 'hoekschewaard'),
'add_new_item' => __('Add new Link', 'hoekschewaard'),
'new_item_name' => __('New Link name', 'hoekschewaard'),
'menu_name' => __('Link', 'hoekschewaard'),
'name' => _x('Link', 'taxonomy general name', 'hollandskroon'),
'singular_name' => _x('Link', 'taxonomy singular name', 'hollandskroon'),
'search_items' => __('Search Links', 'hollandskroon'),
'all_items' => __('All Links', 'hollandskroon'),
'parent_item' => __('Parent Link', 'hollandskroon'),
'parent_item_colon' => __('Parent Link:', 'hollandskroon'),
'edit_item' => __('Edit Link', 'hhollandskroon'),
'update_item' => __('Update Link', 'hollandskroon'),
'add_new_item' => __('Add new Link', 'hollandskroon'),
'new_item_name' => __('New Link name', 'hollandskroon'),
'menu_name' => __('Link', 'hollandskroon'),
];

register_taxonomy('form-links', 'page', [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace HK\Commands;

use \WP_CLI;
use \WP_CLI\ExitException;

class PronamicIdealCleanupCommand
{
/**
* @throws \JsonException
* @throws ExitException
*/
public function __invoke($args, $assoc_args)
{
$postsPerPage = 100;
$deletionCount = 0;

do {
// Get fulfilled payments older than 5 days in batches of 100
$payments = new \WP_Query([
'post_type' => 'pronamic_payment',
'post_status' => 'payment_completed',
'posts_per_page' => $postsPerPage,
hnccox-yard marked this conversation as resolved.
Show resolved Hide resolved
'paged' => 1,
hnccox-yard marked this conversation as resolved.
Show resolved Hide resolved
'date_query' => [
'before' => '5 days ago',
],
]);

foreach ($payments->posts as $payment) {
if (!wp_delete_post($payment->ID, true)) {
WP_CLI::warning('Failed to delete post with ID: ' . $payment->ID);
throw new \Exception('Failed to delete post with ID: ' . $payment->ID);
}
$deletionCount++;
}
hnccox-yard marked this conversation as resolved.
Show resolved Hide resolved
} while ($payments->have_posts());

WP_CLI::success('Pronamic fulfilled payments cleaned up successfully.');
WP_CLI::line('Deleted ' . $deletionCount . ' payments.');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace HK\Providers;

use HK\Commands\PronamicIdealCleanupCommand;

class CommandServiceProvider
{
/**
* @throws \Exception
*/
public function boot()
{
if (defined('WP_CLI') && WP_CLI) {
\WP_CLI::add_command('pronamic:cleanup', PronamicIdealCleanupCommand::class);
}
}
}