90 lines
3.7 KiB
PHP
90 lines
3.7 KiB
PHP
<?php
|
|
ini_set("memory_limit", "-1");
|
|
set_time_limit(0);
|
|
error_reporting(E_ALL);
|
|
|
|
require_once 'Db.php';
|
|
require_once 'CPlatosChiffrement.class.php';
|
|
require_once 'LDCCRM_V1.php';
|
|
|
|
$db = new Database('localhost', 'ldc-crm', 'ldc-crmadm', 'wai6dahB');
|
|
//$db = new Database('192.168.30.3', 'ldc-crm', 'ldc-crmadm', 'wai6dahB');
|
|
$apiCrm = new \LDCCRM\ApiV1('http://crm.test', 'giu6OCyG6FuJvM56zFntDcrtDI23GU7WNnkvOk9rPPTOzKArI8IV9nqgEAnsA8wEQUDnKheQ9FDfKUwG');
|
|
|
|
$siteId = 17;
|
|
$siteName = "REGHALAL";
|
|
|
|
$accounts = $db->requestAll("SELECT *
|
|
FROM useraccount
|
|
INNER JOIN siteuser su ON useraccount.user_id = su.siteuser_useraccountId
|
|
WHERE su.siteuser_siteId = :siteid
|
|
AND user_status = 1
|
|
AND user_lastUpdateDate >= '2018-03-01'
|
|
AND (user_emailCheckStatus <> 0 OR user_emailCheckStatus IS NULL)
|
|
AND (user_lastCnxDateHeure IS NOT NULL AND user_lastCnxDateHeure <> '0000-00-00 00:00:00')", ['siteid' => $siteId]);
|
|
|
|
foreach ($accounts as $account) {
|
|
$isSingleOptin = false;
|
|
|
|
$oldCRMid = $account['user_id'];
|
|
|
|
$civility = $account['user_civilite'];
|
|
$firstname = $account['user_prenom'];
|
|
$lastname = $account['user_nom'];
|
|
|
|
$birthdate = $account['user_dateNaissance'];
|
|
|
|
$address1 = !empty($account['user_adresse1']) ? $account['user_adresse1'] : null;
|
|
$address2 = !empty($account['user_adresse2']) ? $account['user_adresse2'] : null;
|
|
$postcode = (!empty($account['user_codePostal']) && $account['user_codePostal'] !== 0 ? $account['user_codePostal'] : null);
|
|
$city = !empty($account['user_ville']) ? $account['user_ville'] : null;
|
|
|
|
$optin = $account['user_inscritNewsletter'];
|
|
$haschcode = $account['user_hashcode'];
|
|
$status = $account['user_status'];
|
|
|
|
$created_at = $account['user_creationDate'];
|
|
$updated_at = $account['user_lastUpdateDate'];
|
|
|
|
$email = $account['user_email'];
|
|
$password = CPlatosChiffrement::decrypt($account['user_pwd']);
|
|
|
|
$last_cnx = $account['user_lastCnxDateHeure'];
|
|
|
|
if (empty($firstname) && empty($lastname))
|
|
$isSingleOptin = true;
|
|
|
|
// Récupération des champs complémentaires
|
|
$fields = [['fieldkey' => 'created_at', 'fieldvalue' => $created_at], ['fieldkey' => 'updated_at', 'fieldvalue' => $updated_at], ['fieldkey' => 'last_cnx', 'fieldvalue' => $last_cnx]];
|
|
|
|
if (!$isSingleOptin) {
|
|
$crmUser = $apiCrm->createCustomer($email, $password, $firstname, $lastname, $optin, $birthdate, null, $address1, $address2, $city, $postcode, "France");
|
|
if ($crmUser->status === 'OK') {
|
|
$newCRMId = $crmUser->user->crm_id;
|
|
$activate = $apiCrm->activateCustomer($newCRMId);
|
|
if ($activate->status === 'NOK') {
|
|
file_put_contents("Export_errors.txt", "OLD CRM ID : $oldCRMid - NEW CRM ID : $newCRMId - ACTIVATE API ERROR : " . $activate->code . " - " . $activate->message . PHP_EOL, FILE_APPEND);
|
|
}
|
|
} else {
|
|
file_put_contents("Export_errors.txt", "OLD CRM ID : $oldCRMid - API ERROR : " . $crmUser->code . " - " . $crmUser->message . PHP_EOL, FILE_APPEND);
|
|
continue;
|
|
}
|
|
} else {
|
|
$result = $apiCrm->createSingleOptin($email);
|
|
|
|
if ($result->status === 'OK') {
|
|
$newCRMId = "SINGLEOPTIN";
|
|
} else {
|
|
file_put_contents("Export_errors.txt", "OLD CRM ID : $oldCRMid - API ERROR : " . $crmUser->code . " - " . $crmUser->message . PHP_EOL, FILE_APPEND);
|
|
continue;
|
|
}
|
|
}
|
|
write("$oldCRMid;$newCRMId;$email;" . json_encode($fields) . PHP_EOL, $siteName);
|
|
}
|
|
|
|
function write($text, $siteName)
|
|
{
|
|
if (!file_exists("Export_$siteName.csv"))
|
|
file_put_contents("Export_$siteName.csv", "\xEF\xBB\xBF", FILE_APPEND); // BOM UTF-8
|
|
file_put_contents("Export_$siteName.csv", $text, FILE_APPEND);
|
|
}
|