30 search results

Finding Issues via the Call Graph

…or you can try to call the function less times. In our case, we found that the most problematic function is UnitOfWork::createEntity. But this is a vendor function: it's not our code. So it's not something that we can optimize. And honestly…

6:50
Simpler Validator for Checking State Change

…last tutorial, we put this above that same $dragonTreasures property, but inside the User entity. The validator would loop over each DragonTreasure, use Doctrine's UnitOfWork to get the $originalOwnerId, and then check to see if the $newOwnerId is different from the original. If it…

7:23
The N+1 Problem & EXTRA_LAZY

…view the call graph. Well... this looks familiar! We have the same number 1 exclusive-time function as before: UnitOfWork::createEntity(). In that situation, it meant that we were querying for too many items and so Doctrine was hydrating too many objects. Is it the…

5:59
Running Code "On Publish"

…DragonTreasure objects, loop over them, then use Doctrine's UnitOfWork to see what each DragonTreasure looked like when it was originally loaded from the database. Should we use that same trick here to see what the isPublished property originally looked like? We could... but there…

6:05
Validating how Values Change

…what they originally looked like. So, we are going to solve this with validation... but with the help of a special class from Doctrine called the UnitOfWork. Alrighty, let's whip up a test to shine a light on this pesky bug. Inside tests/Functional/…

8:30
Profiling Command Line scripts

…at the same time... which even lets it try to optimize those queries if it can. But the big problem with our old code was something related to Doctrine's UnitOfWork::computeChangeSet(). Each time you call flush() in Doctrine, it looks at all the objects…

6:33
Comparisons: Validate Performance Changes, Find Side Effects

…call graph, in the darkest blue, the critical path this time is the path that improved the most. Click the UnitOfWork call now. Wow. The inclusive time is down by 90 milliseconds and even the memory plummeted: down 1.39 megabytes. But wait. One of…

3:56
Wall Time, Exclusive Time & Other Wonders

…the biggest problem, according to exclusive time, is this UnitOfWork::createEntity function... whatever that is. If you use Doctrine, you might know what this is - but let's pretend we have no idea. Before we dive further into the root cause behind this slow function…

7:47
The Patterns Behind Doctrine

…simplified code with just some, some dump in there to see the results. So we do the same find() twice and in between we look at the UnitOfWork and at the end we looked at the $order and the $sameOrder, um, are actually the same…

37:39
In that case, you can get the UnitOfWork out of the `EntityManager` and add the object manually to the identityMap `$entityManager->getUnitOfWork()->addToIdentityMap($object);` Cheers!
MolloKhan
MolloKhan
Read Full Comment
Hey,Yes I followed it but got the same problems after running composer install !! In UnitOfWork.php line 2718: !! !! Warning: "continue" targeting switch is equivalent to "break". Did you mean !! to use "continue 2"? !! !! !! Script @auto-scripts was called via post-install-cmd
Heninstoa
Heninstoa
Read Full Comment
A little bit more details: Uncaught PHP Exception ErrorException: "Notice: Undefined index: 000000002e4d2d6e0000000027619249" at /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2997 this is about these lines: public function getEntityIdentifier($entity) { return $this->entityIdentifiers[spl_object_hash($entity)]; } Hope this help!
// ... lines 1 - 10
class TreasuresAllowedOwnerChangeValidator extends ConstraintValidator
{
// ... lines 13 - 16
public function validate($value, Constraint $constraint): void
{
// ... lines 19 - 27
$unitOfWork = $this->entityManager->getUnitOfWork();
foreach ($value as $dragonTreasure) {
// ... lines 30 - 31
$originalData = $unitOfWork->getOriginalEntityData($dragonTreasure);
$originalOwnerId = $originalData['owner_id'];
$newOwnerId = $dragonTreasure->getOwner()->getId();
if (!$originalOwnerId || $originalOwnerId === $newOwnerId) {
return;
}
// the owner is being changed
$this->context->buildViolation($constraint->message)
->addViolation();
}
}
}
See Code Block in Script
// ... lines 1 - 10
class TreasuresAllowedOwnerChangeValidator extends ConstraintValidator
{
// ... lines 13 - 16
public function validate($value, Constraint $constraint)
{
// ... lines 19 - 27
$unitOfWork = $this->entityManager->getUnitOfWork();
foreach ($value as $dragonTreasure) {
assert($dragonTreasure instanceof DragonTreasure);
$originalData = $unitOfWork->getOriginalEntityData($dragonTreasure);
dd($dragonTreasure, $originalData);
}
// ... lines 35 - 39
}
}
See Code Block in Script
// ... lines 1 - 10
class TreasuresAllowedOwnerChangeValidator extends ConstraintValidator
{
// ... lines 13 - 16
public function validate($value, Constraint $constraint)
{
// ... lines 19 - 27
$unitOfWork = $this->entityManager->getUnitOfWork();
foreach ($value as $dragonTreasure) {
assert($dragonTreasure instanceof DragonTreasure);
$originalData = $unitOfWork->getOriginalEntityData($dragonTreasure);
$originalOwnerId = $originalData['owner_id'];
$newOwnerId = $dragonTreasure->getOwner()->getId();
if (!$originalOwnerId || $originalOwnerId === $newOwnerId) {
return;
}
// the owner is being changed
$this->context->buildViolation($constraint->message)
->addViolation();
}
}
}
See Code Block in Script
…entity is holding the ID of the related entity record (docs: https://www.doctrine-project.org/projects/doctrine-orm/en/3.0/reference/unitofwork-associations.html#:~:text=The%20owning%20side%20has%20to,side%20of%20a%20bidirectional%20association.) > Own which side of the ownership can…
MolloKhan
MolloKhan
Read Full Comment
…too many good topics are prioritized for now. Btw, we talked a little bit about UnitOfWork in different tutorials and you may leverage our advanced search to find some related videos: https://symfonycasts.com/search?q=UnitOfWork&sort=most%20relevant&page=1&types=video I hope that helps! Cheers…
…that but it gives error like... ` { "type": "https://tools.ietf.org/html/rfc2616#section-10", "title": "An error occurred", "detail": "Warning: Undefined array key \"000000005fdb2782000000003494e2a0\"", "trace": [ { "namespace": "", "short_class": "", "class": "", "type": "", "function": "", "file": "/app/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php", "line": 1544, "args": [] }, `
Hello, I have a problem at first step of readme. When i run composer install in the project I get: [KO] Script cache:clear returned with error code 1 !! !! In UnitOfWork.php line 2718: !! !! Warning: "continue" targeting switch is equivalent to "break". Did you mean …
Žilvinas N.
Žilvinas N.
Read Full Comment
…Go Pro with Doctrine Queries"? I mean like we do have $unitOfWork where we work with "entityInsertions" | "entityUpdates" | "entityDeletions" or $metadataFactory in Doctrine and there are loads of other complex obstacles when you are working with difficult projects... Since you know professional programmers…