mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03:14 +03:00
Added help arguments. Improved multistore checks. Added query-shops argument
This commit is contained in:
parent
41794dca51
commit
f5bfcc0961
@ -99,10 +99,12 @@ class RetailcrmCli
|
||||
RetailcrmLogger::output('WARNING: cannot handle signals properly, force stop can cause problems!');
|
||||
}
|
||||
|
||||
$shortopts = 'j:s:';
|
||||
$shortopts = 'hj:s:';
|
||||
$longopts = [
|
||||
'help',
|
||||
'job:',
|
||||
'shop:',
|
||||
'query-shops',
|
||||
'set-web-jobs:',
|
||||
'query-web-jobs',
|
||||
'run-jobs',
|
||||
@ -124,11 +126,15 @@ class RetailcrmCli
|
||||
RetailcrmTools::startJobManager();
|
||||
} elseif (isset($options['set-web-jobs'])) {
|
||||
$this->setWebJobs(self::getBool($options['set-web-jobs']), $shopId);
|
||||
} elseif (empty($jobName)) {
|
||||
$this->help();
|
||||
} else {
|
||||
} elseif (isset($options['query-shops'])) {
|
||||
$this->queryShops();
|
||||
} elseif (!empty($jobName)) {
|
||||
$this->setCleanupOnShutdown();
|
||||
$this->runJob($jobName, $shopId);
|
||||
} elseif (isset($options['help']) || isset($options['h'])) {
|
||||
$this->printHelp();
|
||||
} else {
|
||||
$this->printArgumentError('Unknown argument!');
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,7 +204,7 @@ class RetailcrmCli
|
||||
/**
|
||||
* Prints CLI help
|
||||
*/
|
||||
private function help()
|
||||
private function printHelp()
|
||||
{
|
||||
RetailcrmLogger::output('Available jobs:');
|
||||
RetailcrmLogger::output();
|
||||
@ -215,6 +221,9 @@ class RetailcrmCli
|
||||
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(sprintf('> php %s --query-shops - Get list of shops with ids (for MultiShop)', $this->cliPath));
|
||||
RetailcrmLogger::output(sprintf('> php %s -h - Shows this page', $this->cliPath));
|
||||
RetailcrmLogger::output(sprintf('> php %s --help - Shows this page', $this->cliPath));
|
||||
RetailcrmLogger::output();
|
||||
RetailcrmLogger::output(
|
||||
'NOTICE: If you have MultiShop feature enabled, you can additionally ' .
|
||||
@ -242,6 +251,15 @@ class RetailcrmCli
|
||||
RetailcrmLogger::output();
|
||||
}
|
||||
|
||||
private function printArgumentError($message = '')
|
||||
{
|
||||
if (!empty($message)) {
|
||||
RetailcrmLogger::output($message);
|
||||
}
|
||||
|
||||
RetailcrmLogger::output('Use -h or --help to get more info about CLI');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets new web jobs state
|
||||
*
|
||||
@ -250,13 +268,12 @@ class RetailcrmCli
|
||||
*/
|
||||
private function setWebJobs($state, $shopId = null)
|
||||
{
|
||||
if (null === $shopId) {
|
||||
RetailcrmLogger::output('You must specify shop id');
|
||||
$shopId = $this->setShopId($shopId);
|
||||
|
||||
if (null === $shopId) {
|
||||
return;
|
||||
}
|
||||
|
||||
RetailcrmContextSwitcher::setShopContext($shopId);
|
||||
$this->loadConfiguration();
|
||||
|
||||
Configuration::updateValue(RetailCRM::ENABLE_WEB_JOBS, $state ? '1' : '0');
|
||||
@ -271,13 +288,12 @@ class RetailcrmCli
|
||||
*/
|
||||
private function queryWebJobs($shopId = null)
|
||||
{
|
||||
if (null === $shopId) {
|
||||
RetailcrmLogger::output('You must specify shop id');
|
||||
$shopId = $this->setShopId($shopId);
|
||||
|
||||
if (null === $shopId) {
|
||||
return;
|
||||
}
|
||||
|
||||
RetailcrmContextSwitcher::setShopContext($shopId);
|
||||
$this->loadConfiguration();
|
||||
|
||||
RetailcrmLogger::output(sprintf(
|
||||
@ -286,6 +302,44 @@ class RetailcrmCli
|
||||
));
|
||||
}
|
||||
|
||||
private function queryShops()
|
||||
{
|
||||
$isFeatureActive = Shop::isFeatureActive();
|
||||
|
||||
RetailcrmLogger::output(sprintf(
|
||||
'Multistore status: %s',
|
||||
$isFeatureActive ? 'true (enabled)' : 'false (disabled)'
|
||||
));
|
||||
|
||||
$shops = RetailcrmContextSwitcher::getShops();
|
||||
RetailcrmLogger::output(
|
||||
"\nShop ID\t| Shop Name"
|
||||
);
|
||||
|
||||
foreach ($shops as $shop) {
|
||||
RetailcrmLogger::output(sprintf(
|
||||
"%s\t- %s",
|
||||
$shop['id_shop'],
|
||||
$shop['name']
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private function setShopId($shopId)
|
||||
{
|
||||
if (null === $shopId) {
|
||||
$shopId = Shop::getContextShopID();
|
||||
}
|
||||
|
||||
if (null === $shopId) {
|
||||
$this->printArgumentError('You must specify shop id');
|
||||
} else {
|
||||
RetailcrmContextSwitcher::setShopContext($shopId);
|
||||
}
|
||||
|
||||
return $shopId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load PrestaShop configuration if it's not loaded yet
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user