1

我想同时从我的数据库和对讲机中删除一个用户,但我想检查该用户是否存在于对讲机中:

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);
}
4

2 回答 2

1

As described in the doc here, you should retrieve an user by email simply as:

// Find user by email
$intercom->getUser(array("email" => "bob@example.com"));

Hope this help

于 2017-04-06T14:03:08.470 回答
0

谢谢Matteo,这个解决方案对我有用

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 (\Intercom\Exception\IntercomException $e) {
                $existe = 0;
            }
        //delete user from database
if($existe==1){
        $em->remove($user);
        $em->flush();
}
    }

    return new Response(200);
}
于 2017-05-25T02:18:17.780 回答