Add check for user class type for cv history #528

This commit is contained in:
Kendrick Chan 2020-12-14 10:56:04 +08:00
parent ba7948c507
commit 0ff930438b

View file

@ -12,6 +12,7 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt
use App\Entity\CVWarrantyHistory;
use App\Entity\CustomerVehicle;
use App\Entity\User;
class CustomerVehicleSerialListener
{
@ -39,7 +40,9 @@ class CustomerVehicleSerialListener
$user = $this->ts->getToken()->getUser();
// 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())
@ -50,6 +53,7 @@ class CustomerVehicleSerialListener
$this->history = $history;
}
}
}
public function postUpdate(CustomerVehicle $cv, LifecycleEventArgs $args)
{
@ -76,6 +80,8 @@ class CustomerVehicleSerialListener
$warr_code = $cv->getWarrantyCode();
// add history
if ($user instanceof App\Entity\User)
{
$history = new CVWarrantyHistory();
$history->setCVID($cv->getID())
->setWarrantyCode($warr_code)
@ -85,4 +91,5 @@ class CustomerVehicleSerialListener
$em->flush();
}
}
}