Files
plugi/plugi-core/src/Repositories/PageTranslationRepository.php
T
deepDiverPaul a07e3ad8d9 fix localized page management and builder synchronization
Validate locales and route uniqueness, report page deletion failures, and keep translation CRUD and route caches consistent. Show translation completeness in page settings and listings, and preserve locale-specific block data while synchronizing shared structure. Add translation service and page builder synchronization tests.
2026-11-25 14:53:35 +01:00

76 lines
2.1 KiB
PHP

<?php
namespace Plugi\Repositories;
use Plugi\Contracts\PageTranslationRepositoryContract;
class PageTranslationRepository extends BaseRepository implements PageTranslationRepositoryContract
{
/**
* The page translations database table.
*
* @var string
*/
protected $table;
/**
* The class that represents each page translation.
*
* @var string
*/
protected $class;
/**
* PageTranslationRepository constructor.
*/
public function __construct()
{
$this->table = empty(phpb_config('page.translation.table')) ? 'page_translations' : phpb_config('page.translation.table');
parent::__construct();
$this->class = phpb_instance('page.translation');
}
/**
* Determine whether a route is already used by another page translation.
*
* @param string $route
* @param mixed|null $excludedPageId
* @return bool
*/
public function routeExists(string $route, $excludedPageId = null): bool
{
$query = "SELECT 1 FROM {$this->table} WHERE route = ?";
$parameters = [$route];
if ($excludedPageId !== null) {
$foreignKey = $this->removeNonAlphaNumeric(phpb_config('page.translation.foreign_key'));
$query .= " AND {$foreignKey} != ?";
$parameters[] = $excludedPageId;
}
$query .= ' LIMIT 1';
return ! empty($this->db->select($query, $parameters));
}
/**
* Return translations belonging to the given page IDs.
*
* @param array $pageIds
* @return array
*/
public function getForPages(array $pageIds): array
{
if (empty($pageIds)) {
return [];
}
$foreignKey = $this->removeNonAlphaNumeric(phpb_config('page.translation.foreign_key'));
$placeholders = implode(', ', array_fill(0, count($pageIds), '?'));
$records = $this->db->select(
"SELECT * FROM {$this->table} WHERE {$foreignKey} IN ({$placeholders})",
array_values($pageIds)
);
return $this->createInstances($records);
}
}