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

Release 3.0.4 #122

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5b46ed2
Process daily validation of conditions
sowbiba Nov 29, 2022
3d2323f
Sync data if needed + Remove unnecessary Configuration variable
sowbiba Nov 29, 2022
6764f4c
Bump version to 3.0.1
sowbiba Nov 29, 2022
be9d1fe
Trigger API sync when module is enabled
sowbiba Nov 29, 2022
d0a8d63
Fix signature validation for advices_16 + Allow install by CLI
sowbiba Dec 21, 2022
fadfd44
Merge pull request #110 from sowbiba/restore-daily-calculation
sowbiba Dec 23, 2022
25603a5
On refresh data return true if success
sowbiba Dec 26, 2022
15c47f9
Merge pull request #111 from sowbiba/fix-register-hooks-on-enable
sowbiba Dec 26, 2022
159c69d
[-] BO : Fix uninstall when DB_PREFIX is empty
Setlakwe Jan 3, 2023
aaa96c0
Secure access to folders and data files
sowbiba Jun 13, 2023
bf0e8a6
Merge pull request #113 from PrestaShopCorp/secure-files-access
sowbiba Jun 15, 2023
3e9aa42
Add module key for Addons
sowbiba Aug 2, 2023
d93fb1a
Adding new countries and limitation to PS 1.7 for PS Paylater banner
Thymotep Aug 29, 2023
f76f7da
Merge pull request #115 from PrestaShopCorp/paylater-banner
intraordinaire Aug 30, 2023
cca46ab
Bump version 3.0.2
intraordinaire Aug 30, 2023
b725657
Merge pull request #116 from PrestaShopCorp/feat/bump-302
intraordinaire Aug 30, 2023
a9a0160
Merge branch 'dev' into 3.x
intraordinaire Aug 30, 2023
53b8cfe
Merge pull request #117 from PrestaShopCorp/3.x
intraordinaire Aug 30, 2023
33856b6
fix: dashboard selector
sullivan-monteiro Oct 2, 2023
09e5ada
Merge pull request #118 from PrestaShopCorp/fix/mbo-1281/dashboard-po…
sowbiba Oct 9, 2023
309e9d9
Merge pull request #119 from PrestaShopCorp/3.x
sowbiba Oct 9, 2023
dc5415a
Merge pull request #112 from Setlakwe/dev
sowbiba Oct 9, 2023
056be25
Bump version to 3.0.3
sowbiba Oct 9, 2023
2bd6d0f
Remove paylater banner code + Bump to 3.0.4
sowbiba Dec 26, 2023
4350b9d
Merge pull request #120 from sowbiba/feat/MBO-1499/3x-remove-paylater
sowbiba Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Disable index view
Options -Indexes

# Hide a specific file
<Files .env>
Order allow,deny
Deny from all
</Files>

<Files ~ "^\.env(.*)$">
Order allow,deny
Deny from all
</Files>

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^data/(.*)$ - [F,L,NC]
</IfModule>
38 changes: 38 additions & 0 deletions classes/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,44 @@ public static function getIdsByHookCalculation($hook_name)
return array_unique($ids);
}

public static function getIdsDailyCalculation()
{
$ids = [];
$in = [];

//advice conditions validation
$sub_query = new DbQuery();
$sub_query->select('id_advice');
$sub_query->from('advice', 'a');

$sub_results = Db::getInstance()->executeS($sub_query);

$in = [];

foreach ($sub_results as $sub_result) {
$in[] = $sub_result['id_advice'];
}

$query = new DbQuery();
$query->select('c.`id_condition`');
$query->from('condition', 'c');
$query->join('LEFT JOIN `' . _DB_PREFIX_ . 'condition_advice` ca ON ca.`id_condition` = c.`id_condition`');
$query->where('c.`calculation_type` = \'time\'');
$query->where('DATEDIFF(NOW(), `date_upd`) >= `calculation_detail`');
$query->where('c.`validated` = 0');
if (count($in)) {
$query->where('ca.`id_advice` IN (' . implode(',', $in) . ')');
}
$query->groupBy('c.`id_condition`');

$result = Db::getInstance()->executeS($query);
foreach ($result as $r) {
$ids[] = $r['id_condition'];
}

return array_unique($ids);
}

public function processCalculation()
{
switch ($this->type) {
Expand Down
35 changes: 35 additions & 0 deletions classes/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2016 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../../../');
exit;
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>gamification</name>
<displayName><![CDATA[Merchant Expertise]]></displayName>
<version><![CDATA[3.0.0]]></version>
<version><![CDATA[3.0.4]]></version>
<description><![CDATA[Become an e-commerce expert within the blink of an eye!]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
Expand Down
22 changes: 18 additions & 4 deletions controllers/admin/AdminGamificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ public function initPageHeaderToolbar()

public function ajaxProcessGamificationTasks()
{
if (!Configuration::get('GF_INSTALL_CALC')) {
$this->processRefreshData();
Configuration::updateGlobalValue('GF_INSTALL_CALC', 1);
}
// Refresh data from API, if needed
$this->processRefreshData();

// Recalculate not validated conditions based on time
$this->processMakeDailyCalculation();

// Compute advices validtion/unvalidation based on conditions
$this->processAdviceValidation();

$return['advices_to_display'] = $this->processGetAdvicesToDisplay();
Expand Down Expand Up @@ -113,6 +115,18 @@ public function processGetAdvicesToDisplay($only_premium = false)
return $return;
}

public function processMakeDailyCalculation()
{
$return = true;
$condition_ids = Condition::getIdsDailyCalculation();
foreach ($condition_ids as $id) {
$condition = new Condition((int) $id);
$return &= $condition->processCalculation();
}

return $return;
}

public function processAdviceValidation()
{
$return = true;
Expand Down
35 changes: 35 additions & 0 deletions controllers/admin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2016 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../../../../');
exit;
95 changes: 19 additions & 76 deletions gamification.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public function __construct()
{
$this->name = 'gamification';
$this->tab = 'administration';
$this->version = '3.0.0';
$this->version = '3.0.4';
$this->author = 'PrestaShop';
$this->module_key = 'c1187d1672d2a2d33fbd7d5c29f0d42e';
$this->ps_versions_compliancy = [
'min' => '8.0.0',
];
Expand All @@ -73,18 +74,15 @@ public function install()

return
$this->installDb()
&& Configuration::updateGlobalValue('GF_INSTALL_CALC', 0)
&& parent::install()
&& $this->registerHook('actionAdminControllerSetMedia')
&& $this->registerHook('displayBackOfficeHeader')
&& $this->registerHook('displayAdminAfterHeader')
;
}

public function uninstall()
{
if (!parent::uninstall() || !$this->uninstallDb() ||
!Configuration::updateGlobalValue('GF_INSTALL_CALC', 0)) {
if (!parent::uninstall() || !$this->uninstallDb()) {
return false;
}

Expand All @@ -106,15 +104,23 @@ public function uninstallDb()
{
$sql = include __DIR__ . '/sql_install.php';
foreach ($sql as $name => $v) {
Db::getInstance()->execute('DROP TABLE ' . $name);
Db::getInstance()->execute('DROP TABLE `' . $name . '`');
}

return true;
}

public function enable($force_all = false)
{
return parent::enable($force_all) && Tab::enablingForModule($this->name);
$enableResult = parent::enable($force_all) && Tab::enablingForModule($this->name);

if (php_sapi_name() !== 'cli') {
// If the module is installed/enabled tthrough CLI, we ignore the data refreshing
// because we cannot guess the shop context
$enableResult &= $this->refreshDatas();
}

return $enableResult;
}

public function disable($force_all = false)
Expand Down Expand Up @@ -213,9 +219,9 @@ public function refreshDatas($iso_lang = null)
$this->processCleanAdvices();

$public_key = file_get_contents(__DIR__ . '/prestashop.pub');
$signature = isset($data->signature) ? base64_decode($data->signature) : '';

if (isset($data->conditions)) {
$signature = isset($data->signature) ? base64_decode($data->signature) : '';
if (
function_exists('openssl_verify')
&& self::TEST_MODE === false
Expand All @@ -232,10 +238,12 @@ function_exists('openssl_verify')
}

if (isset($data->advices_lang_16)) {
$signature16 = isset($data->signature_16) ? base64_decode($data->signature_16) : '';
$sslCheck = openssl_verify(json_encode([$data->advices_lang_16]), $signature16, $public_key);
if (
function_exists('openssl_verify')
&& self::TEST_MODE === false
&& !openssl_verify(json_encode([$data->advices_lang_16]), $signature, $public_key)
&& !$sslCheck
) {
return false;
}
Expand All @@ -246,6 +254,8 @@ function_exists('openssl_verify')
}
}
}

return true;
}

public function getData($iso_lang = null)
Expand Down Expand Up @@ -425,71 +435,4 @@ public function isFresh($file, $timeout = 86400000)

return $now < $lastFileUpdate;
}

/**
* Display PrestaShop Paylater with PayPlug & Oney
*
* @return string
*/
public function hookDisplayAdminAfterHeader()
{
// PrestaShop Paylater with PayPlug & Oney is available only from PrestaShop 1.7
if (version_compare(_PS_VERSION_, '1.7.0.0', '<')) {
return '';
}

// Display PrestaShop Paylater with PayPlug & Oney only if PrestaShop Checkout is enabled and onboarded for FR & IT located merchant
if ('AdminPayment' === Tools::getValue('controller')
&& in_array($this->getShopCountryCode(), ['FR', 'IT'], true)
&& Module::isEnabled('ps_checkout')
&& Configuration::get('PS_CHECKOUT_PAYPAL_ID_MERCHANT')
) {
$this->context->smarty->assign([
'pspaylater_install_link' => $this->getModuleInstallUrl('pspaylater'),
'pspaylater_configure_link' => $this->context->link->getAdminLink('AdminModules', true) . '&configure=pspaylater',
'pspaylater_img_path' => $this->getPathUri() . 'views/img/pspaylater.png',
'pspaylater_enabled' => Module::isEnabled('pspaylater'),
]);

return $this->display(__FILE__, 'displayBackOfficeHeader.tpl');
}

return '';
}

/**
* @return string
*/
private function getShopCountryCode()
{
$defaultCountry = '';

if (empty($defaultCountry) && Configuration::hasKey('PS_COUNTRY_DEFAULT')) {
$defaultCountry = (new Country((int) Configuration::get('PS_COUNTRY_DEFAULT')))->iso_code;
}

return $defaultCountry ? strtoupper($defaultCountry) : '';
}

/**
* @param string $name
*
* @return string
*/
private function getModuleInstallUrl($name)
{
if (version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
return $this->context->link->getAdminLink(
'AdminModulesSf',
true,
[
'route' => 'admin_module_manage_action',
'action' => 'install',
'module_name' => $name,
]
);
}

return $this->context->link->getAdminLink('AdminModules') . '&install=' . $name . '&tab_module=payments_gateways&module_name=' . $name . '&anchor=' . ucfirst($name);
}
}
35 changes: 35 additions & 0 deletions tests/functional/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2016 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../../../');
exit;
Loading
Loading