Example #1
0
        continue;
    }
    $logger->debug('Found Account with Id ' . $account->Id, [$account]);
    $qb = $client->createQueryBuilder();
    $qb->select('Id')->from('Contact')->where('AccountId = :id')->andWhere($qb->expr()->orX('Phone like :phone', 'Phone_2__c like :phone', 'Phone like :alt', 'Phone_2__c like :alt'));
    $contact = $qb->setMaxResults(1)->setParameter('id', $account->Id)->setParameter('phone', getPhoneLikeStatement($row->phone))->setParameter('alt', getPhoneLikeStatement($row->altPhone))->getQuery()->getOneOrNullResult();
    if ($contact !== null) {
        $counter->inc(COUNT_EXISTING);
        continue;
    }
    $sob = new SObject();
    $sob->type = 'Contact';
    $sob->fields = ['AccountId' => $account->Id, 'FirstName' => $row->firstName, 'LastName' => $row->lastName, 'Phone' => $row->phone, 'Phone_2__c' => $row->altPhone, 'Job_Title__c' => $row->position, 'Street' => $row->street, 'City' => $row->city, 'State' => $row->state, 'PostalCode' => $row->zip];
    $logger->info('Creating new Contact on Account (' . $account->Id . ')', [$sob]);
    if (!DRY_RUN) {
        $result = $client->create($sob);
        if (sizeof($result) === 0) {
            throw new RuntimeException(sprintf(MSG_SF_API_UNKNOWN_ERROR, $pos));
        } else {
            if (!$result[0]->success) {
                throw getSalesforceException($result[0]);
            }
        }
        $logger->debug(sprintf(MSG_SF_CONTACT_CREATED, $result[0]->id), [$result]);
    } else {
        $logger->info(sprintf(MSG_SF_CONTACT_CREATED . ' from row %d', $row->phone, $pos));
    }
    $counter->inc(COUNT_CREATED);
}
$logger->info(sprintf(MSG_PASS_SUMMARY, 1, $counter->get(COUNT_CREATED), $counter->get(COUNT_CREATED) !== 1 ? 's' : '', $counter->get(COUNT_EXISTING), $counter->get(COUNT_EXISTING) !== 1 ? 's' : '', $counter->get(COUNT_NEXT_PASS), $counter->get(COUNT_NEXT_PASS) !== 1 ? 's' : ''));
Example #2
0
        if (strlen($row->phone) !== 10) {
            $logger->warning(sprintf(MSG_SF_UNRELIABLE_PHONE_LOOKUP, $pos));
        }
        $qb = $client->createQueryBuilder();
        $qb->select('Id')->from('Contact')->where('AccountId = :id')->andWhere($qb->expr()->orX('Phone like :phone', 'Phone_2__c like :phone', 'Phone like :alt', 'Phone_2__c like :alt'));
        $contact = $qb->setMaxResults(1)->setParameter('id', $account->Id)->setParameter('phone', getPhoneLikeStatement($row->phone))->setParameter('alt', getPhoneLikeStatement($row->altPhone))->getQuery()->getOneOrNullResult();
        if ($contact !== null) {
            $counter->inc(COUNT_CONTACT_EXISTING);
            continue;
        }
    }
    $sob = new SObject();
    $sob->type = 'Contact';
    $sob->fields = ['AccountId' => $account->Id, 'FirstName' => $row->firstName, 'LastName' => $row->lastName, 'Phone' => $row->phone, 'Phone_2__c' => $row->altPhone, 'Job_Title__c' => $row->position, 'Street' => $row->street, 'City' => $row->city, 'State' => $row->state, 'PostalCode' => $row->zip];
    if (!DRY_RUN) {
        $result = $client->create($sob);
        if (sizeof($result) === 0) {
            throw new RuntimeException(sprintf(MSG_SF_API_UNKNOWN_ERROR, $pos));
        } else {
            if (!$result[0]->success) {
                throw new getSalesforceException($result[0]);
            }
        }
        $logger->debug(sprintf(MSG_SF_CONTACT_CREATED, $result[0]->id), [$result[0]]);
    } else {
        $logger->info(sprintf(MSG_SF_CONTACT_CREATED . ' from row %d', $row->phone, $pos));
    }
    $counter->inc(COUNT_CONTACT_CREATED);
}
$logger->info(sprintf(MSG_PASS3_SUMMARY, $counter->get(COUNT_ACCOUNT_EXISTING), $counter->get(COUNT_ACCOUNT_EXISTING) !== 1 ? 's' : '', $counter->get(COUNT_ACCOUNT_EXISTING) !== 1 ? 'were' : 'was', $counter->get(COUNT_CONTACT_EXISTING), $counter->get(COUNT_CONTACT_EXISTING) !== 1 ? 's' : '', $counter->get(COUNT_ACCOUNT_CREATED), $counter->get(COUNT_ACCOUNT_CREATED) !== 1 ? 's' : '', $counter->get(COUNT_CONTACT_CREATED), $counter->get(COUNT_CONTACT_CREATED) !== 1 ? 's' : ''));