bebeboutik-scripts/cron_emarsys_unsubscribe.php

50 lines
1.2 KiB
PHP
Raw Normal View History

2017-12-18 17:14:31 +01:00
<?php
2018-01-19 15:29:39 +01:00
/**
* Import customer details from Emarsys
* - Set newsletter info on customer
*/
2017-12-18 17:14:31 +01:00
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include_once dirname(__FILE__).'/www/config/config.inc.php';
$db = Db::getInstance();
2018-01-19 15:29:39 +01:00
// List all files in dir
2017-12-18 17:14:31 +01:00
foreach(glob(dirname(__FILE__).'/emarsys/*.csv') as $filename) {
$f = fopen($filename, 'r');
2018-01-19 15:29:39 +01:00
// By-pass first line
2017-12-18 17:14:31 +01:00
fgetcsv($f);
2018-01-19 15:29:39 +01:00
// Parse line
2017-12-18 17:14:31 +01:00
while($line = fgetcsv($f, 0, ';', '"')) {
2018-01-19 15:29:39 +01:00
if(in_array((int) $line[1], array(0, 1, 2))
&& !empty($line[2]) && in_array(strtolower($line[3]), array('vrai', 'faux'))
&& Validate::isEmail($line[2])) {
if($customer = $db->getRow('
2017-12-18 17:14:31 +01:00
SELECT `id_customer`
FROM `'._DB_PREFIX_.'customer`
WHERE `email` = "'.pSQL($line[2]).'"
')) {
if(strtolower($line[3]) == 'faux') {
$active = 0;
} else {
$active = (int) $line[1];
}
$db->ExecuteS('
UPDATE `'._DB_PREFIX_.'customer`
SET `newsletter` = '.(int) $active.',
`newsletter_date_add` = NOW()
WHERE `email` = "'.pSQL($line[2]).'"
LIMIT 1
');
}
}
}
fclose($f);
2018-01-19 15:29:39 +01:00
// Move file as done
2017-12-18 17:14:31 +01:00
rename($filename, str_replace('/emarsys/', '/emarsys_done/', $filename));
}