示例#1
0
文件: update.php 项目: dregad/apecove
// ----------------------------------------------------------------------------
// Main block
//
// Get last upload date
$sql = 'SELECT upload_date FROM status';
$status = $db->query($sql)->fetch();
// Get records to upload
echo "Processing rows updated after " . $status['upload_date'] . "\n";
$db->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
$db->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_TO_STRING);
$sql = "SELECT v.*\n\tFROM " . VIEW_MAILCHIMP_EXPORT . " v\n\tJOIN " . MAILCHIMP_TABLE . " mc ON mc.email = v.email\n\tWHERE local_updated > :upload_date\n\t   OR IFNULL( v.erreurs, '' ) <> mc.erreurs";
$query = $db->prepare($sql);
$query->execute($status);
// Only connect to Mailchimp if we have data to process
if ($query->rowCount()) {
    $mc = new MyMailchimp($mailchimp_apikey, $mailchimp_list_name);
    echo "Uploading modified data\n";
}
$num = 0;
$time = microtime(true);
foreach ($query->fetchAll() as $row) {
    printf('  Processing row #%d - %s: ', ++$num, $row['EMAIL']);
    // Get corresponding Mailchimp list member
    $member = $mc->getMember($row['EMAIL']);
    // Refuse to update rows that have been changed in Mailchimp
    if (is_null($member)) {
        continue;
    } elseif ($member['info_changed'] != $row['MC_UPDATED']) {
        echo "Skipped\n    Last updated dates do not match (MC: " . $member['info_changed'] . ' - local: ' . $row['MC_UPDATED'] . ")\n";
        continue;
    }
 function __construct($apikey, $list_name)
 {
     parent::__construct($apikey, $list_name);
     // API entry point
     $this->export_api_url = 'http://' . $this->GetSite() . '.api.mailchimp.com/export/1.0/list?' . http_build_query(array('apikey' => $apikey, 'id' => $this->list_id));
 }
<?php

/**
 * Mise à jour des listes de sélection des classes dans le formulaire
 * d'inscription MailChimp
 */
/**
 * Core functions
 */
require_once 'core.php';
// Spécification du nom (tag) des champs à mettre à jour
define('FIELD_SPEC', '^E[0-9]CLASSE');
echo "Mise à jour des champs de sélection des classes pour la liste '{$mailchimp_list_name}'\n";
// Initialisation MailChimp API
$mc = new MyMailchimp($mailchimp_apikey, $mailchimp_list_name);
// Récupération des champs
$fields = $mc->getMergeVars(FIELD_SPEC);
// Récupération de la liste des classes depuis la BDD
$sql = 'SELECT nom FROM ' . VIEW_CLASSES . ' ORDER BY nom';
$res = $db->query($sql);
$classes_list = $res->fetchAll(PDO::FETCH_COLUMN, 0);
// Insertion valeur vide en tête de liste
array_unshift($classes_list, '');
// Mise à jour des champs spécifiés
foreach ($fields as $field) {
    extract($field, EXTR_PREFIX_ALL, 'f');
    echo "Updating field '{$f_tag}' ({$f_name})\n";
    $mc->updateMergeVarDropdownChoices($f_tag, $classes_list);
}
echo "Terminé\n";