Example #1
0
while (!$reader->eof()) {
    $invalids[$reader->read()->phone] = null;
}
$logger->info(sprintf(MSG_INVALIDS_READ, sizeof($invalids), sizeof($invalids) !== 1 ? 's' : ''));
$reader->close();
if (!file_exists(SYSTEM_CSV_FILE)) {
    throw new IOException('Could not locate ' . SYSTEM_CSV_FILE);
}
$f = fopen(SYSTEM_CSV_FILE, 'r');
if ($f === false) {
    throw new IOException('Could not open ' . SYSTEM_CSV_FILE . ' for reading');
}
$reader = new CsvFileReader($f);
$reader->addFields($config['csv.fields']);
$pos = 0;
$counter = new Counter(true, [COUNT_CREATED, COUNT_EXISTING, COUNT_NEXT_PASS]);
while (!$reader->eof() && ++$pos) {
    $row = $reader->read();
    $logger->debug('-- Read CSV row', [$row]);
    $qb = $client->createQueryBuilder();
    $qb->select('Id')->from('Account')->where('Name = :dealership');
    $account = $qb->setMaxResults(1)->setParameter('dealership', $row->dealership)->getQuery()->getOneOrNullResult();
    if ($account === null) {
        $counter->inc(COUNT_NEXT_PASS);
        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) {
Example #2
0
use DaybreakStudios\Common\IO\IOException;
use DaybreakStudios\Common\Utility\Counter;
use DaybreakStudios\Salesforce\Client;
$logger = getActiveLogger();
$client = new Client($config['sf.username'], $config['sf.token'], SYSTEM_WSDL_FILE);
if (!file_exists(SYSTEM_CSV_FILE)) {
    throw new IOException(sprintf(MSG_FILE_MISSING, SYSTEM_CSV_FILE));
}
$f = fopen(SYSTEM_CSV_FILE, 'r');
if ($f === false) {
    throw new IOException(sprintf(MSG_FILE_NOT_READABLE, SYSTEM_CSV_FILE));
}
$reader = new CsvFileReader($f);
$reader->addFields($config['csv.fields']);
$pos = 0;
$counter = new Counter(true, [COUNT_ACCOUNT_CREATED, COUNT_ACCOUNT_EXISTING, COUNT_CONTACT_CREATED, COUNT_CONTACT_EXISTING]);
while (!$reader->eof() && ++$pos) {
    $row = $reader->read();
    $logger->debug('-- Read CSV row', [$row]);
    $qb = $client->createQueryBuilder();
    $qb->select('Id', 'Name', 'Phone')->from('Account')->where('BillingStreet = :street')->andWhere('BillingCity = :city')->andWhere('BillingState = :state')->andWhere('BillingPostalCode = :zip');
    $account = $qb->setMaxResults(1)->setParameter('street', $row->street)->setParameter('city', $row->city)->setParameter('state', $row->state)->setParameter('zip', $row->zip)->getQuery()->getOneOrNullResult();
    if ($account === null) {
        $sob = new SObject();
        $sob->type = 'Account';
        $sob->fields = ['Name' => $row->dealership, 'BillingStreet' => $row->street, 'BillingCity' => $row->city, 'BillingState' => $row->state, 'BillingPostalCode' => $row->zip];
        if (!DRY_RUN) {
            $result = $client->create($sob);
            if (sizeof($result) === 0) {
                throw new RuntimeException(sprintf(MSG_SF_API_UNKNOWN_ERROR, $pos));
            } else {