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

Cannot get DoctrineExtensions to work with Symfony 7 #2778

Open
vitoff34 opened this issue Mar 3, 2024 · 2 comments
Open

Cannot get DoctrineExtensions to work with Symfony 7 #2778

vitoff34 opened this issue Mar 3, 2024 · 2 comments

Comments

@vitoff34
Copy link

vitoff34 commented Mar 3, 2024

I am running Symfony 7. These are my settings files.
doctrine.yaml

        mappings:
            App:
                type: attribute
                is_bundle: false
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App
            loggable:
                type: attribute # or annotation or xml
                alias: Gedmo
                prefix: Gedmo\Loggable\Entity
                dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Loggable/Entity"
            translatable:
                type: attribute # or annotation or xml
                alias: Gedmo
                prefix: Gedmo\Translatable\Entity
                # make sure vendor library location is correct
                dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity"

services.yaml:

    annotation_reader:
        class: Doctrine\Common\Annotations\AnnotationReader

    Gedmo\Translatable\TranslatableListener:
        tags:
            - { name: doctrine.event_listener, event: 'postLoad' }
            - { name: doctrine.event_listener, event: 'postPersist' }
            - { name: doctrine.event_listener, event: 'preFlush' }
            - { name: doctrine.event_listener, event: 'onFlush' }
            - { name: doctrine.event_listener, event: 'loadClassMetadata' }
        calls:
            - [ setAnnotationReader, [ "@annotation_reader" ] ]
            - [ setDefaultLocale, [ "%kernel.default_locale%" ] ]
            - [ setTranslationFallback, [ false ] ]

    Gedmo\Loggable\LoggableListener:
        tags:
            - { name: doctrine.event_listener, event: 'onFlush' }
            - { name: doctrine.event_listener, event: 'loadClassMetadata' }
            - { name: doctrine.event_listener, event: 'postPersist' }
        calls:
            - [ setAnnotationReader, [ "@annotation_reader" ] ]

composer.json

{
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "stable",
    "prefer-stable": true,
    "require": {
        "php": ">=8.2",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "doctrine/annotations": "^2.0",
        "doctrine/dbal": "^3",
        "doctrine/doctrine-bundle": "^2.11",
        "doctrine/doctrine-migrations-bundle": "^3.3",
        "doctrine/orm": "^3.0",
        "friendsofsymfony/jsrouting-bundle": "^3.5",
        "gedmo/doctrine-extensions": "3.13.0",
        "symfony/asset": "7.0.*",
        "symfony/asset-mapper": "7.0.*",
        "symfony/cache": "6.4",
        "symfony/console": "7.0.*",
        "symfony/dotenv": "7.0.*",
        "symfony/flex": "^2.4",
        "symfony/form": "7.0.*",
        "symfony/framework-bundle": "7.0.*",
        "symfony/mailer": "7.0.*",
        "symfony/runtime": "7.0.*",
        "symfony/security-bundle": "7.0.*",
        "symfony/translation": "7.0.*",
        "symfony/twig-bundle": "7.0.*",
        "symfony/validator": "7.0.*",
        "symfony/yaml": "7.0.*",
        "symfonycasts/verify-email-bundle": "^1.16",
        "twig/extra-bundle": "^2.12|^3.0",
        "twig/twig": "^2.12|^3.0"
    },
    "config": {
        "allow-plugins": {
            "php-http/discovery": true,
            "symfony/flex": true,
            "symfony/runtime": true
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*",
        "symfony/polyfill-php73": "*",
        "symfony/polyfill-php74": "*",
        "symfony/polyfill-php80": "*",
        "symfony/polyfill-php81": "*",
        "symfony/polyfill-php82": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd",
            "importmap:install": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "7.0.*"
        }
    },
    "require-dev": {
        "symfony/maker-bundle": "^1.55",
        "symfony/stopwatch": "7.0.*",
        "symfony/web-profiler-bundle": "7.0.*"
    }
}

I want to implement Loggable and Translatable for my Recipe Entity.

<?php

namespace App\Entity;

use App\Repository\RecipeRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Loggable\Loggable;
use Gedmo\Mapping\Annotation as Gedmo;

#[ORM\Entity(repositoryClass: RecipeRepository::class)]
#[Gedmo\Loggable]
class Recipe
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\OneToOne(inversedBy: 'recipe', cascade: ['persist', 'remove'])]
    private ?Product $product = null;

    #[Gedmo\Loggable]
    #[ORM\Column(length: 255, nullable: false)]
    private ?string $title = null;

    #[ORM\Column(type: Types::TEXT, nullable: true)]
    private ?string $description = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $timeToCook = null;

    public function getId(): ?int
    {
        return $this->id;
    }
}


When I run php bin/console doctrine:mapping:info I get this error:
assert($metadata instanceof DocumentClassMetadata || $metadata instanceof EntityClassMetadata).

This is the stack trace:

[debug] Notified event "console.command" to listener "Symfony\Bundle\FrameworkBundle\EventListener\ConsoleProfilerListener::initialize".
[debug] Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
 Found 16 mapped entities:

[critical] Error thrown while running command "doctrine:mapping:info -vvv". Message: "assert($metadata instanceof DocumentClassMetadata || $metadata instanceof EntityClassMetadata)"
[debug] Notified event "console.error" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SuggestMissingPackageSubscriber::onConsoleError".
[debug] Notified event "console.error" to listener "Symfony\Bundle\MakerBundle\Event\ConsoleErrorSubscriber::onConsoleError".
[debug] Notified event "console.error" to listener "Symfony\Component\Console\EventListener\ErrorListener::onConsoleError".
[debug] Notified event "console.error" to listener "Symfony\Bundle\FrameworkBundle\EventListener\ConsoleProfilerListener::catch".
[debug] Command "doctrine:mapping:info -vvv" exited with code "1"
[debug] Notified event "console.terminate" to listener "Symfony\Bundle\MakerBundle\Event\ConsoleErrorSubscriber::onConsoleTerminate".
[debug] Notified event "console.terminate" to listener "Symfony\Component\Console\EventListener\ErrorListener::onConsoleTerminate".
[debug] Notified event "console.terminate" to listener "Symfony\Bundle\FrameworkBundle\EventListener\ConsoleProfilerListener::profile".
[critical] Uncaught Error: assert($metadata instanceof DocumentClassMetadata || $metadata instanceof EntityClassMetadata)

Thank you for any help.

@mbabker
Copy link
Contributor

mbabker commented Mar 4, 2024

ORM 3.0 is not yet supported by this package, downgrade to 2.18.

@mbabker
Copy link
Contributor

mbabker commented Apr 29, 2024

This particular issue can be closed out. I just checked all of the assert() calls and they are looking for the right ClassMetadata objects for each version of the ORM in the latest release.

There's still work to do for ORM 3.x compat, but this isn't one of the things needing attention it appears.

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

2 participants