-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from matks/clean
Comply to validator.prestashop.com rules
- Loading branch information
Showing
23 changed files
with
172 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
composer.lock | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* 2007-2016 PrestaShop | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
|
@@ -19,7 +19,7 @@ | |
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2016 PrestaShop SA | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
@@ -279,21 +279,39 @@ public static function getTasksListValues() | |
{ | ||
$id_shop = (int)Context::getContext()->shop->id; | ||
$id_shop_group = (int)Context::getContext()->shop->id_shop_group; | ||
$table_name = _DB_PREFIX_.bqSQL(self::$module->name); | ||
|
||
$select_query = sprintf( | ||
"SELECT * FROM `%s` WHERE `id_shop` = '%d' AND `id_shop_group` = '%d'", | ||
$table_name, | ||
$id_shop, | ||
$id_shop_group | ||
); | ||
|
||
self::$module->addNewModulesTasks(); | ||
$crons = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.bqSQL(self::$module->name).'` WHERE `id_shop` = \''.$id_shop.'\' AND `id_shop_group` = \''.$id_shop_group.'\''); | ||
$crons = Db::getInstance()->executeS($select_query); | ||
|
||
foreach ($crons as $key => &$cron) { | ||
if (empty($cron['id_module']) == false) { | ||
$module = Module::getInstanceById((int)$cron['id_module']); | ||
|
||
$delete_query = sprintf( | ||
"DELETE FROM `%s` WHERE `id_cronjob` = '%s'", | ||
$table_name, | ||
(int)$cron['id_cronjob'] | ||
); | ||
|
||
if ($module == false) { | ||
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.bqSQL(self::$module->name).' WHERE `id_cronjob` = \''.(int)$cron['id_cronjob'].'\''); | ||
Db::getInstance()->execute($delete_query); | ||
unset($crons[$key]); | ||
break; | ||
} | ||
|
||
$query = 'SELECT `name` FROM `'._DB_PREFIX_.'module` WHERE `id_module` = \''.(int)$cron['id_module'].'\''; | ||
$query = sprintf( | ||
"SELECT `name` FROM `%s` WHERE `id_module` = '%s'", | ||
_DB_PREFIX_.'module', | ||
(int)$cron['id_module'] | ||
); | ||
$module_name = Db::getInstance()->getValue($query); | ||
|
||
$cron['description'] = Tools::safeOutput(Module::getModuleName($module_name)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* 2007-2016 PrestaShop | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
|
@@ -19,7 +19,7 @@ | |
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2016 PrestaShop SA | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* 2007-2016 PrestaShop | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
|
@@ -19,7 +19,7 @@ | |
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2016 PrestaShop SA | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
@@ -55,17 +55,25 @@ protected function runModulesCrons() | |
{ | ||
$query = 'SELECT * FROM '._DB_PREFIX_.bqSQL($this->module->name).' WHERE `active` = 1 AND `id_module` IS NOT NULL'; | ||
$crons = Db::getInstance()->executeS($query); | ||
$table_name = _DB_PREFIX_.bqSQL($this->module->name); | ||
|
||
|
||
if (is_array($crons) && (count($crons) > 0)) { | ||
foreach ($crons as &$cron) { | ||
$module = Module::getInstanceById((int)$cron['id_module']); | ||
|
||
$delete_query = sprintf( | ||
"DELETE FROM `%s` WHERE `id_cronjob` = '%s'", | ||
$table_name, | ||
(int)$cron['id_cronjob'] | ||
); | ||
|
||
if ($module == false) { | ||
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.bqSQL($this->module->name).' WHERE `id_cronjob` = \''.(int)$cron['id_cronjob'].'\''); | ||
Db::getInstance()->execute($delete_query); | ||
break; | ||
} elseif ($this->shouldBeExecuted($cron) == true) { | ||
Hook::exec('actionCronJob', array(), $cron['id_module']); | ||
$query = 'UPDATE '._DB_PREFIX_.bqSQL($this->module->name).' SET `updated_at` = NOW(), `active` = IF (`one_shot` = TRUE, FALSE, `active`) WHERE `id_cronjob` = \''.(int)$cron['id_cronjob'].'\''; | ||
$query = | ||
Db::getInstance()->execute($query); | ||
} | ||
} | ||
|
@@ -81,7 +89,12 @@ protected function runTasksCrons() | |
foreach ($crons as &$cron) { | ||
if ($this->shouldBeExecuted($cron) == true) { | ||
Tools::file_get_contents(urldecode($cron['task']), false); | ||
$query = 'UPDATE '._DB_PREFIX_.bqSQL($this->module->name).' SET `updated_at` = NOW(), `active` = IF (`one_shot` = TRUE, FALSE, `active`) WHERE `id_cronjob` = \''.(int)$cron['id_cronjob'].'\''; | ||
$query = sprintf( | ||
"UPDATE `%s` SET `updated_at` = NOW(), `active` = IF (`one_shot` = TRUE, FALSE, `active`) WHERE `id_cronjob` = '%s'", | ||
_DB_PREFIX_.bqSQL($this->module->name), | ||
(int)$cron['id_cronjob'] | ||
); | ||
|
||
Db::getInstance()->execute($query); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* 2007-2016 PrestaShop | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
|
@@ -19,7 +19,7 @@ | |
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2016 PrestaShop SA | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* 2007-2016 PrestaShop | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
|
@@ -19,7 +19,7 @@ | |
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2016 PrestaShop SA | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* 2007-2016 PrestaShop | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
|
@@ -19,7 +19,7 @@ | |
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2016 PrestaShop SA | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* 2007-2016 PrestaShop | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
|
@@ -19,7 +19,7 @@ | |
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2016 PrestaShop SA | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* 2007-2016 PrestaShop | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
|
@@ -19,7 +19,7 @@ | |
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2016 PrestaShop SA | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
@@ -255,7 +255,15 @@ public function getContent() | |
$output = $output.$this->renderForm(CronJobsForms::getJobForm(), CronJobsForms::getNewJobFormValues(), 'submitNewCronJob', true, $back_url); | ||
} elseif (Tools::isSubmit('updatecronjobs') && Tools::isSubmit('id_cronjob')) { | ||
$form_structure = CronJobsForms::getJobForm('Update cron task', true); | ||
$form = $this->renderForm($form_structure, CronJobsForms::getUpdateJobFormValues(), 'submitUpdateCronJob', true, $back_url, true); | ||
$form = $this->renderForm( | ||
$form_structure, | ||
CronJobsForms::getUpdateJobFormValues(), | ||
'submitUpdateCronJob', | ||
true, | ||
$back_url, | ||
true | ||
); | ||
|
||
$output = $output.$form; | ||
} elseif (Tools::isSubmit('deletecronjobs') && Tools::isSubmit('id_cronjob')) { | ||
$this->postProcessDeleteCronJob((int)Tools::getValue('id_cronjob')); | ||
|
@@ -364,13 +372,22 @@ protected function checkLocalEnvironment() | |
} | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
protected function isLocalEnvironment() | ||
{ | ||
if (isset($_SERVER['REMOTE_ADDR']) === false) { | ||
return true; | ||
} | ||
|
||
return in_array(Tools::getRemoteAddr(), array('127.0.0.1', '::1')) || preg_match('/^172\.16\.|^192\.168\.|^10\.|^127\.|^localhost|\.local$/', Configuration::get('PS_SHOP_DOMAIN')); | ||
$is_a_local_ip = in_array(Tools::getRemoteAddr(), array('127.0.0.1', '::1')); | ||
$is_a_local_shop_domain = preg_match( | ||
'/^172\.16\.|^192\.168\.|^10\.|^127\.|^localhost|\.local$/', | ||
Configuration::get('PS_SHOP_DOMAIN') | ||
); | ||
|
||
return ($is_a_local_ip || $is_a_local_shop_domain); | ||
} | ||
|
||
protected function renderForm($form, $form_values, $action, $cancel = false, $back_url = false, $update = false) | ||
|
@@ -513,6 +530,7 @@ protected function postProcessUpdateJob() | |
public function addNewModulesTasks() | ||
{ | ||
$crons = Hook::getHookModuleExecList('actionCronJob'); | ||
$table_name = _DB_PREFIX_.bqSQL($this->name); | ||
|
||
if ($crons == false) { | ||
return false; | ||
|
@@ -526,12 +544,20 @@ public function addNewModulesTasks() | |
$module = Module::getInstanceById((int)$cron['id_module']); | ||
|
||
if ($module == false) { | ||
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.bqSQL($this->name).' WHERE `id_cronjob` = \''.(int)$cron['id_cronjob'].'\''); | ||
Db::getInstance()->execute(sprintf("DELETE FROM '%s' WHERE `id_cronjob` = '%s'", $table_name, (int)$cron['id_cronjob'])); | ||
break; | ||
} | ||
|
||
$cronjob = (bool)Db::getInstance()->getValue('SELECT `id_cronjob` FROM `'._DB_PREFIX_.bqSQL($this->name).'` | ||
WHERE `id_module` = \''.$id_module.'\' AND `id_shop` = \''.$id_shop.'\' AND `id_shop_group` = \''.$id_shop_group.'\''); | ||
$select_query = sprintf( | ||
"SELECT `id_cronjob` FROM `%s` | ||
WHERE `id_module` = '%s' AND `id_shop` = '%s' AND `id_shop_group` = '%s'", | ||
$table_name, | ||
$id_module, | ||
$id_shop, | ||
$id_shop_group | ||
); | ||
|
||
$cronjob = (bool)Db::getInstance()->getValue($select_query); | ||
|
||
if ($cronjob == false) { | ||
$this->registerModuleHook($id_module); | ||
|
@@ -709,12 +735,27 @@ protected function updateWebservice($use_webservice) | |
protected function postProcessDeleteCronJob($id_cronjob) | ||
{ | ||
$id_cronjob = Tools::getValue('id_cronjob'); | ||
$id_module = Db::getInstance()->getValue('SELECT `id_module` FROM '._DB_PREFIX_.bqSQL($this->name).' WHERE `id_cronjob` = \''.(int)$id_cronjob.'\''); | ||
$table_name = _DB_PREFIX_.bqSQL($this->name); | ||
|
||
$select_query = sprintf( | ||
"SELECT `id_module` FROM `%s` WHERE `id_cronjob` = '%s'", | ||
$table_name, | ||
(int)$id_cronjob | ||
); | ||
$id_module = Db::getInstance()->getValue($select_query); | ||
|
||
if ((bool)$id_module == false) { | ||
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.bqSQL($this->name).' WHERE `id_cronjob` = \''.(int)$id_cronjob.'\''); | ||
Db::getInstance()->execute(sprintf( | ||
"DELETE FROM `%s` WHERE `id_cronjob` = '%s'", | ||
$table_name, | ||
(int)$id_cronjob | ||
)); | ||
} else { | ||
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.bqSQL($this->name).' SET `active` = FALSE WHERE `id_cronjob` = \''.(int)$id_cronjob.'\''); | ||
Db::getInstance()->execute(sprintf( | ||
"UPDATE `%s` SET `active` = FALSE WHERE `id_cronjob` = '%s'", | ||
$table_name, | ||
(int)$id_cronjob | ||
)); | ||
} | ||
|
||
return Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', false) | ||
|
@@ -747,6 +788,12 @@ protected function registerModuleHook($id_module) | |
|
||
protected function unregisterModuleHook($id_module) | ||
{ | ||
return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.bqSQL($this->name).' WHERE `id_module` = \''.(int)$id_module.'\''); | ||
$table_name = _DB_PREFIX_.bqSQL($this->name); | ||
|
||
return Db::getInstance()->execute(sprintf( | ||
"DELETE FROM `%s` WHERE `id_module` = '%s'", | ||
$table_name, | ||
(int)$id_module | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* 2007-2016 PrestaShop | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
|
@@ -19,7 +19,7 @@ | |
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2016 PrestaShop SA | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* 2007-2016 PrestaShop | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
|
@@ -19,7 +19,7 @@ | |
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2016 PrestaShop SA | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* 2007-2016 PrestaShop | ||
* 2007-2018 PrestaShop | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
|
@@ -19,7 +19,7 @@ | |
* needs please refer to http://www.prestashop.com for more information. | ||
* | ||
* @author PrestaShop SA <[email protected]> | ||
* @copyright 2007-2016 PrestaShop SA | ||
* @copyright 2007-2018 PrestaShop SA | ||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) | ||
* International Registered Trademark & Property of PrestaShop SA | ||
*/ | ||
|
Oops, something went wrong.