public static function getDataApi()
 {
     $obj = new Mailjet();
     if (self::$data_api === null) {
         self::$data_api = mailjetdata::getInstance();
         self::$data_api->setKeys($obj->getAccountSettingsKey('API_KEY'), $obj->getAccountSettingsKey('SECRET_KEY'));
     }
     return self::$data_api;
 }
Esempio n. 2
0
 /**
  *
  * @throws Exception
  */
 public function initalSynchronize()
 {
     if (!$this->isAccountSet()) {
         return false;
     }
     $initialSynchronization = new HooksSynchronizationInitial(MailjetTemplate::getApi());
     try {
         $newlyCreatedListId = $initialSynchronization->synchronize();
         if ($newlyCreatedListId) {
             $this->account->MASTER_LIST_SYNCHRONIZED = 1;
             $this->account->MASTER_LIST_ID = $newlyCreatedListId;
             $this->updateAccountSettings();
         } else {
             throw new Exception('The master list is not created.');
         }
     } catch (Exception $e) {
         $this->errors_list[] = $this->l($e->getMessage());
         return false;
     }
     return true;
 }
Esempio n. 3
0
include_once _PS_ROOT_DIR_ . '/init.php';
$response = false;
/* $token_ok = Tools::getAdminTokenLite('AdminModules'); */
$token_ok = Tools::getAdminToken('AdminModules');
if (!Tools::getValue('token') && Tools::getValue('token') != $token_ok) {
    die('hack attempt');
}
if (Tools::getValue('idfilter') == 0 && Tools::getValue('action') == 'getQuery') {
    die('You have to save the list first.');
}
include_once _PS_MODULE_DIR_ . 'mailjet/mailjet.php';
/* include_once(_PS_MODULE_DIR_.'mailjet/classes/MailjetAPI.php'); */
include_once _PS_MODULE_DIR_ . 'mailjet/classes/MailJetTemplate.php';
include_once _PS_MODULE_DIR_ . 'mailjet/classes/hooks/synchronization/SynchronizationAbstract.php';
include_once _PS_MODULE_DIR_ . 'mailjet/classes/hooks/synchronization/Segment.php';
if (Tools::getValue('action') == 'getQuery') {
    Configuration::updateValue('MJ_PERCENTAGE_SYNC', 0);
    $obj = new Segmentation();
    $res_contacts = Db::getInstance()->executeS($obj->getQuery($_POST, true, false));
    $api = MailjetTemplate::getApi();
    $synchronization = new HooksSynchronizationSegment(MailjetTemplate::getApi());
    $response = $synchronization->sychronize($res_contacts, Tools::getValue('idfilter'), Tools::getValue('name'));
} else {
    if (Tools::getValue('action') == 'getPercentage') {
        $response = Configuration::get('MJ_PERCENTAGE_SYNC');
    }
}
if ($response === false) {
    $response = 'Error';
}
echo $response;
Esempio n. 4
0
 /**
  * 
  * @author atanas
  * @param int $filterId
  * @return int
  */
 public function _getMailjetContactListId($filterId)
 {
     if (array_key_exists($filterId, $this->_contactListsMap)) {
         return $this->_contactListsMap[$filterId];
     }
     $api = MailjetTemplate::getApi();
     $lists = $api->getContactsLists();
     $id_list_contact = 0;
     if ($lists !== false) {
         foreach ($lists as $l) {
             $n = explode('idf', $l->Name);
             if ((string) $n[0] == (string) $filterId) {
                 $id_list_contact = (int) $l->ID;
                 $this->_contactListsMap[$filterId] = $id_list_contact;
                 break;
             }
         }
     }
     return $id_list_contact;
 }