Merge branch '528-app-cannot-add-customer-vehicle' into 'master'

Add check for user class type for cv history #528

Closes #528

See merge request jankstudio/resq!613
This commit is contained in:
Kendrick Chan 2020-12-14 02:56:58 +00:00
commit 83e5ea3810

View file

@ -12,6 +12,7 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt
use App\Entity\CVWarrantyHistory; use App\Entity\CVWarrantyHistory;
use App\Entity\CustomerVehicle; use App\Entity\CustomerVehicle;
use App\Entity\User;
class CustomerVehicleSerialListener class CustomerVehicleSerialListener
{ {
@ -39,15 +40,18 @@ class CustomerVehicleSerialListener
$user = $this->ts->getToken()->getUser(); $user = $this->ts->getToken()->getUser();
// error_log('user - ' . $user->getID()); // error_log('user - ' . $user->getID());
// check if user is App\Entity\User
if ($user instanceof App\Entity\User)
{
// add history
$history = new CVWarrantyHistory();
$history->setCVID($cv->getID())
->setWarrantyCode($cv->getWarrantyCode())
->setUser($user);
$em->persist($history);
// add history $this->history = $history;
$history = new CVWarrantyHistory(); }
$history->setCVID($cv->getID())
->setWarrantyCode($cv->getWarrantyCode())
->setUser($user);
$em->persist($history);
$this->history = $history;
} }
} }
@ -76,13 +80,16 @@ class CustomerVehicleSerialListener
$warr_code = $cv->getWarrantyCode(); $warr_code = $cv->getWarrantyCode();
// add history // add history
$history = new CVWarrantyHistory(); if ($user instanceof App\Entity\User)
$history->setCVID($cv->getID()) {
->setWarrantyCode($warr_code) $history = new CVWarrantyHistory();
->setUser($user); $history->setCVID($cv->getID())
$em->persist($history); ->setWarrantyCode($warr_code)
->setUser($user);
$em->persist($history);
$em->flush(); $em->flush();
}
} }
} }