statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Duplicating pages with multiple languages causes different page IDs for non-primary languages #2163

Open FrittenKeeZ opened 6 years ago

FrittenKeeZ commented 6 years ago

Describe the bug Duplicating a page with multiple languages will cause duplicate IDs error. When trying to resolve the issue, the non-primary languages with get different IDs than the primary, which will blow up the cache/stache.

To Reproduce Steps to reproduce the behavior:

  1. Create a page with multiple language versions.
  2. Duplicate the page.
  3. See that there's suddenly duplicate IDs and press the button to resolve.
  4. See that Stache updater explodes with Call to a member function in() on null.

Expected behavior Duplication of pages should work regardless of number of languages.

Screenshots stache-explosion

Environment details (please complete the following information):

FrittenKeeZ commented 6 years ago

Worth noting that this is an extremely hard to reproduce bug, which has only occurred on our staging environment. The localized pages will have the same ID, but they will differ from the main language. This is the only errors we have prior to the crash:

[2018-09-05 14:35:57] stage.ERROR: Cannot add [pages/1.hoteller/17.comwell-hotel-varbergs-kusthotell/4.behandlinger/_3.spabehandlingar-1/index.md] to Stache repository [pages]. File at [pages/1.hoteller/17.comwell-hotel-varbergs-kusthotell/4.behandlinger/_1.spabehandlingar-1/index.md] already exists in repository [pages] with an ID of [4b7daf5a-ec5b-4fcb-a106-9aa1f860e7b2].
[2018-09-05 14:38:12] stage.ERROR: Cannot add [pages/1.hoteller/17.comwell-hotel-varbergs-kusthotell/4.behandlinger/3.spabehandlingar-1/index.md] to Stache repository [pages]. File at [pages/1.hoteller/17.comwell-hotel-varbergs-kusthotell/4.behandlinger/1.spabehandlingar-1/index.md] already exists in repository [pages] with an ID of [4b7daf5a-ec5b-4fcb-a106-9aa1f860e7b2].
[2018-09-05 14:44:56] stage.ERROR: Cannot add [pages/1.hoteller/17.comwell-hotel-varbergs-kusthotell/4.behandlinger/4.spabehandlingar-1-1/index.md] to Stache repository [pages]. File at [pages/1.hoteller/17.comwell-hotel-varbergs-kusthotell/4.behandlinger/1.spabehandlingar-1-1/index.md] already exists in repository [pages] with an ID of [9769d355-1d0f-45f3-980d-b1bf1a8ba7c3].
[2018-09-05 14:44:56] stage.ERROR: Cannot add [pages/1.hoteller/17.comwell-hotel-varbergs-kusthotell/4.behandlinger/5.spabehandlingar-1-1-1/index.md] to Stache repository [pages]. File at [pages/1.hoteller/17.comwell-hotel-varbergs-kusthotell/4.behandlinger/1.spabehandlingar-1-1-1/index.md] already exists in repository [pages] with an ID of [1e607b7a-1697-43ce-97cf-c7c00ebd904b].
[2018-09-05 14:57:08] stage.ERROR: Cannot add [pages/1.hoteller/17.comwell-hotel-varbergs-kusthotell/3.spa/1.behandlinger/3.spabehandlingar-hand-fot/index.md] to Stache repository [pages]. File at [pages/1.hoteller/17.comwell-hotel-varbergs-kusthotell/4.behandlinger/3.spabehandlingar-hand-fot/index.md] already exists in repository [pages] with an ID of [4b7daf5a-ec5b-4fcb-a106-9aa1f860e7b2].
FrittenKeeZ commented 6 years ago

Hey @jackmcdade and @jasonvarga

We're having a really rough time with multiple languages - we get a lot of duplicate ID issues and editors only use CP... I don't know how or why it's happening, but we're losing credibility with our client, as they think the system is unstable with these errors, which potentially can force the site to crash.

We need this to be resolved once and for all.

FrittenKeeZ commented 6 years ago

This sadly also occurs when moving pages around.

nobodyiscertain commented 5 years ago

Any update on this one? I've got a client site that is having the same issue when reordering or removing pages. Also a site with multiple languages.

Let me know what info I can provide to help debug further.

FrittenKeeZ commented 5 years ago

@nobodyiscertain how much content do they have on their site? We have a patch in place for locking the Stache when pages are being moved around, but Stache still isn't always updated correctly after the reordering - but corruption seems to be prevented with it.

diff --git statamic/core/Http/Controllers/PagesController.php statamic/core/Http/Controllers/PagesController.php
index 5b79402..52af909 100644
--- statamic/core/Http/Controllers/PagesController.php
+++ statamic/core/Http/Controllers/PagesController.php
@@ -161,10 +161,20 @@ class PagesController extends CpController
     {
         $this->authorize('pages:reorder');

-        // Grab the JSON payload
-        $tree = $this->request->input('pages');
+        // Hang it there, this might take a while!
+        set_time_limit(0);

-        $reorderer->reorder($tree);
+        if (app('stache')->lock()->acquire(true)) {
+            // Grab the JSON payload
+            $tree = $this->request->input('pages');
+
+            $reorderer->reorder($tree);
+
+            app('stache')->lock()->release();
+        }

         Stache::update();
nobodyiscertain commented 5 years ago

Quite a bit of content, hundreds of pages/collection entries. Does that patch work with lots of content?

FrittenKeeZ commented 5 years ago

It works a lot better than without the patch, that much I can say.

nobodyiscertain commented 5 years ago

Patching core code isn't ideal, but will give it a shot and see how it goes. Thanks for the help!