Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update entry URI's when collection route is changed #378

Open
mthorsdal opened this issue Nov 18, 2024 · 2 comments · May be fixed by statamic/cms#11150
Open

Update entry URI's when collection route is changed #378

mthorsdal opened this issue Nov 18, 2024 · 2 comments · May be fixed by statamic/cms#11150
Assignees
Labels
feature request New feature or request

Comments

@mthorsdal
Copy link

mthorsdal commented Nov 18, 2024

Description

I recently had to change the route of my collection, and I found that due to using eloquent-driver, all the entries of that collection became inaccessible afterwards, as the uri no longer matched the one in entries table

Perhaps a simple command will do the trick?
Claude.ai wrote this one

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Statamic\Facades\Entry;

class UpdateEntryUris extends Command
{
    protected $signature = 'statamic:update-uris';
    protected $description = 'Update entry URIs in database';

    public function handle()
    {
        $entries = Entry::query()->where('collection', 'erlebnisse')->get();
        
        foreach ($entries as $entry) {
            $entry->save(); // This will trigger URI regeneration
            $this->info("Updated URI for entry: {$entry->id()}");
        }

        $this->info('All URIs updated successfully');
    }
}

@mthorsdal mthorsdal added the feature request New feature or request label Nov 18, 2024
@ryanmitchell
Copy link
Contributor

Yes if you change the route all entries need re-saved. I would guess most dev's know this and would write a migration or console task to do this. I dont feel we need to include one in the add-on.

@duncanmcclean
Copy link
Member

Re-opening as I reckon we could support this fairly easily in the Eloquent Driver, like we do for updating collection trees & collection ordering. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
3 participants