statamic / v2-hub

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

Statamic doesn't produce the directory and index.md files properly when creating a new page while having a non-default locale active #2531

Open LucasAppleseeds opened 4 years ago

LucasAppleseeds commented 4 years ago

Describe the bug Primary locale: English (EN, en_US, English, /) Secondary locale: Portuguese (PT, pt_BR, Portuguese, /pt/)

If I create a completely fresh new page while having Portuguese locale active, upon clicking Save Statamic will create the directory .../site/content/pages/__test-page (does not contain a sorting number). Additionally, index.md within said directory will be blank except for a single line for 'id'. All contents are populated onto pt.index.md instead - i.e. id, title, fieldset, etc. values.

From then onwards:

  1. If I attempt to do a subsequent Save while still on the Portuguese, I'll be prompted with a "There was a problem saving your data" error (error in logs is pasted at the bottom). Statamic at this point has created another directory for the page: .../site/content/pages/_6.test-page (has a sorting number this time).
  2. Switching back to English, the contents are completely blank including a missing title - which has to be specified manually before I can then Save.
  3. Only now can both my English and Portuguese edit forms be Saved. This affects the index.md files in the newer directory which has the sorting number.
  4. Statamic prompts warnings of duplicate IDs sourcing from the two directories that were created in the process.
  5. When I delete the page that is visible on the CP, it deletes the directory without the sorting number, leaving the "correct" one in place.

To Reproduce Steps to reproduce the behavior:

  1. Create an additional secondary site locale via Statamic CP Settings.
  2. Go to 'Pages' on the Statamic CP.
  3. Switch active locale to the secondary locale.
  4. Click 'Create Page' - secondary locale will still be active on the creation form.
  5. Click 'Save' to produce the new page (index.md files are produced).

Expected behavior When creating a new page whilst having a secondary locale active, it should produce the relevant directory/files to the same outcome it would produce if I were to instead create (with a Save) the page while on the default locale prior to switching to the secondary locale and modifying that.

Screenshots imgur album of screenshots: https://imgur.com/a/UBe1eyc

Environment details (please complete the following information):

Additional context

  1. Error message produced in the logs when attempting to Save (see Description):

    [2020-11-11 09:18:04] production.ERROR: Cannot add [pages/_test-page/index.md] to Stache repository [pagestructure]. File at [pages/_6.test-page/index.md] already exists in repository [pages] with an ID of [43f8915e-b350-4dc0-90ea-d853cab828b9].  
    [2020-11-11 09:18:04] production.ERROR: League\Flysystem\FileExistsException: File already exists at path: pages/_test-page/index.md in /Users/lucaslim/dev/statamic/statamic/vendor/league/flysystem/src/Filesystem.php:405
  2. A different accompanying issue: If I switch active locales whilst on the Create Page form, Statamic appends 'fieldset: home' onto my index.md file(s).

  3. When attempting the same procedure on creating a new Collection entry, it leaves the default locale copy of the entry with a slug as its title, but there are no issues with directory/file creation nor any errors when attempting to Save.