<?php

/**
 * Update all of the event codes of all existing events.
 */
$debug = isset($_REQUEST['debug']);
header('Content-type: text/' . ($debug ? 'html' : 'x-json'));
require_once '../util/Db.php';
$conn = PdoHelper::getPdo();
$isSuccessful = false;
try {
    $conn->beginTransaction();
    CmaticSchema::updateEventCodes($conn, false);
    $conn->commit();
    $isSuccessful = true;
} catch (Exception $e) {
    $conn->rollBack();
    $conn = null;
}
$conn = null;
?>
{success: <?php 
echo $isSuccessful ? 'true' : 'false';
?>
}
示例#2
0
             }
         }
     }
 }
 // Do the mass update if there is something to do
 if (!empty($newEvents)) {
     $conn->beginTransaction();
     try {
         foreach ($newEvents as $e) {
             // TODO: Consider using binds instead
             $conn->query(sprintf('insert into %s (division_id, sex_id, age_group_id, form_id) values(%d, %d, %d, %d)', $eventDbTable, $e['d'], $e['s'], $e['a'], $e['f']));
         }
         // Update all event codes that are NULL
         // This will include all the newly added ones and any that were
         // somehow missed before.
         if (!CmaticSchema::updateEventCodes($conn, true)) {
             // TODO: Throw cmatic exception about the failed update
             throw new CmaticApiException('Arg, update failed');
         }
         $conn->commit();
         // If we got passed the commit, it's all good, report success
         $isSuccessful = true;
     } catch (Exception $e) {
         $conn->rollBack();
         // This should be in a "finally" block, but PHP doesn't have that
         $conn = null;
         throw $e;
     }
 } else {
     // Got here because we had nothing to do.
     // We'll consider that a success.