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

Replace command with WP Cron + REST endpoints #7

Merged
merged 5 commits into from
Jul 15, 2024

Conversation

mvdhoek1
Copy link
Contributor

Scherm­afbeelding 2024-07-12 om 07 46 57 Scherm­afbeelding 2024-07-12 om 07 46 42

Scherm­afbeelding 2024-07-11 om 16 54 25

*
* @return mixed
*/
public function handleRequestParam(WP_REST_Request $request, string $param, string $type, $default = null)
Copy link

@ictbeheer ictbeheer Jul 12, 2024

Choose a reason for hiding this comment

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

Als je args definieert in register_rest_route gebeurt dit allemaal automatisch. (validatie, default enz)

https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah goeie, ga ik niet nu meenemen. Wellicht in de volgende versie.

Copy link
Member

@sanderdekroon sanderdekroon left a comment

Choose a reason for hiding this comment

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

Ziet er goed uit! Mooi dat je typehints e.d. hebt toegevoegd.

Zou je willen kijken naar de tijdzone opmerking? Dat is het enige wat misschien nog even aangepast moet worden.

*/
public function getLegeBySlug(WP_REST_Request $request)
{
$slug = $request->get_param('slug');
Copy link
Member

Choose a reason for hiding this comment

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

Waarom hier geen gebruik van $this->handleRequestParam()?

{
$perPage = $query->get('posts_per_page');
$page = $query->get('paged');
$page = 0 == $page || -1 == $perPage ? 1 : $page; // If $perPage = -1, $page should be 1.
Copy link
Member

Choose a reason for hiding this comment

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

Ik hou ook van compacte code, maar ik vind dit wel moeilijk leesbaar. Haakjes maken het (voor mij althans) iets beter leesbaar: $page = (0 == $page || -1 == $perPage) ? 1 : $page;.

src/Leges/WPCron/Events/UpdateLegesPrices.php Show resolved Hide resolved

protected function timeToExecute(): int
{
$currentDateTime = new DateTime('now', new DateTimeZone(wp_timezone_string()));
Copy link
Member

Choose a reason for hiding this comment

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

wp_timezone_string() kan ook een offset teruggeven (bijv. +08:45). Zo'n waarde is niet in een format die door DateTimeZone geaccepteerd wordt ("One of the supported timezone names, an offset value (+0200), or a timezone abbreviation (BST)"). Wellicht hier een try...catch omheen zetten.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Goed dat je het zegt, dit is een betere oplossing:
$currentDateTime = new DateTime('now', wp_timezone());

{
$slug = $request->get_param('slug');

if (empty($slug) || ! is_string($slug)) {

Choose a reason for hiding this comment

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

Dit gaat ook vanzelf als je slug als arg registreert.

@mvdhoek1 mvdhoek1 force-pushed the feat/wp-cron-event-updating-leges branch from 3220af4 to 130f161 Compare July 12, 2024 13:10
CHANGELOG.md Outdated
@@ -1,94 +1,106 @@
# CHANGELOG

## Version 1.2.5
## [2.0.0]
Copy link
Member

Choose a reason for hiding this comment

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

Top om die Version hier weg te laten maar waarom deze brackets?

@@ -4,7 +4,7 @@
* Plugin Name: PDC Leges
* Plugin URI: https://www.openwebconcept.nl
* Description: PDC Leges
* Version: 1.2.5
* Version: 2.0.0
Copy link
Member

Choose a reason for hiding this comment

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

Just checking: is dit een major, backwards incompatible version? Is er een upgrade guide nodig?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nee, het huidige commando (<2.0) is straks weg maar zal niets breken, in de README.md staat het wel beschreven:

Since version 2.0.0, the commands have been replaced by WP Cron Events. This change requires less configuration on your server by eliminating the need to add server cron jobs. Just activate the plugin and you're all set.
Remember to remove any previously configured cron jobs from your web server, as they have been deprecated since version 2.0.0.

@mvdhoek1 mvdhoek1 force-pushed the feat/wp-cron-event-updating-leges branch from 130f161 to 4695448 Compare July 15, 2024 08:16
@mvdhoek1 mvdhoek1 requested a review from robertbossaert July 15, 2024 08:17
@mvdhoek1 mvdhoek1 force-pushed the feat/wp-cron-event-updating-leges branch from 4695448 to 984259c Compare July 15, 2024 08:42
'type' => 'integer',
'default' => 10,
],
'page' => [

Choose a reason for hiding this comment

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

Ik zou hier nog 'minimum' => 1 toevoegen

'permission_callback' => '__return_true',
'args' => [
'limit' => [
'description' => 'Number of posts per page.',

Choose a reason for hiding this comment

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

'minimum' => -1,
'maximum' => 100,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Toegevoegd

'description' => 'Slug of the post.',
'type' => 'string',
'default' => '',
]

Choose a reason for hiding this comment

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

Als je slug 'required' => true maakt hoef je in de controller niet meer te checken of ie gevuld is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Zal niets doen, zonder slug param komt ie in het algemene endpoint voor het ophalen van alle leges.

@mvdhoek1 mvdhoek1 force-pushed the feat/wp-cron-event-updating-leges branch from 3b119b9 to 889cae7 Compare July 15, 2024 09:30
@mvdhoek1 mvdhoek1 force-pushed the feat/wp-cron-event-updating-leges branch from 889cae7 to daf843e Compare July 15, 2024 09:33
@mvdhoek1 mvdhoek1 merged commit e919d2e into master Jul 15, 2024
1 of 2 checks passed
@mvdhoek1 mvdhoek1 deleted the feat/wp-cron-event-updating-leges branch July 15, 2024 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants