Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for backward compatibility #142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions backward_compatibility/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class Context
*/
public $smarty;

/**
* @throws PrestaShopException
* @throws PrestaShopDatabaseException
*/
public function __construct()
{
global $cookie, $cart, $smarty, $link;
Expand All @@ -129,12 +133,12 @@ public function __construct()
$this->link = $link;

$this->controller = new ControllerBackwardModule();
$this->currency = new Currency((int) $cookie->id_currency);
$this->language = new Language((int) $cookie->id_lang);
$this->country = new Country((int) $cookie->id_country);
$this->currency = new Currency(isset($cookie->id_currency) ? (int)$cookie->id_currency : null);
$this->language = new Language(isset($cookie->id_lang) ? (int)$cookie->id_lang : null);
$this->country = new Country(isset($cookie->id_country) ? (int)$cookie->id_country : null);
$this->shop = new ShopBackwardModule();
$this->customer = new Customer((int) $cookie->id_customer);
$this->employee = new Employee((int) $cookie->id_employee);
$this->customer = new Customer(isset($cookie->id_customer) ? (int)$cookie->id_customer : null);
$this->employee = new Employee(isset($cookie->id_employee) ? (int)$cookie->id_employee : null);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions backward_compatibility/backward.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
*/
// Get out if the context is already defined
if (!in_array('Context', get_declared_classes())) {
include_once dirname(__FILE__) . '/Context.php';
include_once __DIR__ . '/Context.php';
}

// Get out if the Display (BWDisplay to avoid any conflict)) is already defined
if (!in_array('BWDisplay', get_declared_classes())) {
include_once dirname(__FILE__) . '/Display.php';
include_once __DIR__ . '/Display.php';
}

// If not under an object we don't have to set the context
Expand Down
33 changes: 10 additions & 23 deletions libraries/Mailjet.Overlay.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,12 @@ public function __destruct()
*/
private function createErrorsArray()
{
return;
$response = $this->getAPIStatus();
$this->_errors = array();
foreach ($response->status as $error) {
$this->_errors[$error->code] = '[' . $error->code . '] ' . $error->status . ' : ' . $error->description;
if (isset($response->status)) {
foreach ($response->status as $error) {
$this->_errors[$error->code] = '[' . $error->code . '] ' . $error->status . ' : ' . $error->description;
}
}
}

Expand Down Expand Up @@ -1030,19 +1031,6 @@ public function getDomainStatusP(Mailjet_Parameters $parameters)
*/
public function getUser($cache = null)
{
// $params = array(
// 'method' => 'GET'
// );
// if (!is_null($cache))
// $params['cache'] = $cache;
// $response = $this->_api->userInfos($params);
// if ($response !== FALSE)
// return ($response);
// else
// throw new Mailjet_ApiException($this->_api->getHTTPCode(), $this->_errors[$this->_api->getHTTPCode()]);



$paramsProfile = array(
'method' => 'GET',
);
Expand Down Expand Up @@ -5044,13 +5032,12 @@ public function getAPIMethods(string $category, $cache = 600)
/**
* HELP : Get response status and status code you'll encounter when calling our API
* - url : api.mailjet.com/0.1/helpStatus
*
* @access public
* @throw Mailjet::Mailjet_ApiException
* @param int $code Code response (Optional)
* @param int $cache Cache period for the object - default to 600s = 10m (Optional)
*
* @param int|null $code Code response (Optional)
* @param int $cache Cache period for the object - default to 600s = 10m (Optional)
* @return mixed Response from the API
* @throws Mailjet_ApiException
*/
public function getAPIStatus(int $code = null, $cache = 600)
{
Expand All @@ -5061,14 +5048,14 @@ public function getAPIStatus(int $code = null, $cache = 600)
$params['code'] = $code;
}
if (!is_null($cache)) {
$params['cache'] = intval($cache);
$params['cache'] = (int)$cache;
}

$response = $this->_api->helpStatus($params);
if ($response !== false) {
return ($response);
} else {
throw new Mailjet_ApiException($this->_api->getHTTPCode(), $this->_errors[$this->_api->getHTTPCode()]);
}

throw new Mailjet_ApiException($this->_api->getHTTPCode(), $this->_errors[$this->_api->getHTTPCode()]);
}
}
33 changes: 24 additions & 9 deletions mailjet.php
Original file line number Diff line number Diff line change
Expand Up @@ -990,9 +990,9 @@ public function checkAutoAssignment($id_customer = 0)

if ($result) {
if ($customer->active == 1) {
$initialSynchronization->subscribe($customer, $mailjetListID);
$initialSynchronization->subscribe($customer->email, $mailjetListID);
} else {
$initialSynchronization->unsubscribe($customer, $mailjetListID);
$initialSynchronization->unsubscribe($customer->email, $mailjetListID);
}
} else {
$initialSynchronization->remove($customer->email, $mailjetListID);
Expand Down Expand Up @@ -1054,12 +1054,21 @@ public function loadConfiguration()
);
}

