v2-hub icon indicating copy to clipboard operation
v2-hub copied to clipboard

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

Open FrittenKeeZ opened this issue 5 years ago • 8 comments

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):

  • Statamic Version: 2.10.4 upgrade
  • OS: Alpine Linux 3.7
  • Web Server: Nginx
  • PHP Version: 7.1

FrittenKeeZ avatar Sep 05 '18 13:09 FrittenKeeZ

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 avatar Sep 05 '18 15:09 FrittenKeeZ

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 avatar Sep 25 '18 08:09 FrittenKeeZ

This sadly also occurs when moving pages around.

FrittenKeeZ avatar Oct 25 '18 07:10 FrittenKeeZ

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.

nobodyiscertain avatar Jul 02 '19 15:07 nobodyiscertain

@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();

FrittenKeeZ avatar Jul 02 '19 15:07 FrittenKeeZ

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

nobodyiscertain avatar Jul 02 '19 15:07 nobodyiscertain

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

FrittenKeeZ avatar Jul 02 '19 15:07 FrittenKeeZ

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

nobodyiscertain avatar Jul 02 '19 16:07 nobodyiscertain