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

The make: command doesn't run correctly when an entity with annotations has been found. #1212

Closed
tamsirgueye opened this issue Sep 26, 2022 · 7 comments
Labels
Status: Waiting Feedback Needs feedback from the author

Comments

@tamsirgueye
Copy link

Hi
I don't speak english very well, so i write comment in French.

Je travaille sur un nouveau projet avec api-platform. Après avoir mis en place le système d'authentification par le biais de lexik/LexikJWTAuthenticationBundle, j'ai voulu implémenté un système de rafraîchissement de token avec markitosgv/JWTRefreshTokenBundle. Ce bundle génére une entité qui utilise les annotations. Mais cette entité empêche le maker-bundle de fonctionner correctement.

@tamsirgueye tamsirgueye changed the title The make: command doesn't run correctly when an entity with annotations is found. The make: command doesn't run correctly when an entity with annotations has found. Sep 26, 2022
@tamsirgueye tamsirgueye changed the title The make: command doesn't run correctly when an entity with annotations has found. The make: command doesn't run correctly when an entity with annotations has been found. Sep 26, 2022
@weaverryan
Copy link
Member

Google translation, for my sake and others :)

I am working on a new project with api-platform. After setting up the authentication system through lexik/LexikJWTAuthenticationBundle, I wanted to implement a token refresh system with markitosgv/JWTRefreshTokenBundle. This bundle generates an entity that uses annotations. But this entity prevents the maker-bundle from working properly.

This bundle generates an entity that uses annotations

If you're using PHP 8 and a new enough DoctrineBundle, it should generate attributes, not annotations. If you are using a new project, I would expect that everything would be "new enough" to use attributes. What version of PHP and Symfony are you using?

But this entity prevents the maker-bundle from working properly.

Do you get an error?

@weaverryan weaverryan added the Status: Waiting Feedback Needs feedback from the author label Sep 27, 2022
@tamsirgueye
Copy link
Author

tamsirgueye commented Sep 27, 2022

Google translation

First of all thank you for your quick response.

If you're using PHP 8 and a new enough DoctrineBundle, it should generate attributes, not annotations. If you are using a new project, I would expect that everything would be "new enough" to use attributes. What version of PHP and Symfony are you using?

I am using php 8.1 and symfony 6.1.4

Do you get an error?

Yes I get the following errors :

after a symfony console make:user
make command error

Here is the incomplete User class generated by the command

  <?php
  
  namespace App\Entity;
  
  use App\Repository\UserRepository;
  use Doctrine\ORM\Mapping as ORM;
  
  #[ORM\Entity(repositoryClass: UserRepository::class)]
  class User
  {
      #[ORM\Id]
      #[ORM\GeneratedValue]
      #[ORM\Column]
      private ?int $id = null;
  
      public function getId(): ?int
      {
          return $this->id;
      }
  }

The repository is correctly generated

After a symfony console make:entity Post
make entity command error

If I remove the RefreshToken class generated by the bundle, everything works fine. Here is its content

  <?php
  
  namespace App\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;
  
  /**
   * @ORM\Entity
   * @ORM\Table("refresh_tokens")
   */
  class RefreshToken extends BaseRefreshToken
  {
  }

After several tests I made the following observations:

  • The error is displayed if the RefreshToken class is the only entity present in /src/Entity
  • If I put the equivalent attribute of the annotations without deleting the annotations everything works correctly
  • But if I completely replace the annotations with attributes I see the error
  • The symfony console make:controller command works fine.

I assume that for the make command to correctly create a class in the src/Entity folder, it must be empty or contain at least one class with attributes.
What do you think?

@weaverryan
Copy link
Member

Hi!

But if I completely replace the annotations with attributes I see the error

So if you make RefreshToken only use attributes:

  namespace App\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;
  
  #[ORM\Entity]
  #[ORM\Table('refresh_tokens')]
  class RefreshToken extends BaseRefreshToken
  {
  }

Then you DO get an error in this situation? Is this the same error that you posted above in the screenshots?

Also, you mentioned:

If I remove the RefreshToken class generated by the bundle

What command did you run to generate this RefreshToken class? There is no support in MakerBundle to generate an entity for this bundle.

@tamsirgueye
Copy link
Author

tamsirgueye commented Sep 28, 2022

Hi, thank you for your feedback 👍

So if you make RefreshToken only use attributes:
...
Then you DO get an error in this situation? Is this the same error that you posted above in the screenshots?

Yes of course!

What command did you run to generate this RefreshToken class? There is no support in MakerBundle to generate an entity for this bundle.

The class is generated with the recipe when installing the bundle
This entity allows you to create the table that will keep the refresh tokens

When I add the attributes in addition to the annotations like this, everything works fine

  <?php
  
  namespace App\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;
  
  /**
   * @ORM\Entity
   * @ORM\Table("refresh_tokens")
   */
  #[ORM\Entity]
  #[ORM\Table('refresh_tokens')]
  class RefreshToken extends BaseRefreshToken
  {
  }

@diam
Copy link

diam commented Sep 29, 2022

Moved Comment to Issue #1229 - JR

Same problème here while migrating a projet from sf2.8->sf3.4->sf4.4 (then I could switch php to php-8.1) and trying to go for sf5.4.
The project make use of old annotation system and the symfony console make:user generate new php annotation.

For helping (the user of) google to find the present issue, I add the error message which only appear here in a screenshot:

Cannot find the entity manager for class "App\Entity\User"

@cklm
Copy link

cklm commented Feb 16, 2023

I had the same problem (symfony 5.4 on php 8.1) - in my case I'm using a trait from a bundle in an entity which uses annotations. Its not possible to mix annotations and attributes - annotations will be ignored, if there are attributes.

The solution to use the maker-bundle is to have one attribute somewhere in an entity. One attribute is enough to point doctrine to the App\Entity-namespace. Then php bin/console make:user runs through and the attributes can be removed again.

@jrushlow
Copy link
Collaborator

I'm going to go ahead and close this - annotation support was dropped a few releases ago.

For help upgrading entities to use attributes, see the comments in #1294

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Waiting Feedback Needs feedback from the author
Projects
None yet
Development

No branches or pull requests

5 participants