Skip to content

Commit

Permalink
fix cast issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Nakahiru committed Mar 2, 2017
1 parent 683d691 commit 5f6b20c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions classes/CronJobsForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function getJobForm($title = 'New cron task', $update = false)

if (($update == true) && (Tools::isSubmit('id_cronjob'))) {
$id_cronjob = (int)Tools::getValue('id_cronjob');
$id_module = (int)Db::getInstance()->getValue('SELECT `id_module` FROM `'._DB_PREFIX_.self::$module->name.'`
$id_module = (int)Db::getInstance()->getValue('SELECT `id_module` FROM `'._DB_PREFIX_.bqSQL(self::$module->name).'`
WHERE `id_cronjob` = \''.(int)$id_cronjob.'\'
AND `id_shop` = \''.$id_shop.'\' AND `id_shop_group` = \''.$id_shop_group.'\'');

Expand Down Expand Up @@ -252,7 +252,7 @@ public static function getUpdateJobFormValues()
$id_shop_group = (int)Context::getContext()->shop->id_shop_group;

$id_cronjob = (int)Tools::getValue('id_cronjob');
$cron = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.self::$module->name.'`
$cron = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.bqSQL(self::$module->name).'`
WHERE `id_cronjob` = \''.$id_cronjob.'\'
AND `id_shop` = \''.$id_shop.'\' AND `id_shop_group` = \''.$id_shop_group.'\'');

Expand Down Expand Up @@ -281,14 +281,14 @@ public static function getTasksListValues()
$id_shop_group = (int)Context::getContext()->shop->id_shop_group;

self::$module->addNewModulesTasks();
$crons = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.self::$module->name.'` WHERE `id_shop` = \''.$id_shop.'\' AND `id_shop_group` = \''.$id_shop_group.'\'');
$crons = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.bqSQL(self::$module->name).'` WHERE `id_shop` = \''.$id_shop.'\' AND `id_shop_group` = \''.$id_shop_group.'\'');

foreach ($crons as $key => &$cron) {
if (empty($cron['id_module']) == false) {
$module = Module::getInstanceById((int)$cron['id_module']);

if ($module == false) {
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.self::$module->name.' WHERE `id_cronjob` = \''.(int)$cron['id_cronjob'].'\'');
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.bqSQL(self::$module->name).' WHERE `id_cronjob` = \''.(int)$cron['id_cronjob'].'\'');
unset($crons[$key]);
break;
}
Expand Down
10 changes: 5 additions & 5 deletions controllers/admin/AdminCronJobsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ public function postProcess()

protected function runModulesCrons()
{
$query = 'SELECT * FROM '._DB_PREFIX_.$this->module->name.' WHERE `active` = 1 AND `id_module` IS NOT NULL';
$query = 'SELECT * FROM '._DB_PREFIX_.bqSQL($this->module->name).' WHERE `active` = 1 AND `id_module` IS NOT NULL';
$crons = Db::getInstance()->executeS($query);

if (is_array($crons) && (count($crons) > 0)) {
foreach ($crons as &$cron) {
$module = Module::getInstanceById((int)$cron['id_module']);

if ($module == false) {
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->module->name.' WHERE `id_cronjob` = \''.(int)$cron['id_cronjob'].'\'');
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.bqSQL($this->module->name).' WHERE `id_cronjob` = \''.(int)$cron['id_cronjob'].'\'');
break;
} elseif ($this->shouldBeExecuted($cron) == true) {
Hook::exec('actionCronJob', array(), $cron['id_module']);
$query = 'UPDATE '._DB_PREFIX_.$this->module->name.' SET `updated_at` = NOW(), `active` = IF (`one_shot` = TRUE, FALSE, `active`) WHERE `id_cronjob` = \''.$cron['id_cronjob'].'\'';
$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'].'\'';
Db::getInstance()->execute($query);
}
}
Expand All @@ -74,14 +74,14 @@ protected function runModulesCrons()

