mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03:14 +03:00
ability to enable or disable job manager runs via client request
* ability to enable or disable job manager runs via client request * ability to run all jobs via cli
This commit is contained in:
parent
7db8ff5044
commit
8a3f87ce81
@ -77,12 +77,9 @@ class RetailcrmJobsModuleFrontController extends ModuleFrontController
|
||||
*/
|
||||
protected function getData()
|
||||
{
|
||||
RetailcrmJobManager::startJobs(array(
|
||||
'RetailcrmAbandonedCartsEvent' => null,
|
||||
'RetailcrmIcmlEvent' => new \DateInterval('PT4H'),
|
||||
'RetailcrmSyncEvent' => new \DateInterval('PT7M'),
|
||||
'RetailcrmInventoriesEvent' => new \DateInterval('PT15M')
|
||||
));
|
||||
if (RetailcrmTools::isWebJobsEnabled()) {
|
||||
RetailcrmTools::startJobManager();
|
||||
}
|
||||
|
||||
return array('success' => true);
|
||||
}
|
||||
|
@ -99,7 +99,15 @@ class RetailcrmCli
|
||||
}
|
||||
|
||||
$shortopts = "j:";
|
||||
$longopts = array("job:", "reset-job-manager", "reset-all");
|
||||
$longopts = array(
|
||||
"job:",
|
||||
"set-web-jobs:",
|
||||
"query-web-jobs",
|
||||
"run-jobs",
|
||||
"reset-job-manager",
|
||||
"reset-all"
|
||||
);
|
||||
|
||||
$options = getopt($shortopts, $longopts);
|
||||
$jobName = isset($options['j']) ? $options['j'] : (isset($options['job']) ? $options['job'] : null);
|
||||
|
||||
@ -107,6 +115,12 @@ class RetailcrmCli
|
||||
$this->resetJobManager();
|
||||
} elseif (isset($options['reset-all'])) {
|
||||
$this->resetAll();
|
||||
} elseif (isset($options['query-web-jobs'])) {
|
||||
$this->queryWebJobs();
|
||||
} elseif (isset($options['run-jobs'])) {
|
||||
RetailcrmTools::startJobManager();
|
||||
} elseif (isset($options['set-web-jobs'])) {
|
||||
$this->setWebJobs(self::getBool($options['set-web-jobs']));
|
||||
} elseif (empty($jobName)) {
|
||||
$this->help();
|
||||
} else {
|
||||
@ -181,6 +195,9 @@ class RetailcrmCli
|
||||
RetailcrmLogger::output();
|
||||
RetailcrmLogger::output(sprintf('> php %s -j <job name> - Runs provided job', $this->cliPath));
|
||||
RetailcrmLogger::output(sprintf('> php %s --job <job name> - Runs provided job', $this->cliPath));
|
||||
RetailcrmLogger::output(sprintf('> php %s --run-jobs - Run default jobs routine', $this->cliPath));
|
||||
RetailcrmLogger::output(sprintf('> php %s --set-web-jobs true / false - Enable or disable web jobs', $this->cliPath));
|
||||
RetailcrmLogger::output(sprintf('> php %s --query-web-jobs - Check web jobs status', $this->cliPath));
|
||||
RetailcrmLogger::output();
|
||||
RetailcrmLogger::output(
|
||||
"WARNING: Commands below are dangerous and should be used only when " .
|
||||
@ -199,6 +216,43 @@ class RetailcrmCli
|
||||
RetailcrmLogger::output();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets new web jobs state
|
||||
*
|
||||
* @param bool $state
|
||||
*/
|
||||
private function setWebJobs($state)
|
||||
{
|
||||
$this->loadConfiguration();
|
||||
|
||||
Configuration::updateGlobalValue(RetailCRM::ENABLE_WEB_JOBS, $state ? '1' : '0');
|
||||
RetailcrmLogger::output('Updated web jobs state.');
|
||||
$this->queryWebJobs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints web jobs status
|
||||
*/
|
||||
private function queryWebJobs()
|
||||
{
|
||||
$this->loadConfiguration();
|
||||
|
||||
RetailcrmLogger::output(sprintf(
|
||||
'Web jobs status: %s',
|
||||
RetailcrmTools::isWebJobsEnabled() ? 'true (enabled)' : 'false (disabled)'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load PrestaShop configuration if it's not loaded yet
|
||||
*/
|
||||
private function loadConfiguration()
|
||||
{
|
||||
if (!Configuration::configurationIsLoaded()) {
|
||||
Configuration::loadConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets JobManager
|
||||
*/
|
||||
@ -267,6 +321,24 @@ class RetailcrmCli
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts string param from CLI into boolean
|
||||
*
|
||||
* @param string $param
|
||||
*/
|
||||
private static function getBool($param)
|
||||
{
|
||||
if ('true' == $param) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ('false' == $param) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of jobs which are allowed to be executed via cli
|
||||
*
|
||||
|
@ -365,6 +365,11 @@ class RetailcrmTools
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function isWebJobsEnabled()
|
||||
{
|
||||
return '0' !== Configuration::getGlobalValue(RetailCRM::ENABLE_WEB_JOBS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge new address to customer, preserves old phone numbers.
|
||||
*
|
||||
@ -460,4 +465,19 @@ class RetailcrmTools
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts JobManager with list of pre-registered jobs
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function startJobManager()
|
||||
{
|
||||
RetailcrmJobManager::startJobs(array(
|
||||
'RetailcrmAbandonedCartsEvent' => null,
|
||||
'RetailcrmIcmlEvent' => new \DateInterval('PT4H'),
|
||||
'RetailcrmSyncEvent' => new \DateInterval('PT7M'),
|
||||
'RetailcrmInventoriesEvent' => new \DateInterval('PT15M')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ class RetailCRM extends Module
|
||||
const LATEST_API_VERSION = '5';
|
||||
const CONSULTANT_SCRIPT = 'RETAILCRM_CONSULTANT_SCRIPT';
|
||||
const CONSULTANT_RCCT = 'RETAILCRM_CONSULTANT_RCCT';
|
||||
const ENABLE_WEB_JOBS = 'RETAILCRM_ENABLE_WEB_JOBS';
|
||||
|
||||
/**
|
||||
* @var array $templateErrors
|
||||
|
Loading…
x
Reference in New Issue
Block a user