Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Commit

Permalink
fix(Mautic) points sync by default and set user if does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
joebordes committed May 3, 2024
1 parent ef34ea4 commit 5ac72d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
6 changes: 5 additions & 1 deletion include/integrations/mautic/contactsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function contactsync($input) {
foreach ($fields as $field) {
$mauticdata[$field['alias']] = $field['value'];
}
$mauticdata['contact_points'] = $contact['points'];
$send2cb = array();
$bmapname = 'MauticToContacts';
$cbMapid = GlobalVariable::getVariable('BusinessMapping_'.$bmapname, cbMap::getMapIdByName($bmapname));
Expand All @@ -68,6 +69,7 @@ function contactsync($input) {
$send2cb['mautic_id'] = $contact['id'];
$send2cb['assigned_user_id'] = $usrwsid;
$send2cb['from_externalsource'] = 'mautic';
$send2cb['contact_points'] = $mauticdata['contact_points'];

$record = vtws_create('Contacts', $send2cb, $current_user);
if ($record) {
Expand Down Expand Up @@ -97,6 +99,7 @@ function contactsync($input) {
foreach ($fields as $field) {
$mauticdata[$field['alias']] = $field['value'];
}
$mauticdata['contact_points'] = $contact['points'];
$send2cb = array();
$bmapname = 'MauticToContacts';
$cbMapid = GlobalVariable::getVariable('BusinessMapping_'.$bmapname, cbMap::getMapIdByName($bmapname));
Expand All @@ -112,6 +115,7 @@ function contactsync($input) {
$send2cb['assigned_user_id'] = $usrwsid;
$send2cb['id'] = $fields['corebos_id']['value'];
$send2cb['from_externalsource'] = 'mautic';
$send2cb['contact_points'] = $mauticdata['contact_points'];

$record = vtws_update($send2cb, $current_user);
if ($record) {
Expand All @@ -130,4 +134,4 @@ function contactsync($input) {
$adb->pquery('UPDATE vtiger_contactdetails SET mautic_id=?, deleted_in_mautic=? where contactid=?', array('', 1, $contact_crmid));
}
}
}
}
34 changes: 16 additions & 18 deletions include/integrations/mautic/mautic.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class corebos_mautic {
private $mauticUsername = '';
private $mauticPassword = '';
private $mauticWebhookSecret = '';
private $usrwsid = '0x0';

// Configuration Keys
const KEY_ISACTIVE = 'mautic_isactive';
Expand All @@ -77,7 +78,12 @@ class corebos_mautic {
public static $ERROR_NOACCESSTOKEN = 2;

public function __construct() {
global $current_user;
$this->initGlobalScope();
if (empty($current_user)) {
$current_user = Users::getActiveAdminUser();
}
$this->usrwsid = vtws_getEntityId('Users').'x'.$current_user->id;
}

public function initGlobalScope() {
Expand Down Expand Up @@ -320,6 +326,7 @@ public function leadsToContacts() {
foreach ($fields as $field) {
$mauticdata[$field['alias']] = $field['value'];
}
$mauticdata['contact_points'] = $contact['points'];

if (empty($mauticdata['corebos_id'])) {
if (!empty($mauticdata['lastname']) && !empty($mauticdata['email'])) {
Expand All @@ -346,9 +353,7 @@ public function leadsToContacts() {
}

public function createCBContact($contact_id, $mauticdata) {
global $adb;
$current_user = Users::getActiveAdminUser();
$usrwsid = vtws_getEntityId('Users').'x'.$current_user->id;
global $adb, $current_user;
$send2cb = array();
$bmapname = 'MauticToContacts';
$cbMapid = GlobalVariable::getVariable('BusinessMapping_'.$bmapname, cbMap::getMapIdByName($bmapname));
Expand All @@ -361,7 +366,7 @@ public function createCBContact($contact_id, $mauticdata) {
$send2cb['email'] = $mauticdata['email'];
}
$send2cb['mautic_id'] = $contact_id;
$send2cb['assigned_user_id'] = $usrwsid;
$send2cb['assigned_user_id'] = $this->usrwsid;
$send2cb['from_externalsource'] = 'mautic';

$record = vtws_create('Contacts', $send2cb, $current_user);
Expand All @@ -375,9 +380,7 @@ public function createCBContact($contact_id, $mauticdata) {
}

public function updateCBContact($contact_id, $mauticdata) {
global $adb;
$current_user = Users::getActiveAdminUser();
$usrwsid = vtws_getEntityId('Users').'x'.$current_user->id;
global $adb, $current_user;
$send2cb = array();
$bmapname = 'MauticToContacts';
$cbMapid = GlobalVariable::getVariable('BusinessMapping_'.$bmapname, cbMap::getMapIdByName($bmapname));
Expand All @@ -390,9 +393,10 @@ public function updateCBContact($contact_id, $mauticdata) {
$send2cb['email'] = $mauticdata['email'];
}
$send2cb['mautic_id'] = $contact_id;
$send2cb['assigned_user_id'] = $usrwsid;
$send2cb['assigned_user_id'] = $this->usrwsid;
$send2cb['id'] = $mauticdata['corebos_id'];
$send2cb['from_externalsource'] = 'mautic';
$send2cb['contact_points'] = $mauticdata['contact_points'];

$record = vtws_update($send2cb, $current_user);
if ($record) {
Expand Down Expand Up @@ -446,9 +450,7 @@ public function companiesToAccounts() {
}

public function createCBAccount($company_id, $mauticdata) {
global $adb;
$current_user = Users::getActiveAdminUser();
$usrwsid = vtws_getEntityId('Users').'x'.$current_user->id;
global $adb ,$current_user;
$send2cb = array();
$bmapname = 'MauticToAccounts';
$cbMapid = GlobalVariable::getVariable('BusinessMapping_'.$bmapname, cbMap::getMapIdByName($bmapname));
Expand All @@ -459,9 +461,8 @@ public function createCBAccount($company_id, $mauticdata) {
$send2cb['accountname'] = $mauticdata['companyname'];
}
$send2cb['mautic_id'] = $company_id;
$send2cb['assigned_user_id'] = $usrwsid;
$send2cb['assigned_user_id'] = $this->usrwsid;
$send2cb['from_externalsource'] = 'mautic';

$record = vtws_create('Accounts', $send2cb, $current_user);
if ($record) {
// Reset from_externalsource
Expand All @@ -473,9 +474,7 @@ public function createCBAccount($company_id, $mauticdata) {
}

public function updateCBAccount($company_id, $mauticdata) {
global $adb;
$current_user = Users::getActiveAdminUser();
$usrwsid = vtws_getEntityId('Users').'x'.$current_user->id;
global $adb, $current_user;
$send2cb = array();
$bmapname = 'MauticToAccounts';
$cbMapid = GlobalVariable::getVariable('BusinessMapping_'.$bmapname, cbMap::getMapIdByName($bmapname));
Expand All @@ -486,10 +485,9 @@ public function updateCBAccount($company_id, $mauticdata) {
$send2cb['accountname'] = $mauticdata['companyname'];
}
$send2cb['mautic_id'] = $company_id;
$send2cb['assigned_user_id'] = $usrwsid;
$send2cb['assigned_user_id'] = $this->usrwsid;
$send2cb['id'] = $mauticdata['company_corebos_id'];
$send2cb['from_externalsource'] = 'mautic';

$record = vtws_update($send2cb, $current_user);
if ($record) {
// Reset from_externalsource
Expand Down

0 comments on commit 5ac72d9

Please sign in to comment.