我想同时从我的数据库和对讲机中删除用户但我想检查这个用户是否存在于对讲机中:
public function deleteUserAction(Request $request, $id)
{
$doctrine = $this->getDoctrine();
$em = $doctrine->getManager();
$intercom = IntercomBasicAuthClient::factory(array(
'app_id' => 'xxxxxx',
'api_key' => 'xxxxxxxxxxxx'
));
$user = $doctrine->getRepository('ZaidUserBundle:User')->find($id);
if($user) {
//delete user from intercom
//I want some condition here
$intercom->deleteUser(array("email" => $user->getEmail()));
//delete user from database
$em->remove($user);
$em->flush();
}
return new Response(200);
}
如此处的文档中所述,您应该通过电子邮件检索用户,只需:
// Find user by email
$intercom->getUser(array("email" => "bob@example.com"));
希望这个帮助
谢谢马特奥此解决方案对我有用
public function deleteUserAction(Request $request, $id)
{
$doctrine = $this->getDoctrine();
$em = $doctrine->getManager();
$intercom = IntercomBasicAuthClient::factory(array(
'app_id' => 'xxxxxx',
'api_key' => 'xxxxxxxxxxxx'
));
$user = $doctrine->getRepository('ZaidUserBundle:User')->find($id);
$existe = 1;
if($user) {
//delete user from intercom
//I want some condition here
try{
$intercom->deleteUser(array("email" => $user->getEmail()));
} catch (IntercomExceptionIntercomException $e) {
$existe = 0;
}
//delete user from database
if($existe==1){
$em->remove($user);
$em->flush();
}
}
return new Response(200);
}