Weird issues - a folder with name "new" is being created too

Hi everyone,

I’m getting a weird error when creating a new draft, another folder called “new” is also created automatically.

This is how it looks, I created a draft called “Telephony in Ansbach” and the draft called “new” was created with it. Is this a known issue and is there a workaround?

Not that I know of.

What’s your Kirby version? do you have any hooks in place? Can you reproduce the issue in a fresh Starterkit?

I’ve been running into the same issue a while back. It was caused by a custom fields value() method calling $page->uuid() too early. Your problem might be different though.

In versions prior to 4.5.0 Kirby would also re-use the uuid assigned to the new page for the page that was created. So you might want to check for duplicate pages with the same Uuid as the new page. Script below for scanning the complete content folder

Issue: Same Uuid is re-used every time when creating a child page · Issue #6640 · getkirby/kirby · GitHub

Here’s a bodge of a php script i wrote while trying to find the duplicated uuids. Save it to something like findDuplicateUuids.php and run it via terminal, passing the path of your content directory as first parameter. Please create a backup before running this.

> php findDuplicateUuids.php path/to/content-folder

<?php

if ($argc !== 2) {
    echo "Usage: php duplicateUuids.php <directory>\n";
    exit(1);
}

$directory = $argv[1];

if (!is_dir($directory)) {
    echo "Error: The provided directory does not exist.\n";
    exit(1);
}

$uuidPattern = '/^Uuid:\s*([a-zA-Z0-9-]+)/m';
$uuids = [];
$duplicates = [];

// Recursive function to scan directory
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 the provided directory for .txt files
$txtFiles = scanDirectory($directory);

// Extract UUIDs from each .txt file
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 the results and remove UUID lines from files with duplicate UUIDs
if (!empty($duplicates)) {
    echo "Duplicate UUIDs found:\n";
    foreach ($duplicates as $uuid => $files) {
        echo "UUID: $uuid\n";
        foreach ($files as $file) {
            echo "  - $file\n";

            // Remove the UUID line from the file
            // $content = file_get_contents($file);
            // $newContent = preg_replace($uuidPattern, '', $content);
            // file_put_contents($file, $newContent);
        }
    }
    // echo "UUID lines removed from files with duplicate UUIDs.\n";
} else {
    echo "No duplicate UUIDs found.\n";
}```

Thanks @Ove

I had version 4.4.1, after I updated to 4.5 the problem is gone!