Example #1
0
if ($unvalidated_supporters->num_rows > 0) {
    while ($unvalidated_supporter_arr = $unvalidated_supporters->fetch_assoc()) {
        $supporter = new Supporter($unvalidated_supporter_arr);
        $supporter->geovalidate();
        $supporter->db_update();
        $supporter->data['key'] = $supporter->data['supporter_KEY'];
        //$dia->save('supporter', $supporter->data);
    }
}
#update counts
$last_modified_condition = "Last_Modified >= '" . $update_count_date . "'";
update_counts('supporter_action', 'updateActionCounts', $last_modified_condition);
update_counts('donation', 'updateDonationCounts', $last_modified_condition);
update_counts('email', 'updateEmailCounts', $last_modified_condition);
update_counts('unsubscribe', 'updateUnsubscribeInfo', $last_modified_condition);
update_counts('unsubscribe', 'updateUnsubscribeInfo', "receive_email < 1 AND (data__unsub_method IS NULL OR data__unsub_method = '')");
function update_counts($table, $method_name, $condition)
{
    global $db;
    $new = $db->query("SELECT DISTINCT supporter_KEY FROM " . $table . " WHERE " . $condition);
    if ($new->num_rows > 0) {
        while ($new_arr = $new->fetch_assoc()) {
            $supporter_info = $db->query("SELECT * FROM supporter WHERE supporter_KEY=" . $new_arr['supporter_KEY'])->fetch_assoc();
            $supporter = new Supporter($supporter_info);
            $supporter->{$method_name}();
            $supporter->db_update();
            $supporter->data['key'] = $supporter->data['supporter_KEY'];
            //$dia->save('supporter', $supporter->data);
        }
    }
}
<?php

require '../../boot.php';
list($cmd, $update_count_date) = $argv;
update_counts('supporter_action', 'updateActionCounts', "Last_Modified > " . $update_count_date);
function update_counts($table, $method_name, $condition)
{
    global $db;
    $new = $db->query("SELECT DISTINCT action_KEY FROM " . $table . " WHERE " . $condition);
    if ($new->num_rows > 0) {
        while ($new_arr = $new->fetch_assoc()) {
            $action_info = $db->query("SELECT * FROM action WHERE action_KEY=" . $new_arr['action_KEY'])->fetch_assoc();
            $action = new Action($action_info);
            $action->{$method_name}();
            $action->data['key'] = $action->data['action_KEY'];
            //$dia->save('action', $action->data);
        }
    }
}