define('COUNT_CREATED', 'COUNT_CREATED'); define('COUNT_EXISTING', 'COUNT_EXISTING'); define('COUNT_NEXT_PASS', 'COUNT_NEXT_PASS'); define('LOGGING_CHANNEL', 'pass1'); define('LOGGING_LEVEL', 'DEBUG'); define('LOGGING_FORK_TO_STDOUT', true); define('DRY_RUN', true); require __DIR__ . '/bootstrap.php'; use RuntimeException; use SObject; use DaybreakStudios\Common\IO\CsvFileReader; 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_INVALIDS_FILE)) { throw new IOException(sprintf(MSG_FILE_MISSING, SYSTEM_INVALIDS_FILE)); } $f = fopen(SYSTEM_INVALIDS_FILE, 'r'); if ($f === false) { throw new IOException(sprintf(MSG_FILE_NOT_READABLE, SYSTEM_INVALIDS_FILE)); } $reader = new CsvFileReader($f); $reader->addField('phone', 'cleanPhone'); $invalids = []; while (!$reader->eof()) { $invalids[$reader->read()->phone] = null; } $logger->info(sprintf(MSG_INVALIDS_READ, sizeof($invalids), sizeof($invalids) !== 1 ? 's' : ''));
define('MSG_SF_ACCOUNT_CREATED', sprintf(MSG_SF_OBJECT_CREATED, 'Account', '%s')); define('MSG_SF_CONTACT_CREATED', sprintf(MSG_SF_OBJECT_CREATED, 'Contact', '%s')); define('MSG_SF_OBJECT_FOUND', 'Found %s with Id %s'); define('MSG_SF_WILL_CREATE_OBJECT', 'No %s match; a new one will be created'); define('MSG_SF_UNRELIABLE_PHONE_LOOKUP', 'Row %d\'s phone number is not 10 digits, and may not be reliably looked up'); Monolog\Registry::addLogger(makeLogger(LOGGING_GLOBAL_CHANNEL, LOGGING_GLOBAL_LEVEL)); set_error_handler(function ($number, $text, $file, $line) { if (!(error_reporting() & $number)) { return; } getActiveLogger()->critical($text); printf("%s in %s on line %d\n", $text, $file, $line); die; }); set_exception_handler(function (\Exception $e) { getActiveLogger()->critical($e->getMessage(), [$e->getTraceAsString()]); $trace = "\t" . implode("\n\t", explode("\n", $e->getTraceAsString())); printf("Uncaught Exception: %s\n\nStack Trace: \n%s\n", $e->getMessage(), $trace); die; }); $config = Symfony\Component\Yaml\Yaml::parse(file_get_contents(SYSTEM_CONFIG_FILE)); function makeLogger($channel, $level) { $logger = new Monolog\Logger($channel); $file = defined('LOGGING_LOG_FILE') ? LOGGING_LOG_FILE : LOGGING_GLOBAL_LOG_FILE; if (!file_exists($file)) { if (!file_exists(dirname($file))) { mkdir(dirname($file), 755, true); } touch($file); }