Skip to content

Commit

Permalink
(refactor): validations of upl-names
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike van den Hoek committed Jan 2, 2024
1 parent 2a3ae3e commit 54dd130
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## Version [3.9.1] (2024-01-02)

### Refactor

- Remove strtolower check when validating value of UniformeProductnaam.
- Remove conversion to lowercase of meta '_owc_pdc_upl_naam' when validating the values.

## Version [3.9] (2023-10-27)

### Feat
Expand Down
2 changes: 1 addition & 1 deletion pdc-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Yard | PDC Base
* Plugin URI: https://www.openwebconcept.nl/
* Description: Acts as foundation for other PDC related content plugins. This plugin implements actions to allow for other plugins to add and/or change Custom Posttypes, Metaboxes, Taxonomies, en Posts 2 posts relations.
* Version: 3.9
* Version: 3.9.1
* Author: Yard | Digital Agency
* Author URI: https://www.yard.nl/
* License: GPL-3.0
Expand Down
2 changes: 1 addition & 1 deletion src/Base/Foundation/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Plugin
*
* @var string
*/
public const VERSION = '3.9';
public const VERSION = '3.9.1';

/**
* Path to the root of the plugin.
Expand Down
3 changes: 1 addition & 2 deletions src/Base/UPL/CorrectItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class CorrectItems extends UPL
{
public function handle()
{
$this->validateUPLNames();
$this->prepareItems();
$correctItems = $this->compareCorrectItems();

Expand All @@ -23,7 +22,7 @@ public function compareCorrectItems(): array
protected function compareCorrectItem($item): bool
{
foreach ($this->uplOptions as $option) {
if ($item['uplName'] !== strtolower($option['UniformeProductnaam']['value']) || strtolower($item['uplUrl']) !== strtolower($option['URI']['value'])) {
if ($option['UniformeProductnaam']['value'] !== $item['uplName'] || strtolower($item['uplUrl']) !== strtolower($option['URI']['value'])) {
continue;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Base/UPL/IncorrectItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class IncorrectItems extends UPL
{
public function handle()
{
$this->validateUPLNames();
$this->prepareItems();
$incorrectItems = $this->compareIncorrectItems();

Expand All @@ -23,7 +22,7 @@ public function compareIncorrectItems(): array
protected function compareIncorrectItem($item): bool
{
foreach ($this->uplOptions as $option) {
if ($item['uplName'] === strtolower($option['UniformeProductnaam']['value']) && strtolower($item['uplUrl']) === strtolower($option['URI']['value'])) {
if ($option['UniformeProductnaam']['value'] === $item['uplName'] && strtolower($item['uplUrl']) === strtolower($option['URI']['value'])) {
return false;
}
}
Expand Down
31 changes: 3 additions & 28 deletions src/Base/UPL/UPL.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,15 @@

class UPL
{
protected array $items;
protected array $uplOptions;

public function __construct(array $items, array $options)
{
$this->items = $items;
$this->uplOptions = $options;
}

protected function validateUPLNames(): void
{
foreach ($this->items as $item) {
$uplName = get_post_meta($item->ID, '_owc_pdc_upl_naam', true);

if (empty($uplName) || ctype_lower($uplName)) {
continue;
}

$this->UPLNameToLowerCase($item, $uplName);
}
}

/**
* Update post meta when value is not in lowercase.
* Post meta should be in lowercase so let's fix this in advance.
*/
protected function UPLNameToLowerCase(\WP_Post $item, string $uplName): string
{
$result = update_post_meta($item->ID, '_owc_pdc_upl_naam', strtolower($uplName));

if (! $result) {
return $uplName;
}

return strtolower($uplName);
}

protected function prepareItems(): void
{
$this->items = array_map(function ($item) {
Expand Down

0 comments on commit 54dd130

Please sign in to comment.