Created
May 16, 2014 18:18
-
-
Save cmpaul/aba9e4a985fd59a19554 to your computer and use it in GitHub Desktop.
A quick and dirty PHP script to resend API callback events based on audit logs. See the DQL query for the constraints (date and type).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ResendCallbackEvents { | |
public function __construct() { | |
// Configure Symfony | |
require_once ('/opt/hellofax/config/ProjectConfiguration.class.php'); | |
$configuration = ProjectConfiguration::getApplicationConfiguration('jobapp', 'prod', true); | |
require ($configuration->getConfigCache()->checkConfig(sfConfig::get('sf_config_dir') . '/ops.yml')); | |
sfContext::createInstance($configuration); | |
} | |
public function __destruct() { | |
sfContext::getInstance()->shutdown(); | |
sfCoreAutoload::unregister(); | |
} | |
public function run() { | |
echo "Running...\n"; | |
$dbh = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh(); | |
try { | |
$q = $dbh->query("SELECT ae.id FROM audit_event ae INNER JOIN super_group sg ON sg.id = ae.super_group_id INNER JOIN transmission_group request_tg ON request_tg.super_group_id = sg.id WHERE request_tg.type_code = 'R' AND request_tg.created_via_code = 'B' AND (ae.created_at > '2014-05-14 06:24:00' AND ae.created_at < '2014-05-15 18:15:00') AND ae.type_code IN ('V', 'X', 'S') AND ae.id > 14685945"); | |
$results = $q->fetchAll(); | |
echo "Fetch size: " . count($results) . "\n"; | |
foreach ($results as $audit_event_id) { | |
echo " " . $audit_event_id['id'] . "\n"; | |
$audit_event = Doctrine::getTable("AuditEvent")->findOneById($audit_event_id['id']); | |
$acct = $audit_event->getAccount(); | |
$tsm_group = $audit_event->getTransmissionGroup(); | |
$event_time = $audit_event->getDateTimeObject('created_at')->format('U'); | |
$type_code = $audit_event->getTypeCode(); | |
echo " Audit event=" . $audit_event->getId() . ", acct=" . $acct->getId() . ", tsm_group=" . $tsm_group->getId() . ", time=" . $event_time . ", type=" . $type_code . "\n"; | |
if ($type_code == AuditEvent::TYPE_CODE_VIEW) { | |
$related_sig_id = null; | |
$signer_name = null; | |
$related_data = json_decode($audit_event->getRelatedData(), true); | |
if (isset($related_data['signer_name'])) { | |
$signer_name = $related_data['signer_name']; | |
} | |
if ($signer_name) { | |
echo " signer_name=$signer_name\n"; | |
echo " Finding related signature id...\n"; | |
foreach ($tsm_group->Transmissions as $tsm) { | |
if ($tsm->getRecipientName() == $signer_name) { | |
$related_sig_id = $tsm->getSignatureId(); | |
} | |
} | |
if ($related_sig_id) { | |
echo " related_sig_id=$related_sig_id\n"; | |
} | |
} | |
HFApi::reportTransmissionGroupEvent(HFApi::EVENT_SIGNATURE_REQUEST_VIEWED, $tsm_group, $event_time, 0, $related_sig_id); | |
} elseif ($type_code == AuditEvent::TYPE_CODE_SIGN) { | |
$related_sig_id = $tsm_group->Transmissions[0]->getSignatureId(); | |
if ($related_sig_id) { | |
echo " related_sig_id=$related_sig_id\n"; | |
} | |
HFApi::reportTransmissionGroupEvent(HFApi::EVENT_SIGNATURE_REQUEST_SIGNED, $tsm_group, $event_time, 0, $related_sig_id); | |
} elseif ($type_code == AuditEvent::TYPE_CODE_SEND && $audit_event->SuperGroup->isRequestFlow()) { | |
HFApi::reportTransmissionGroupEvent(HFApi::EVENT_SIGNATURE_REQUEST_SENT, $tsm_group, $event_time); | |
} | |
} | |
} catch (Exception $ex) { | |
echo "Unable to execute: " . $ex->getMessage() . "\n"; | |
} | |
} | |
} | |
echo "Start...\n"; | |
$task = new ResendCallbackEvents(); | |
$task->run(); | |
echo "End!\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment