Same UUID assigned to different pages

Hi! I’m encountering a bug on a live client site where multiple different pages have apparently been assigned identical UUIDs, which leads to pages fields not working properly. Is this a known bug? Do you have any idea what might have been the cause of this error and what steps I can take to fix it?

The site has been running on Kirby 4.6.1. I’m now updating to the most recent version. As a quick fix I’m temporarily changing the pages field to store IDs instead of UUIDs.

All the best!

Edit: even with stored IDs the pages field seems to get confused and stores the ID of the wrong page.

Can you reproduce the issue in a Starterkit of the same Kirby version? Could it be that those duplicated UUID were created through page duplication? As far as I recall, that used to be an issue but not exactly sure which update fixed that, guess that was long before 4.6

Had same issue when on 4.4.1. Also some weird folders called “new” popping up when drafts where created.

The steps I took was

  1. I had to update a custom custom plugin which made use of the uuid in a property. Might not apply to you but do a search for uuid in blueprints and plugins.

I changed this line:
return $this->model()->uuid()->id();

To this
return $this->model()->content()->get("uuid")->value();

  1. update to 4.7

  2. Clean the cache, including the uuid cache! On the live server I had to do that by ssh as ftp didn’t handle the big number of files very well

  3. Finally you can force Kirby to regenerate the uuid cache in one go, there’s a method for that which I can’t recall at the moment

This script might help to identify duplicates and verify you don’t have any left after the remedy. Put it in a template. It’s originally based on something I found on this forum, should credit someone but it was a while ago so I don’t know who.

<?php
  
  // Use Kirby CMS content directory
  $directory = kirby()->root('content');
  
  $uuidPattern = '/^Uuid:\s*([a-zA-Z0-9-]+)/m';
  $uuids = [];
  $duplicates = [];
  
  function scanDirectory($dir)
  {
      $files = [];
      $items = scandir($dir);
      foreach ($items as $item) {
          if ($item === '.' || $item === '..') continue;
          $path = $dir . DIRECTORY_SEPARATOR . $item;
          if (is_dir($path)) {
              $files = array_merge($files, scanDirectory($path));
          } elseif (pathinfo($path, PATHINFO_EXTENSION) === 'txt') {
              $files[] = $path;
          }
      }
      return $files;
  }
  
  // Scan content folder
  $txtFiles = scanDirectory($directory);
  
  // Detect duplicates
  foreach ($txtFiles as $file) {
      $content = file_get_contents($file);
      if (preg_match($uuidPattern, $content, $matches)) {
          $uuid = $matches[1];
          if (isset($uuids[$uuid])) {
              $duplicates[$uuid][] = $file;
          } else {
              $uuids[$uuid] = [$file];
          }
      }
  }
  
  // Output results as HTML
  echo '<main class="wrapper">';
  echo '<h1>Duplicate UUID Checker</h1>';
  
  if (!empty($duplicates)) {
      echo "<h2>Duplicate UUIDs found:</h2><ul>";
      foreach ($duplicates as $uuid => $files) {
          echo "<li><strong>UUID: $uuid</strong><ul>";
          foreach ($files as $file) {
              echo "<li>$file</li>";
          }
          echo "</ul></li>";
      }
      echo "</ul>";
  } else {
      echo "<p>No duplicate UUIDs found.</p>";
  }

Might be related to this issue:

Basically, don’t use page.uuid in your blueprints for now.

Interesting, thanks a lot for the hint. I’ve had the __new__ issue as well.

I’m actually using slug: "{{ site.time }}-{{page.title.slug}}" in a custom page creation dialog, but displaying the page’s UUID with text: "{{ page.permalink }}" in a text field in the sidebar. I’ll remove that field for now.

Thank you for this! Turns out there’s way more same UUIDs than I thought. I’ll clean the cache and regenerate UUIDs. The method is Uuids::generate('pages') (see Regenerate page uuids - #2 by texnixe)

Meanwhile I’ve upgraded Kirby to the latest version and removed the field where the UUID is shown to the user. Let’s see if the issue persists.

1 Like