2

I wanted to continu a project I haven't touched in a while, and came across this error when executing
php bin/console doctrine:generate:entites SalonBundle (it's from shell, so it use PHP CLI)

Generating entities for bundle "SalonBundle"
> backing up Salon.php to Salon.php~
> generating SalonBundle\Entity\Salon

[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: chmod(): Operation not permitted

doctrine:generate:entities [--path PATH] [--no-backup] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> <name>

To begin with, I'm not sure why Symfony try a chmod
All files are owned by root:www-data
File permissions are rw-rw-r--
My user is in group www-data
upload, creating file, copy, move, etc works fine

The permissions are set via a script which run the following commands
$targetDiris the path passed as argument to the script.

chown -R root:www-data $targerDir
find $targerDir -type d -exec chmod ug+rwx "{}" \;
find $targerDir -type f -exec chmod ug+rw "{}" \;
find $targerDir -type d -exec chmod g+s "{}" \;
find $targerDir -type d -exec setfacl -m g:www-data:rwx,d:g:www-data:rwx "{}" \;
find $targerDir -type f -exec setfacl -m g:www-data:rw- "{}" \;

Just added -vvv to the command line as suggested by someone and got this:

Exception trace:
() at /var/www/3DH/salon/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/EntityGenerator.php:392
Symfony\Component\Debug\ErrorHandler->handleError() at n/a:n/a
chmod() at /var/www/3DH/salon/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/EntityGenerator.php:392
Doctrine\ORM\Tools\EntityGenerator->writeEntityClass() at /var/www/3DH/salon/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/EntityGenerator.php:347
Doctrine\ORM\Tools\EntityGenerator->generate() at /var/www/3DH/salon/vendor/doctrine/doctrine-bundle/Command/GenerateEntitiesDoctrineCommand.php:133
Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute() at /var/www/3DH/salon/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:256
Symfony\Component\Console\Command\Command->run() at /var/www/3DH/salon/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:837
Symfony\Component\Console\Application->doRunCommand() at /var/www/3DH/salon/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:187
Symfony\Component\Console\Application->doRun() at /var/www/3DH/salon/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/3DH/salon/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:118
Symfony\Component\Console\Application->run() at /var/www/3DH/salon/bin/console:27

This topic provide no solutions
This solution doesn't apply to me as I don't use vagrant (not installed)

Community
  • 1
  • 1
Preciel
  • 2,666
  • 3
  • 20
  • 45

1 Answers1

0

Well, I understood the problem.
I would say I'm stupid in the first place I guess...

@john Smith: You weren't far off...

In fact, my problem is just logic...
Trying to chmod a file owned by root with a regular user is impossible...
And that's normal

Every files generated in the src/ folder are made from the files(lets call them tools) in /vendor/doctrine/orm/lib/Doctrine/ORM/Tools/
And of course files are owned by the user who user these tools (twig, entity, form, etc)
When generating a file, these tools try to chmod the new file in case we were dumb enough to not set right our folders & files permissions.

In my case, as I did a pass of my webperms script, all files were owner by root:www-data.
So of course, when I try to generate entities, it would fail because I wasn't the file owner anymore.

There are currently two solutions to this problem:

  1. Change src/ files ownership to user:www-data
  2. Comment the chmodcommand in the tools located in /vendor/doctrine/orm/lib/Doctrine/ORM/Tools/

I'm not sure how to contact the symfony team, but I would suggest to add an if condition, which would depend of a symfony parameter and allow us to bypass this chmod

Preciel
  • 2,666
  • 3
  • 20
  • 45