XF 2.0 Correct way to clean up orphan title/description phrases on uninstall?

DragonByte Tech

Well-known member
So I'm using the "MasterTitle" style of generating translatable titles for a few parts of my product, but since they don't have an addon ID associated, they don't get removed on uninstall.

If I add the addon ID, they get exported when I export a new phrase XML, which is not desirable.

I don't want to leave orphaned data in the database, so what would be the correct method? Do I simply do a delete from xf_phrase, xf_phrase_compiled, and xf_phrase_map, or do the latter two tables get rebuilt at the end of the uninstallation process and I should only delete orphan phrases from the main phrase table?


Fillip
 
I've just been grabbing the phrase entities with a finder on uninstallation, and iterating over them calling delete().
Thanks :)

For anyone else who might arrive at this thread, this is my uninstall step:

PHP:
    /**
     * @throws \XF\PrintableException
     */
    public function uninstallStep4()
    {
        $conditions = [
            ['title', 'LIKE', 'dbtechEcommerce%'],
            ['title', 'LIKE', 'dbtech_ecommerce_%']
        ];
        
        $phrases = $this->app->finder('XF:Phrase')
            ->whereOr($conditions)
        ->fetch();
        
        /** @var \XF\Entity\Phrase $phrase */
        foreach ($phrases as $phrase)
        {
            $phrase->delete(false);
        }
    }

(The false in delete() ensures no exceptions are thrown, since we don't want to interrupt the uninstall process.)


Fillip
 
Back
Top Bottom