public function create($contact = array())
 {
     if (is_array($contact)) {
         $contact = new Contact($contact);
     } elseif (!$contact instanceof Contact) {
         throw new Exception('Not instance of `Contact` class');
     }
     $this->stack[$contact->uniqueHash()] = $contact;
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * `push()` function is taking a `ContactCollection` object as argument. If
  * contact update failed exception will be catched. Result will be array:
  *
  * array['fail'] = ContactCollection();
  *
  */
 public function testPushContactsUpdateFail()
 {
     $data = array('Id' => 1, 'Email' => '*****@*****.**', 'FirstName' => 'FirstName1');
     $failedContact = new Contact();
     $failedContact->setIsFailed();
     $i = $this->getMockBuilder('\\Wildsurfer\\Infusionsoft\\Sync')->disableOriginalConstructor()->setMethods(array('updateContact'))->getMock();
     $i->expects($this->once())->method('updateContact')->will($this->returnValue($failedContact));
     $isdk = $this->getMockedIsdk();
     $i->setIsdk($isdk);
     $collection = new ContactCollection();
     $collection->create($data);
     $expected = $i->push($collection);
     $this->assertEquals(1, $expected['fail']->count());
 }
Ejemplo n.º 3
0
 public function updateContact(Contact $contact)
 {
     $isdk = $this->getIsdk();
     try {
         $remote = $this->loadContact($contact->getId());
         if (is_string($remote)) {
             $contact->setErrorMessage($remote);
             $contact->setIsFailed();
         } else {
             if ($remote->uniqueHash() == $contact->uniqueHash()) {
                 $contact->setIsSkipped();
             } else {
                 $response = $isdk->updateCon($contact->getId(), $contact->getData());
                 if (is_string($response)) {
                     $messsage = 'Add failed. Error:' . $response;
                     $contact->setErrorMessage($messsage);
                     $contact->setIsFailed();
                 } else {
                     $contact->setId($response);
                     $contact->setIsUpdated();
                     $remoteTags = $remote->getTags();
                     $tags = $contact->getTags();
                     $diff = array_diff($tags, $remoteTags);
                     foreach ($diff as $d) {
                         $response1 = $isdk->grpAssign($contact->getId(), $d);
                         if (is_string($response1)) {
                             $messsage1 = 'Add Tag failed. Error:' . $response1;
                             $isdk->updateCon($contact->getId(), $remote->getData());
                             $contact->setErrorMessage($messsage1);
                             $contact->setIsFailed();
                             break;
                         }
                     }
                     $diffRemote = array_diff($remoteTags, $tags);
                     foreach ($diffRemote as $dr) {
                         $response2 = $isdk->grpRemove($contact->getId(), $dr);
                         if (is_string($response2)) {
                             $messsage1 = 'Delete Tag failed. Error:' . $response2;
                             $isdk->updateCon($contact->getId(), $remote->getData());
                             $contact->setErrorMessage($messsage2);
                             $contact->setIsFailed();
                             break;
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $contact->setErrorMessage($e->getMessage());
         $contact->setIsFailed();
     }
     return $contact;
 }
Ejemplo n.º 4
0
 /**
  * Name fields differ from text fields only in that (supposedly) they
  * automatically capitalize the first letter of every word
  */
 public function testSetGetDataNames()
 {
     $data = array('FirstName' => 'test', 'LastName' => 'test e');
     $dataExpected = array('FirstName' => 'Test', 'LastName' => 'Test e', 'OwnerID' => 0);
     $contact = new Contact();
     $contact->setData($data);
     $this->assertEquals($dataExpected, $contact->getData());
 }
Ejemplo n.º 5
0
 public function testPushUpdateWithTags()
 {
     $unique = md5(microtime());
     $isdk = $this->i->getIsdk();
     $tId1 = $isdk->dsAdd('ContactGroup', array('GroupName' => '1' . $unique));
     $tId2 = $isdk->dsAdd('ContactGroup', array('GroupName' => '2' . $unique));
     $tId3 = $isdk->dsAdd('ContactGroup', array('GroupName' => '3' . $unique));
     $validTags = array($tId1 => '1' . $unique, $tId2 => '2' . $unique, $tId3 => '3' . $unique);
     $config = $this->testConfig;
     $config['tags'] = array_keys($validTags);
     $i = new Sync($config);
     $contact = new Contact(array('Email' => $unique . '@test.com', 'FirstName' => $unique, 'OwnerID' => 0));
     $contact->setTags(array($tId1));
     $collection = new ContactCollection();
     $collection->create($contact);
     $c = $i->push($collection);
     $read = $c['create']->read();
     $data = reset($read);
     $dataUpdate = $data->getData();
     $dataUpdate['Id'] = $data->getId();
     $contactUpdate = new Contact($dataUpdate);
     $contactUpdate->setTags(array($tId2, $tId3));
     $collection = new ContactCollection();
     $collection->create($contactUpdate);
     $c = $i->push($collection);
     $read = $c['update']->read();
     $data = reset($read);
     $expectedTags = $isdk->dsQuery('ContactGroupAssign', 1000, 0, array('ContactId' => $data->getId()), array('GroupId'));
     $this->assertCount(2, $expectedTags);
     $isdk->dsDelete('Contact', $data->getId());
     $isdk->dsDelete('ContactGroup', $tId1);
     $isdk->dsDelete('ContactGroup', $tId2);
     $isdk->dsDelete('ContactGroup', $tId3);
 }