/**
* @throws SmartyException
*/
public function fetchTemplate($path, $name)
{
if (_PS_VERSION_ < '1.4') {
$this->context->smarty->currentTemplate = $name;
}

try {
return $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'mailjet' . $path . $name . '.tpl');
} catch (SmartyException $smartyException) {
$this->context->smarty->clearCache(_PS_MODULE_DIR_ . 'mailjet' . $path . $name . '.tpl');
}

return $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'mailjet' . $path . $name . '.tpl');
}

Expand Down Expand Up @@ -1138,7 +1147,7 @@ public function postProcess()
$this->page_name = 'CAMPAIGN3';
}
// Activation root file Creation
if (Tools::isSubmit('submitCreateRootFile')) {
if (Tools::isSubmit('submitCreateRootFile') && MailjetTemplate::getApi() !== null) {
$api = MailjetTemplate::getApi();
$infos = $api->getUser();
$sendersFromApi = $api->getSenders(null, $infos);
Expand All @@ -1149,15 +1158,15 @@ public function postProcess()
if ($sender->DNS->Domain == Configuration::get('PS_SHOP_DOMAIN')
|| $sender->DNS->Domain == Configuration::get('PS_SHOP_DOMAIN_SSL')
) {
$fp = fopen(_PS_ROOT_DIR_ . '/' . $sender->Filename, 'w');
$fp = fopen(_PS_ROOT_DIR_ . '/' . $sender->Filename, 'wb');
fclose($fp);
}
}
}
}
}
// Account settings : details
if (Tools::isSubmit('MJ_set_account_details')) {
if (Tools::isSubmit('MJ_set_account_details') && MailjetTemplate::getApi() !== null) {
$api = MailjetTemplate::getApi();
$api->updateUser(
Tools::getValue('MJ_account_address_city'),
Expand All @@ -1174,7 +1183,7 @@ public function postProcess()
$modif = true;
}
// Account settings : tracking
if (Tools::isSubmit('MJ_set_account_tracking')) {
if (Tools::isSubmit('MJ_set_account_tracking') && MailjetTemplate::getApi() !== null) {
$api = MailjetTemplate::getApi();
if (Tools::getValue('MJ_account_tracking_clicks') == '1') {
$tracking_clicks = true;
Expand Down Expand Up @@ -1944,8 +1953,8 @@ private function setUserLinkToEvents($events)
*/
public function checkTokenValidity()
{
if (!isset($this->account->{'TOKEN_' . $this->context->employee->id})
|| $this->account->{'IP_' . $this->context->employee->id} != $_SERVER['REMOTE_ADDR']
if (!isset($this->account->{'TOKEN_' . $this->context->employee->id})
|| $this->account->{'IP_' . $this->context->employee->id} != $_SERVER['REMOTE_ADDR']
|| ($this->account->{'TIMESTAMP_' . $this->context->employee->id} <= strtotime('-1 day'))
) {
$this->account->{'IP_' . $this->context->employee->id} = $_SERVER['REMOTE_ADDR'];
Expand Down Expand Up @@ -1980,7 +1989,7 @@ protected function getPlan()
{
if (!$this->isAccountSet()) {
return null;
};
}
}

/**
Expand All @@ -1991,6 +2000,12 @@ public function checkPlanValidity()
new Mailjet_ApiOverlay($this->account->API_KEY, $this->account->SECRET_KEY);
}

/**
* @param $apiKey
* @param $secretKey
* @return bool
* @throws Exception
*/
public function auth($apiKey, $secretKey)
{
$test = new Mailjet_ApiOverlay($apiKey, $secretKey);
Expand Down