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:
@@ -5,6 +5,7 @@ namespace Plugi\Repositories;
|
||||
use Plugi\Contracts\PageContract;
|
||||
use Plugi\Contracts\PageRepositoryContract;
|
||||
use Plugi\Contracts\PageTranslationContract;
|
||||
use Plugi\PageTranslationService;
|
||||
|
||||
class PageRepository extends BaseRepository implements PageRepositoryContract
|
||||
{
|
||||
@@ -90,7 +91,10 @@ class PageRepository extends BaseRepository implements PageRepositoryContract
|
||||
return false;
|
||||
}
|
||||
|
||||
$updateResult = $this->db->transaction(function () use ($page, $data) {
|
||||
$translationService = new PageTranslationService();
|
||||
$oldRoutes = [];
|
||||
$updateResult = $this->db->transaction(function () use ($page, $data, $translationService, &$oldRoutes) {
|
||||
$oldRoutes = $translationService->getPageRoutes($page->getId());
|
||||
if (! $this->replaceTranslations($page, $data)) {
|
||||
return false;
|
||||
}
|
||||
@@ -102,7 +106,7 @@ class PageRepository extends BaseRepository implements PageRepositoryContract
|
||||
]);
|
||||
});
|
||||
if ($updateResult) {
|
||||
$page->invalidateCache();
|
||||
$translationService->invalidateRoutes(array_merge($oldRoutes, array_values($data['route'])));
|
||||
}
|
||||
return $updateResult;
|
||||
}
|
||||
@@ -185,13 +189,9 @@ class PageRepository extends BaseRepository implements PageRepositoryContract
|
||||
$routes[$route] = true;
|
||||
}
|
||||
|
||||
$foreignKey = phpb_config('page.translation.foreign_key');
|
||||
$pageTranslationRepository = new PageTranslationRepository;
|
||||
foreach ($pageTranslationRepository->getAll(['route', $foreignKey]) as $translation) {
|
||||
if ($pageId !== null && (string) $translation->$foreignKey === (string) $pageId) {
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists($translation->route, $routes)) {
|
||||
foreach (array_keys($routes) as $route) {
|
||||
if ($pageTranslationRepository->routeExists($route, $pageId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,9 @@ class PageRepository extends BaseRepository implements PageRepositoryContract
|
||||
$updateResult = parent::update($page, [
|
||||
'data' => json_encode($data),
|
||||
]);
|
||||
$page->invalidateCache();
|
||||
if ($updateResult) {
|
||||
$page->invalidateCache();
|
||||
}
|
||||
return $updateResult;
|
||||
}
|
||||
|
||||
@@ -223,8 +225,22 @@ class PageRepository extends BaseRepository implements PageRepositoryContract
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->findWithId($id)->invalidateCache();
|
||||
$translationService = new PageTranslationService();
|
||||
$routes = [];
|
||||
$destroyResult = $this->db->transaction(function () use ($id, $translationService, &$routes) {
|
||||
$routes = $translationService->getPageRoutes($id);
|
||||
$pageTranslationRepository = new PageTranslationRepository();
|
||||
if (! $pageTranslationRepository->destroyWhere(phpb_config('page.translation.foreign_key'), $id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::destroy($id);
|
||||
return parent::destroy($id);
|
||||
});
|
||||
|
||||
if ($destroyResult) {
|
||||
$translationService->invalidateRoutes($routes);
|
||||
}
|
||||
|
||||
return $destroyResult;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user