2017-12-20 13:44:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
*
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
*
|
|
|
|
* http://www.shopmodule.com
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\Ordermanager\Application\Controller\Admin;
|
|
|
|
|
2018-02-20 09:37:52 +01:00
|
|
|
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
|
|
|
|
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
|
2017-12-20 13:44:53 +01:00
|
|
|
use D3\Ordermanager\Application\Model\d3ordermanager;
|
|
|
|
use D3\ModCfg\Application\Controller\Admin\d3_cfg_mod_main;
|
|
|
|
use D3\ModCfg\Application\Model\d3str;
|
|
|
|
use D3\ModCfg\Application\Model\Filegenerator\d3filegeneratorcronsh;
|
|
|
|
use D3\ModCfg\Application\Model\Shopcompatibility\d3ShopCompatibilityAdapterHandler;
|
2018-02-20 09:37:52 +01:00
|
|
|
use Doctrine\DBAL\DBALException;
|
2019-05-15 11:31:56 +02:00
|
|
|
use Exception;
|
|
|
|
use OxidEsales\Eshop\Core\Config;
|
2018-02-20 09:37:52 +01:00
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\FileException;
|
2019-05-15 11:31:56 +02:00
|
|
|
use OxidEsales\Eshop\Core\Exception\StandardException;
|
|
|
|
use OxidEsales\Eshop\Core\Language;
|
2017-12-20 13:44:53 +01:00
|
|
|
use OxidEsales\Eshop\Core\Request;
|
|
|
|
use OxidEsales\Eshop\Application\Model\Shop;
|
|
|
|
use OxidEsales\Eshop\Core\ViewConfig;
|
|
|
|
|
|
|
|
class d3_cfg_ordermanagerset_main extends d3_cfg_mod_main
|
|
|
|
{
|
|
|
|
protected $_sModId = 'd3_ordermanager';
|
2019-05-15 11:31:56 +02:00
|
|
|
|
2017-12-20 13:44:53 +01:00
|
|
|
protected $_sThisTemplate = "d3_cfg_ordermanagerset_main.tpl";
|
|
|
|
protected $_blHasDebugSwitch = true;
|
|
|
|
protected $_sDebugHelpTextIdent = 'D3_ORDERMANAGER_SET_DEBUG_DESC';
|
|
|
|
protected $_sMenuItemTitle = 'd3mxordermanager';
|
|
|
|
protected $_sMenuSubItemTitle = 'd3mxordermanager_settings';
|
|
|
|
|
2019-05-15 11:31:56 +02:00
|
|
|
/**
|
|
|
|
* d3_cfg_ordermanagerset_main constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
d3GetModCfgDIC()->setParameter('d3.ordermanager.modcfgid', $this->_sModId);
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return d3ordermanager
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function getManager()
|
|
|
|
{
|
|
|
|
return d3GetModCfgDIC()->get(d3ordermanager::class);
|
|
|
|
}
|
|
|
|
|
2017-12-20 13:44:53 +01:00
|
|
|
/**
|
|
|
|
* get basic cronjob access password; for cases only, if no password is set
|
|
|
|
*
|
|
|
|
* @return string
|
2019-05-15 11:31:56 +02:00
|
|
|
* @throws Exception
|
2017-12-20 13:44:53 +01:00
|
|
|
*/
|
|
|
|
public function getBaseCronPW()
|
|
|
|
{
|
2019-05-15 11:31:56 +02:00
|
|
|
return $this->getManager()->getBaseCronPW();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ViewConfig
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function getViewConfig()
|
|
|
|
{
|
|
|
|
// don't use DIC because of circular reference
|
|
|
|
if ($this->_oViewConf === null) {
|
|
|
|
$this->_oViewConf = oxNew(ViewConfig::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->_oViewConf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return d3str
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function getD3Str()
|
|
|
|
{
|
|
|
|
return d3GetModCfgDIC()->get(d3str::class);
|
2017-12-20 13:44:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $blUsePw
|
|
|
|
* @param bool|int $iCronJobId
|
|
|
|
*
|
|
|
|
* @return string
|
2018-02-20 09:37:52 +01:00
|
|
|
* @throws DBALException
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
|
|
|
* @throws FileException
|
2019-05-15 11:31:56 +02:00
|
|
|
* @throws Exception
|
2017-12-20 13:44:53 +01:00
|
|
|
*/
|
|
|
|
public function getCronLink($blUsePw, $iCronJobId = false)
|
|
|
|
{
|
2019-05-15 11:31:56 +02:00
|
|
|
$sBaseUrl = $this->getViewConfig()->getModuleUrl('d3ordermanager').'public/d3_ordermanager_cron.php';
|
2017-12-20 13:44:53 +01:00
|
|
|
|
|
|
|
$aParameters = array(
|
2019-05-15 11:31:56 +02:00
|
|
|
'shp' => $this->getViewConfig()->getActiveShopId(),
|
2017-12-20 13:44:53 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($iCronJobId !== false) {
|
|
|
|
$aParameters['cjid'] = $iCronJobId;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($blUsePw) {
|
|
|
|
$aParameters['key'] = $this->d3GetSet()->getValue('sCronPassword') ?
|
|
|
|
$this->d3GetSet()->getValue('sCronPassword') :
|
|
|
|
$this->getBaseCronPW();
|
|
|
|
}
|
|
|
|
|
2019-05-15 11:31:56 +02:00
|
|
|
$sURL = $this->getD3Str()->generateParameterUrl($sBaseUrl, $aParameters);
|
2017-12-20 13:44:53 +01:00
|
|
|
|
|
|
|
return $sURL;
|
|
|
|
}
|
|
|
|
|
2019-12-10 11:45:33 +01:00
|
|
|
/**
|
|
|
|
* @param bool $blUsePw
|
|
|
|
* @param bool|int $iCronJobId
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @throws DBALException
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
|
|
|
* @throws FileException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function getCronPath($iCronJobId = false)
|
|
|
|
{
|
|
|
|
$sScriptPath = VENDOR_PATH.'bin/d3_ordermanager_cron';
|
|
|
|
|
|
|
|
$aParameters = array(
|
|
|
|
'shp' => $this->getViewConfig()->getActiveShopId(),
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($iCronJobId !== false) {
|
|
|
|
$aParameters['cjid'] = $iCronJobId;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sPath = $sScriptPath." ".implode(' ', $aParameters);
|
|
|
|
|
|
|
|
return $sPath;
|
|
|
|
}
|
|
|
|
|
2017-12-20 13:44:53 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
2018-02-20 09:37:52 +01:00
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
2019-05-15 11:31:56 +02:00
|
|
|
* @throws Exception
|
2017-12-20 13:44:53 +01:00
|
|
|
*/
|
|
|
|
public function getAvailableCronjobIds()
|
|
|
|
{
|
2019-05-15 11:31:56 +02:00
|
|
|
return $this->getManager()->getAvailableCronjobIds();
|
2017-12-20 13:44:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool|array $aCJID
|
|
|
|
* @return string
|
2019-05-15 11:31:56 +02:00
|
|
|
* @throws Exception
|
2017-12-20 13:44:53 +01:00
|
|
|
*/
|
|
|
|
public function getCJIDDesc($aCJID)
|
|
|
|
{
|
2019-05-15 11:31:56 +02:00
|
|
|
/** @var Language $oLang */
|
|
|
|
$oLang = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Language::class);
|
2017-12-20 13:44:53 +01:00
|
|
|
if ($aCJID['count'] == 1) {
|
|
|
|
return sprintf(
|
2019-05-15 11:31:56 +02:00
|
|
|
$oLang->translateString('D3_ORDERMANAGER_SET_CRON_JOBID', null, true),
|
2017-12-20 13:44:53 +01:00
|
|
|
$aCJID['id'],
|
|
|
|
$aCJID['count']
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return sprintf(
|
2019-05-15 11:31:56 +02:00
|
|
|
$oLang->translateString('D3_ORDERMANAGER_SET_CRON_JOBSID', null, true),
|
2017-12-20 13:44:53 +01:00
|
|
|
$aCJID['id'],
|
|
|
|
$aCJID['count']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool|int $iCronJobId
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCronTimestampVarName($iCronJobId = false)
|
|
|
|
{
|
|
|
|
$sVarName = "sCronExecTimestamp";
|
|
|
|
|
|
|
|
if ($iCronJobId !== false) {
|
|
|
|
$sVarName .= $iCronJobId;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sVarName;
|
|
|
|
}
|
|
|
|
|
2019-05-15 11:31:56 +02:00
|
|
|
/**
|
|
|
|
* @return d3filegeneratorcronsh
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function getFileGeneratorCronSh()
|
|
|
|
{
|
|
|
|
return d3GetModCfgDIC()->get(d3filegeneratorcronsh::class);
|
|
|
|
}
|
|
|
|
|
2017-12-20 13:44:53 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
2019-05-15 11:31:56 +02:00
|
|
|
* @throws Exception
|
2017-12-20 13:44:53 +01:00
|
|
|
*/
|
|
|
|
public function getCronProviderList()
|
|
|
|
{
|
2019-05-15 11:31:56 +02:00
|
|
|
return $this->getFileGeneratorCronSh()->getContentList();
|
|
|
|
}
|
2017-12-20 13:44:53 +01:00
|
|
|
|
2019-05-15 11:31:56 +02:00
|
|
|
/**
|
|
|
|
* @return d3ShopCompatibilityAdapterHandler
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function getCompatibilityAdapterHandler()
|
|
|
|
{
|
|
|
|
return d3GetModCfgDIC()->get(d3ShopCompatibilityAdapterHandler::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Shop
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function d3GetActiveShop()
|
|
|
|
{
|
|
|
|
/** @var Config $config */
|
|
|
|
$config = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Config::class);
|
|
|
|
|
|
|
|
return $config->getActiveShop();
|
2017-12-20 13:44:53 +01:00
|
|
|
}
|
|
|
|
|
2018-02-20 09:37:52 +01:00
|
|
|
/**
|
|
|
|
* @throws DBALException
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
2019-05-15 11:31:56 +02:00
|
|
|
* @throws StandardException
|
2018-02-20 09:37:52 +01:00
|
|
|
* @throws d3ShopCompatibilityAdapterException
|
|
|
|
* @throws d3_cfg_mod_exception
|
2019-05-15 11:31:56 +02:00
|
|
|
* @throws Exception
|
2018-02-20 09:37:52 +01:00
|
|
|
*/
|
2017-12-20 13:44:53 +01:00
|
|
|
public function generateCronShFile()
|
|
|
|
{
|
2019-12-10 11:45:33 +01:00
|
|
|
$sScriptPath = VENDOR_PATH.'bin/d3_ordermanager_cron';
|
2017-12-20 13:44:53 +01:00
|
|
|
|
2019-05-15 11:31:56 +02:00
|
|
|
/** @var Request $request */
|
|
|
|
$request = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Request::class);
|
|
|
|
$sCronId = $request->getRequestEscapedParameter('cronid');
|
2017-12-20 13:44:53 +01:00
|
|
|
|
|
|
|
/** @var Shop $oShop */
|
2019-05-15 11:31:56 +02:00
|
|
|
$oShop = $this->d3GetActiveShop();
|
2017-12-20 13:44:53 +01:00
|
|
|
$aParameters = array(
|
|
|
|
0 => $oShop->getId(),
|
|
|
|
1 => $sCronId,
|
|
|
|
);
|
|
|
|
|
2019-05-15 11:31:56 +02:00
|
|
|
$oD3ShGenerator = $this->getFileGeneratorCronSh();
|
|
|
|
$oD3ShGenerator->setContentType($request->getRequestEscapedParameter('crontype'));
|
2017-12-20 13:44:53 +01:00
|
|
|
$oD3ShGenerator->setScriptPath($sScriptPath);
|
|
|
|
$oD3ShGenerator->setSortedParameterList($aParameters);
|
|
|
|
$oD3ShGenerator->startDownload('d3ordermanager_'.$oShop->getId()."_".$sCronId.".sh");
|
|
|
|
}
|
|
|
|
}
|