protected function runTasksCrons()
{
$query = 'SELECT * FROM '._DB_PREFIX_.$this->module->name.' WHERE `active` = 1 AND `id_module` IS NULL';
$query = 'SELECT * FROM '._DB_PREFIX_.bqSQL($this->module->name).' WHERE `active` = 1 AND `id_module` IS NULL';
$crons = Db::getInstance()->executeS($query);

if (is_array($crons) && (count($crons) > 0)) {
foreach ($crons as &$cron) {
if ($this->shouldBeExecuted($cron) == true) {
Tools::file_get_contents(urldecode($cron['task']), false);
$query = 'UPDATE '._DB_PREFIX_.$this->module->name.' SET `updated_at` = NOW(), `active` = IF (`one_shot` = TRUE, FALSE, `active`) WHERE `id_cronjob` = \''.$cron['id_cronjob'].'\'';
$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'].'\'';
Db::getInstance()->execute($query);
}
}
Expand Down
30 changes: 15 additions & 15 deletions cronjobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function uninstall()
public function installDb()
{
return Db::getInstance()->execute(
'CREATE TABLE IF NOT EXISTS '._DB_PREFIX_.$this->name.' (
'CREATE TABLE IF NOT EXISTS '._DB_PREFIX_.bqSQL($this->name).' (
`id_cronjob` INTEGER(10) NOT NULL AUTO_INCREMENT,
`id_module` INTEGER(10) DEFAULT NULL,
`description` TEXT DEFAULT NULL,
Expand All @@ -153,7 +153,7 @@ public function installDb()

public function uninstallDb()
{
return Db::getInstance()->execute('DROP TABLE IF EXISTS '._DB_PREFIX_.$this->name);
return Db::getInstance()->execute('DROP TABLE IF EXISTS '._DB_PREFIX_.bqSQL($this->name));
}

public function installTab()
Expand Down Expand Up @@ -454,15 +454,15 @@ protected function postProcessNewJob()
$month = (int)Tools::getValue('month');
$day_of_week = (int)Tools::getValue('day_of_week');

$result = Db::getInstance()->getRow('SELECT id_cronjob FROM '._DB_PREFIX_.$this->name.'
$result = Db::getInstance()->getRow('SELECT id_cronjob FROM '._DB_PREFIX_.bqSQL($this->name).'
WHERE `task` = \''.$task.'\' AND `hour` = \''.$hour.'\' AND `day` = \''.$day.'\'
AND `month` = \''.$month.'\' AND `day_of_week` = \''.$day_of_week.'\'');

if ($result == false) {
$id_shop = (int)Context::getContext()->shop->id;
$id_shop_group = (int)Context::getContext()->shop->id_shop_group;

$query = 'INSERT INTO '._DB_PREFIX_.$this->name.'
$query = 'INSERT INTO '._DB_PREFIX_.bqSQL($this->name).'
(`description`, `task`, `hour`, `day`, `month`, `day_of_week`, `updated_at`, `active`, `id_shop`, `id_shop_group`)
VALUES (\''.$description.'\', \''.$task.'\', \''.$hour.'\', \''.$day.'\', \''.$month.'\', \''.$day_of_week.'\', NULL, TRUE, '.$id_shop.', '.$id_shop_group.')';

Expand Down Expand Up @@ -495,7 +495,7 @@ protected function postProcessUpdateJob()
// $id_shop = (int)Context::getContext()->shop->id;
// $id_shop_group = (int)Context::getContext()->shop->id_shop_group;

$query = 'UPDATE '._DB_PREFIX_.$this->name.'
$query = 'UPDATE '._DB_PREFIX_.bqSQL($this->name).'
SET `description` = \''.$description.'\',
`task` = \''.$task.'\',
`hour` = \''.$hour.'\',
Expand Down Expand Up @@ -526,11 +526,11 @@ public function addNewModulesTasks()
$module = Module::getInstanceById((int)$cron['id_module']);

if ($module == false) {
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->name.' WHERE `id_cronjob` = \''.(int)$cron['id_cronjob'].'\'');
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.bqSQL($this->name).' WHERE `id_cronjob` = \''.(int)$cron['id_cronjob'].'\'');
break;
}

$cronjob = (bool)Db::getInstance()->getValue('SELECT `id_cronjob` FROM `'._DB_PREFIX_.$this->name.'`
$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.'\'');

if ($cronjob == false) {
Expand All @@ -549,7 +549,7 @@ protected function postProcessUpdateJobOneShot()
// $id_shop = (int)Context::getContext()->shop->id;
// $id_shop_group = (int)Context::getContext()->shop->id_shop_group;

Db::getInstance()->execute('UPDATE '._DB_PREFIX_.$this->name.'
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.bqSQL($this->name).'
SET `one_shot` = IF (`one_shot`, 0, 1) WHERE `id_cronjob` = \''.(int)$id_cronjob.'\'');

Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', false)
Expand All @@ -567,7 +567,7 @@ protected function postProcessUpdateJobStatus()
// $id_shop = (int)Context::getContext()->shop->id;
// $id_shop_group = (int)Context::getContext()->shop->id_shop_group;

Db::getInstance()->execute('UPDATE '._DB_PREFIX_.$this->name.'
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.bqSQL($this->name).'
SET `active` = IF (`active`, 0, 1) WHERE `id_cronjob` = \''.(int)$id_cronjob.'\'');

Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', false)
Expand Down Expand Up @@ -709,12 +709,12 @@ 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_.$this->name.' WHERE `id_cronjob` = \''.(int)$id_cronjob.'\'');
$id_module = Db::getInstance()->getValue('SELECT `id_module` FROM '._DB_PREFIX_.bqSQL($this->name).' WHERE `id_cronjob` = \''.(int)$id_cronjob.'\'');

if ((bool)$id_module == false) {
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->name.' WHERE `id_cronjob` = \''.(int)$id_cronjob.'\'');
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.bqSQL($this->name).' WHERE `id_cronjob` = \''.(int)$id_cronjob.'\'');
} else {
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.$this->name.' SET `active` = FALSE WHERE `id_cronjob` = \''.(int)$id_cronjob.'\'');
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.bqSQL($this->name).' SET `active` = FALSE WHERE `id_cronjob` = \''.(int)$id_cronjob.'\'');
}

return Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', false)
Expand All @@ -731,13 +731,13 @@ protected function registerModuleHook($id_module)
if (is_callable(array($module, 'getCronFrequency')) == true) {
$frequency = $module->getCronFrequency();

$query = 'INSERT INTO '._DB_PREFIX_.$this->name.'
$query = 'INSERT INTO '._DB_PREFIX_.bqSQL($this->name).'
(`id_module`, `hour`, `day`, `month`, `day_of_week`, `active`, `id_shop`, `id_shop_group`)
VALUES (\''.$id_module.'\', \''.$frequency['hour'].'\', \''.$frequency['day'].'\',
\''.$frequency['month'].'\', \''.$frequency['day_of_week'].'\',
TRUE, '.$id_shop.', '.$id_shop_group.')';
} else {
$query = 'INSERT INTO '._DB_PREFIX_.$this->name.'
$query = 'INSERT INTO '._DB_PREFIX_.bqSQL($this->name).'
(`id_module`, `active`, `id_shop`, `id_shop_group`)
VALUES ('.$id_module.', FALSE, '.$id_shop.', '.$id_shop_group.')';
}
Expand All @@ -747,6 +747,6 @@ protected function registerModuleHook($id_module)

protected function unregisterModuleHook($id_module)
{
return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->name.' WHERE `id_module` = \''.(int)$id_module.'\'');
return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.bqSQL($this->name).' WHERE `id_module` = \''.(int)$id_module.'\'');
}
}

0 comments on commit 5f6b20c

Please sign in to comment.