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.
This commit is contained in:
2026-11-25 14:53:35 +01:00
parent 9d192c2141
commit a07e3ad8d9
19 changed files with 983 additions and 122 deletions
@@ -29,4 +29,47 @@ class PageTranslationRepository extends BaseRepository implements PageTranslatio
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);
}
}