-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix crashes in ConvertMappingCommand and GenerateEntitiesCommand... #1345
Fix crashes in ConvertMappingCommand and GenerateEntitiesCommand... #1345
Conversation
… using entities with joined table inheritance ConvertMappingCommand and GenerateEntitiesCommand both use the DisconnectedClassMetadataFactory, which allows metadata manipulation without loading the associated classes. Commit a36bea broke these two commands by adding a bailout condition in ClassMetadataFactory::populateDiscriminatorValue which checks $metadata->reflClass->isAbstract(). If the DisconnectedClassMetadataFactory is being used, $metadata->reflClass will always be null, causing a fatal error, "Fatal error: Call to a member function isAbstract() on null". This commit adds a check to see if $metadata->reflClass is set before checking isAbstract.
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DDC-3632 We use Jira to track the state of pull requests and the versions they got |
@zeroedin-bill any way to get a test case for this before merge? I can work on it tomorrow otherwise |
@Ocramius I don't have time till late in the week probably :/ travelling and internal bug piles... |
Will try dealing with it during lunch break then |
I could not reproduce the bug. Neither with a Will merge anyway, as the conditional doesn't hurt there. |
…ng-command Fix crashes in ConvertMappingCommand and GenerateEntitiesCommand...
Thanks! |
Fixes [BUG] Call to member function isAbstract on null in mappedEventSubscriber doctrine:generate:entities This seems to be related to the following issue filed on the doctrine github: doctrine/orm#4459 and the following pull request: doctrine/orm#1345 The generate:entities command uses the ```DisconnectedClassMetadataFactory``` and so ```getReflectionClass``` isn't guaranteed to return anything and can be null, as such the following lines in ```LaravelDoctrine\ACL\Mappings\Subscribers\MappedEventSubscriber``` should be changed: From: ``` /** * A MappedSuperClass or Abstract class cannot be instantiated. * * @param ClassMetadata $metadata * * @return bool */ protected function isInstantiable(ClassMetadata $metadata) { if ($metadata->isMappedSuperclass) { return false; } if ($metadata->getReflectionClass()->isAbstract()) { return false; } return true; } ``` To: ``` /** * A MappedSuperClass or Abstract class cannot be instantiated. * * @param ClassMetadata $metadata * * @return bool */ protected function isInstantiable(ClassMetadata $metadata) { if ($metadata->isMappedSuperclass) { return false; } if (!$metadata->getReflectionClass() || $metadata->getReflectionClass()->isAbstract()) { return false; } return true; } ``` I've tried it and it seems to work fine after that - but I don't know if this will affect anything else internally.
Fixes [BUG] Call to member function isAbstract on null in mappedEventSubscriber doctrine:generate:entities This seems to be related to the following issue filed on the doctrine github: doctrine/orm#4459 and the following pull request: doctrine/orm#1345 The generate:entities command uses the ```DisconnectedClassMetadataFactory``` and so ```getReflectionClass``` isn't guaranteed to return anything and can be null, as such the following lines in ```LaravelDoctrine\ACL\Mappings\Subscribers\MappedEventSubscriber``` should be changed: From: ``` /** * A MappedSuperClass or Abstract class cannot be instantiated. * * @param ClassMetadata $metadata * * @return bool */ protected function isInstantiable(ClassMetadata $metadata) { if ($metadata->isMappedSuperclass) { return false; } if ($metadata->getReflectionClass()->isAbstract()) { return false; } return true; } ``` To: ``` /** * A MappedSuperClass or Abstract class cannot be instantiated. * * @param ClassMetadata $metadata * * @return bool */ protected function isInstantiable(ClassMetadata $metadata) { if ($metadata->isMappedSuperclass) { return false; } if (!$metadata->getReflectionClass() || $metadata->getReflectionClass()->isAbstract()) { return false; } return true; } ``` I've tried it and it seems to work fine after that - but I don't know if this will affect anything else internally.
Fixes [BUG] Call to member function isAbstract on null in mappedEventSubscriber doctrine:generate:entities This seems to be related to the following issue filed on the doctrine github: doctrine/orm#4459 and the following pull request: doctrine/orm#1345 The generate:entities command uses the ```DisconnectedClassMetadataFactory``` and so ```getReflectionClass``` isn't guaranteed to return anything and can be null, as such the following lines in ```LaravelDoctrine\ACL\Mappings\Subscribers\MappedEventSubscriber``` should be changed: From: ``` /** * A MappedSuperClass or Abstract class cannot be instantiated. * * @param ClassMetadata $metadata * * @return bool */ protected function isInstantiable(ClassMetadata $metadata) { if ($metadata->isMappedSuperclass) { return false; } if ($metadata->getReflectionClass()->isAbstract()) { return false; } return true; } ``` To: ``` /** * A MappedSuperClass or Abstract class cannot be instantiated. * * @param ClassMetadata $metadata * * @return bool */ protected function isInstantiable(ClassMetadata $metadata) { if ($metadata->isMappedSuperclass) { return false; } if (!$metadata->getReflectionClass() || $metadata->getReflectionClass()->isAbstract()) { return false; } return true; } ``` I've tried it and it seems to work fine after that - but I don't know if this will affect anything else internally.
... when using entities with joined table inheritance
ConvertMappingCommand and GenerateEntitiesCommand both use the DisconnectedClassMetadataFactory, which allows metadata manipulation without loading the associated classes. Commit a36bea broke these two commands by adding a bailout condition in ClassMetadataFactory::populateDiscriminatorValue which checks $metadata->reflClass->isAbstract(). If the DisconnectedClassMetadataFactory is being used, $metadata->reflClass will always be null, causing a fatal error, "Fatal error: Call to a member function isAbstract() on null".
This commit adds a check to see if $metadata->reflClass is set before checking isAbstract.