4

I am parsing contacts from Gmail, and creating a sync functionality with my product. But on my script i'm having a hard time determining which contacts get 'deleted' from gmail.

EXAMPLE: If I have John Doe in my Application, along with Gmail... (and they are synced with the gmailId). Later on down the road, if the user DELETES the contact John Doe, and I run my SYNC, how do I determine that the contact was deleted?

I need to know where to throw a trigger to delete the same contact within my database. I currently have this to obtain information on each contact sent through.

$xml = simplexml_load_string($entry->getXML());
$obj = new stdClass;

//    EDIT LINK
$obj->gmailUrl   = rawurlencode($entry->id);                
$obj->delete     =  (string) $xml->groupMembershipInfo['deleted'];

//    FIRST Name
$obj->firstName  = (string) $xml->name->givenName;

Previous in my code i'm also query google with these extra params.

$query->setParam('updated-min', $updatedMin);
$query->setParam('showdeleted', 'true');
$query->setParam('requirealldeleted', 'true');

Any help would be appreciated!

Justin
  • 2,502
  • 7
  • 42
  • 77

2 Answers2

1

I'm not sure about any particular hooks, nor can I see an obvious deleted field, but here is another way to solve the problem...

When you do your full sync, or single item updates, if a particular contact is no longer returned, then you can mark it as deleted. Note, this would only work if you keep showdeleted as false.

Example...

$local = array(1, 3, 5, 7, 9);

You run a full sync...

$remote = array(, 1, 3, 5, 9);

Comparing the two arrays will show that 7 has been deleted. Similarly, if you are synchronizing a single item, if it doesn't return anything you can assume its deleted.

Adrian Schneider
  • 7,239
  • 1
  • 19
  • 13
1

I found out that Google adds an empty XML Tag called Deleted when a contact is deleted.

Something like this.

if(isset($xml->deleted)) { $deleted = "true"; } else { $deleted = NULL; } 
$obj->delete = $deleted;

Although Adrian's solution would work, I felt that wasn't the best solution as I felt Google must to have an answer for this rather than checking to see if a contact was available every day.

Justin
  • 2,502
  • 7
  • 42
  • 77
  • 1
    This however will only be caught if the item was deleted within last 30 days per google's documentation. – jray0039 Feb 27 '13 at 21:25
  • True... For syncing it should be fine, but for that initial blast might be a problem... – Justin Feb 28 '13 at 01:41