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

[MediaBundle] Treeview incorrect #3383

Open
stanv923 opened this issue Apr 2, 2024 · 3 comments
Open

[MediaBundle] Treeview incorrect #3383

stanv923 opened this issue Apr 2, 2024 · 3 comments

Comments

@stanv923
Copy link

stanv923 commented Apr 2, 2024

I was reordering media folders in the CMS and when i move a specific folder to the root folder, the treeview on the left side shows only the folder contents of that specific folder. When i click media again i see the root folder again in the treeview but the subfolder is missing. In the content view (middle of the screen) the folder does appear. So the treeview and the contents view differ. When i look in the database i can see that the there are many rows in the kuma_folders table that have negative lft and rgt values.

I have also tried:

@delboy1978uk
Copy link
Contributor

delboy1978uk commented Apr 2, 2024

Possibly related, I've literally just run into this error:
Kunstmaan\MenuBundle\Twig\MenuTwigExtension::getMenu(): Return value must be of type string, array returned
In vendor/gedmo/doctrine-extensions/src/Tree/RepositoryUtils::buildTree() we can see the following comment on line 118:

// If you don't want any html output it will return the nested array

The twig extension was changed in commit c48c515 on 24/03/2024
It (obviously) works when I change the return type to string|array

@vytenis-sciukas-nfq
Copy link

Ive stumbled upon this issue myself, can confirm it exists, tree rebuilding inside media bundle happens to properly support only two levels deep, as it orders items by parent ID, if you have further nesting you end up with incorrect levels that breaks tree. Ive used gedmo recover and my tree is flawless, but some events triggers something and tree breaks after some changes. Im still trying to figure out where.

@vytenis-sciukas-nfq
Copy link

I ended up overriding folder repository, now for me it seems everything works as expected, so pull request is quite easy I guess.


declare(strict_types=1);

namespace App\Repository;

use Doctrine\ORM\EntityManagerInterface;
use Kunstmaan\MediaBundle\Entity\Folder;
use Kunstmaan\MediaBundle\Repository\FolderRepository;

class ExtendedFolderRepository extends FolderRepository
{
    public function __construct(EntityManagerInterface $em)
    {
        parent::__construct($em, $em->getClassMetadata(Folder::class));
    }

    /**
     * Override incorrectly working code as saving is handled by nested set extension
     *
     * @param Folder $folder
     * @return void
     */
    public function save(Folder $folder)
    {
        $em = $this->getEntityManager();

        $em->persist($folder);
        $em->flush();
    }

    /**
     * Override incorrectly working code with proper original nested set behavior
     *
     * @return void
     */
    public function rebuildTree()
    {
        $this->recover(['flush' => true]);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants