4

I have deleted all Slugs in my DB in hope that they regenerates automatically - but they dont!

Is there any way to trigger the regeneration? When upgrading from TYPO3 < 9 the get initially generated - but how?

Thanks for helping :)

Peter Kraume
  • 3,577
  • 2
  • 21
  • 39
Naderio
  • 1,306
  • 11
  • 26

6 Answers6

17

You can go to Upgrade > Run Upgrade Wizard and mark the wizard Introduce URL parts ("slugs") to all existing pages as undone.

Afterwards you can run this wizard and have the slug field filled for all pages again. Notice that this wizard only processes pages with an empty slug field. If you want to have all existing pages processed execute an SQL query like this:

UPDATE `pages` SET `slug` = NULL;
Mathias Brodala
  • 5,905
  • 13
  • 30
4

You may also have a look a the "slug" extension which provides batch editing of slug fields. https://extensions.typo3.org/extension/slug/

Christian
  • 56
  • 2
  • First look: Nice 1 !! Second Look: Its a Beta with issues - but I will follow this project. That looks promising :) Thanks for pointing to this Extension. – Naderio Feb 01 '19 at 10:32
  • 1
    @Naderio should be stable now. So i would accept this as a good solution – Spears Jul 05 '19 at 08:26
  • Yes, it's stable and seems to be working. Thanks for the hint. – Naderio Jul 05 '19 at 14:51
2

try this

public static function setPageSlug($uid) {
        $fieldConfig = $GLOBALS['TCA']['tablename']['columns']['slug_field_name']['config'];
        $slugHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\SlugHelper::class, 'tablename', 'slug_field_name', $fieldConfig);

        $connection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)->getConnectionForTable('tablename');
        $queryBuilder = $connection->createQueryBuilder();

        $queryBuilder->getRestrictions()->removeAll()->add(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction::class));
        $statement = $queryBuilder->select('*')->from('tablename')->where(
        $queryBuilder->expr()->eq('uid', $uid)
        )->execute();

        $record = $statement->fetch();

        $slug = $slugHelper->generate($record, $record['pid']);

        // Update
        $queryBuilder = $connection->createQueryBuilder();
        $queryBuilder->update('tablename')->where(
        $queryBuilder->expr()->eq('uid', $uid)
        )->set('slug_field_name', $slug)->execute();

        var_dump($slug);
        return $slug;

        }

tablename => name of the table with the slug field

slug_field_name => name of the corresponding slug field

Naderio
  • 1,306
  • 11
  • 26
1

The Answere by Mathias Brodala works exactly as I wanted.

I had to prepare the database before use the Wizard with: UPDATE `pages` SET `slug` = NULL where 1

This deletes all(!!!) Slugs so that they can be recreated by the Wizard.

The Wizard only shows up, when there are records with an empty slug in the table. All Slugs that are already set will be ignored by the Wizard. (i have tested it - nothing gets broken).

An easy and effective solution. Thanks again @Mathias Brodala

Naderio
  • 1,306
  • 11
  • 26
  • I get in trouble with TYPO3 9.5.14 with many sites and translations. The page gets back with 503 status. I Used the command line to start the wizard typo3/sysext/core/bin/typo3 upgrade:pagesSlugs or on composer based systems bin/typo3 upgrade:pagesSlugs – CalleKhan Apr 27 '20 at 19:22
1

TYPO3 has an in-built mechanism for this operation.

Log in to the backend,

  1. Click on Upgrade menu under ADMIN TOOLS
  2. Click on Run Upgrade Wizard on Upgrade Wizard card
  3. Check for Introduce URL parts ("slugs") to all existing pages in the list and click on its wizard. If already executed, check for it under Wizards marked as done list and reactivate it by clicking its Mark undone button and remember to execute its wizard once it reappears in the wizard list at the top. If you encounter a message instead, it means you lack empty slug fields.
John Miller
  • 527
  • 4
  • 15
0

This one populates all empty slugs for a given table (e.g. after importing records from foreign sources into a custom extension):

https://www.typo3tiger.de/blog/post/typo3-extension-slugs-automatisiert-generieren.html

JKB
  • 499
  • 2
  • 13