new file: olm-login.php

This commit is contained in:
Sven Steinert
2026-05-27 14:17:22 +02:00
parent 1d4cf6e727
commit e99acdce47
25 changed files with 36226 additions and 630 deletions

View File

@@ -111,7 +111,18 @@ final class PageRepository
public function findFrontendPage(string $productSlug, string $versionSlug, string $pageSlug): ?\WP_Post
{
return $this->findFrontendPageInProducts([$productSlug], $versionSlug, $pageSlug);
}
public function findFrontendPageInProducts(array $productSlugs, string $versionSlug, string $pageSlug): ?\WP_Post
{
$productSlugs = array_values(array_filter(array_map('sanitize_title', $productSlugs)));
$pageSlug = $pageSlug ?: '';
if (! $productSlugs) {
return null;
}
$query = new \WP_Query([
'post_type' => 'kb_doc_page',
'post_status' => 'publish',
@@ -119,10 +130,12 @@ final class PageRepository
'no_found_rows' => true,
'meta_query' => [
'relation' => 'AND',
['key' => '_kb_product_slug', 'value' => $productSlug],
['key' => '_kb_version_slug', 'value' => $versionSlug],
['key' => '_kb_page_slug', 'value' => $pageSlug],
],
'tax_query' => [
['taxonomy' => 'kb_product', 'field' => 'slug', 'terms' => $productSlugs],
],
]);
return $query->have_posts() ? $query->posts[0] : null;

View File

@@ -5,6 +5,11 @@ namespace KbMarkdownImporter\Repository;
final class ProductRepository
{
public const META_GROUP_NAME = '_kb_product_group_name';
public const META_GROUP_SLUG = '_kb_product_group_slug';
public const META_PART_LABEL = '_kb_product_part_label';
public const META_CATEGORY = '_kb_product_category';
public function ensure(string $name, string $slug = ''): int
{
$slug = $slug ? sanitize_title($slug) : sanitize_title($name);
@@ -54,13 +59,14 @@ final class ProductRepository
'term' => $term,
'page_count' => count($pageIds),
'versions' => array_values($versions),
'meta' => $this->frontendMeta($term),
];
}
return $items;
}
public function update(int $termId, string $name, string $slug): \WP_Term|\WP_Error
public function update(int $termId, string $name, string $slug, array $frontend = []): \WP_Term|\WP_Error
{
$name = trim($name);
$slug = sanitize_title($slug ?: $name);
@@ -82,6 +88,23 @@ final class ProductRepository
update_post_meta($pageId, '_kb_product_slug', $slug);
}
$groupName = sanitize_text_field((string) ($frontend['group_name'] ?? ''));
$groupName = '' !== trim($groupName) ? $groupName : $name;
$groupSlugInput = sanitize_title((string) ($frontend['group_slug'] ?? ''));
$groupSlug = $groupSlugInput ?: sanitize_title($groupName);
if ($groupSlugInput === $slug && 0 !== strcasecmp($groupName, $name)) {
$groupSlug = sanitize_title($groupName);
}
$partLabel = sanitize_text_field((string) ($frontend['part_label'] ?? ''));
$category = sanitize_text_field((string) ($frontend['category'] ?? ''));
update_term_meta($termId, self::META_GROUP_NAME, $groupName ?: $name);
update_term_meta($termId, self::META_GROUP_SLUG, $groupSlug ?: $slug);
update_term_meta($termId, self::META_PART_LABEL, $partLabel);
update_term_meta($termId, self::META_CATEGORY, $category);
$term = get_term((int) $updated['term_id'], 'kb_product');
return $term instanceof \WP_Term ? $term : new \WP_Error('kb_product_missing', __('Product could not be loaded after update.', 'kb-markdown-importer'));
@@ -115,6 +138,27 @@ final class ProductRepository
return true;
}
public function frontendMeta(\WP_Term $term): array
{
$storedGroupName = trim((string) get_term_meta($term->term_id, self::META_GROUP_NAME, true));
$storedGroupSlug = sanitize_title((string) get_term_meta($term->term_id, self::META_GROUP_SLUG, true));
$groupName = '' !== $storedGroupName ? $storedGroupName : $term->name;
$groupSlug = '' !== $storedGroupSlug ? $storedGroupSlug : ('' !== $storedGroupName ? sanitize_title($groupName) : $term->slug);
$partLabel = trim((string) get_term_meta($term->term_id, self::META_PART_LABEL, true));
$category = trim((string) get_term_meta($term->term_id, self::META_CATEGORY, true));
if ('' !== $storedGroupName && $groupSlug === $term->slug && 0 !== strcasecmp($groupName, $term->name)) {
$groupSlug = sanitize_title($groupName);
}
return [
'group_name' => $groupName,
'group_slug' => '' !== $groupSlug ? $groupSlug : $term->slug,
'part_label' => $partLabel,
'category' => $category,
];
}
private function pageIdsForProduct(int $termId, array $postStatus = ['publish']): array
{
$query = new \WP_Query([