implement action runner
This commit is contained in:
parent
216c5a8dd5
commit
af9cc1759d
@ -44,7 +44,7 @@ class d3ActionWizard extends AdminDetailsController
|
||||
|
||||
public function getGroups()
|
||||
{
|
||||
return $this->configuration->getGroups();
|
||||
return $this->configuration->getActionGroups();
|
||||
}
|
||||
|
||||
public function getGroupActions($group)
|
||||
|
@ -44,7 +44,7 @@ class d3ExportWizard extends AdminDetailsController
|
||||
|
||||
public function getGroups()
|
||||
{
|
||||
return $this->configuration->getGroups();
|
||||
return $this->configuration->getExportGroups();
|
||||
}
|
||||
|
||||
public function getGroupExports($group)
|
||||
|
@ -15,15 +15,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\DataWizard\Application\Model;
|
||||
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
|
||||
use D3\ModCfg\Application\Model\d3filesystem;
|
||||
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
|
||||
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use OxidEsales\Eshop\Core\DatabaseProvider;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
||||
use OxidEsales\Eshop\Core\Exception\StandardException;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
abstract class ActionBase implements QueryBase
|
||||
@ -35,85 +29,14 @@ abstract class ActionBase implements QueryBase
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $format
|
||||
*
|
||||
* @throws DBALException
|
||||
* @throws DatabaseConnectionException
|
||||
* @throws DatabaseErrorException
|
||||
* @throws Exceptions\NoSuitableRendererException
|
||||
* @throws Exceptions\TaskException
|
||||
* @throws StandardException
|
||||
* @throws d3ShopCompatibilityAdapterException
|
||||
* @throws d3_cfg_mod_exception
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$rowCount = $this->getExportData( $this->getQuery() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getButtonText() : string
|
||||
{
|
||||
return "D3_DATAWIZARD_EXPORT_SUBMIT";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $format
|
||||
*
|
||||
* @return ExportRenderer\RendererInterface
|
||||
* @throws Exceptions\NoSuitableRendererException
|
||||
*/
|
||||
public function getRenderer($format): ExportRenderer\RendererInterface
|
||||
{
|
||||
return oxNew(RendererBridge::class)->getRenderer($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $format
|
||||
*
|
||||
* @return string
|
||||
* @throws Exceptions\NoSuitableRendererException
|
||||
*/
|
||||
public function getFileExtension($format): string
|
||||
{
|
||||
return $this->getRenderer($format)->getFileExtension();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rows
|
||||
* @param $fieldnames
|
||||
* @param $format
|
||||
*
|
||||
* @return string
|
||||
* @throws Exceptions\NoSuitableRendererException
|
||||
*/
|
||||
public function renderContent($rows, $fieldnames, $format): string
|
||||
{
|
||||
$renderer = $this->getRenderer($format);
|
||||
return $renderer->getContent($rows, $fieldnames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getExportFilenameBase() : string
|
||||
{
|
||||
return $this->getTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $format
|
||||
*
|
||||
* @return string
|
||||
* @throws Exceptions\NoSuitableRendererException
|
||||
*/
|
||||
public function getExportFileName($format) : string
|
||||
{
|
||||
return $this->getExportFilenameBase().'_'.date('Y-m-d_H-i-s').'.'.$this->getFileExtension($format);
|
||||
$this->executeAction( $this->getQuery() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,7 +46,7 @@ abstract class ActionBase implements QueryBase
|
||||
* @throws DatabaseConnectionException
|
||||
* @throws DatabaseErrorException
|
||||
*/
|
||||
public function getExportData( array $query ): array
|
||||
public function executeAction( array $query ): int
|
||||
{
|
||||
[ $queryString, $parameters ] = $query;
|
||||
|
||||
@ -137,6 +60,25 @@ abstract class ActionBase implements QueryBase
|
||||
);
|
||||
}
|
||||
|
||||
return DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC )->execute( $queryString, $parameters );
|
||||
$affected = DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC )->execute( $queryString, $parameters );
|
||||
|
||||
throw oxNew(
|
||||
Exceptions\TaskException::class,
|
||||
$this,
|
||||
sprintf(
|
||||
Registry::getLang()->translateString(
|
||||
$affected === 1 ? 'D3_DATAWIZARD_ERR_ACTIONRESULT' : 'D3_DATAWIZARD_ERR_ACTIONRESULTS'
|
||||
),
|
||||
$affected
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getButtonText() : string
|
||||
{
|
||||
return "D3_DATAWIZARD_ACTION_SUBMIT";
|
||||
}
|
||||
}
|
89
src/Application/Model/Actions/FixArtextendsItems.php
Normal file
89
src/Application/Model/Actions/FixArtextendsItems.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DataWizard\Application\Model\Actions;
|
||||
|
||||
use D3\DataWizard\Application\Model\ActionBase;
|
||||
use OxidEsales\Eshop\Core\Model\BaseModel;
|
||||
use OxidEsales\Eshop\Core\Model\MultiLanguageModel;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class FixArtextendsItems extends ActionBase
|
||||
{
|
||||
/**
|
||||
* fehlende oxartextends-Einträge nachtragen
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() : string
|
||||
{
|
||||
return Registry::getLang()->translateString('D3_DATAWIZARD_ACTIONS_FIXARTEXTENDSITEMS');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getQuery() : array
|
||||
{
|
||||
$aDefaultValueFields = array(
|
||||
'oxtimestamp' => "''",
|
||||
);
|
||||
|
||||
$aNonArtExtendsFields = array(
|
||||
'oxid' => 'oxarticles.oxid',
|
||||
);
|
||||
|
||||
$aArtExtendsFields = array_fill_keys($this->getArtExtendsFields(), "''");
|
||||
$aMergedFields = array_merge($aNonArtExtendsFields, $aArtExtendsFields);
|
||||
$aQueryFields = array_diff_key($aMergedFields, $aDefaultValueFields);
|
||||
|
||||
$sArtExtendsFields = implode(', ', array_keys($aQueryFields));
|
||||
|
||||
$select = "SELECT ".implode(', ', $aQueryFields).
|
||||
" FROM oxarticles".
|
||||
" LEFT JOIN oxartextends AS arx ON oxarticles.oxid = arx.oxid".
|
||||
" WHERE arx.oxid IS NULL";
|
||||
|
||||
$query = "INSERT INTO oxartextends ($sArtExtendsFields) ".
|
||||
$select;
|
||||
|
||||
return [$query, []];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getArtExtendsFields(): array
|
||||
{
|
||||
/** @var $oArtExtends MultiLanguageModel */
|
||||
$oArtExtends = oxNew(BaseModel::class);
|
||||
$oArtExtends->init('oxartextends', false);
|
||||
|
||||
$aFieldNames = $oArtExtends->getFieldNames();
|
||||
|
||||
if (false == $aFieldNames) {
|
||||
$oArtExtends->disableLazyLoading();
|
||||
$aFieldNames = $oArtExtends->getFieldNames();
|
||||
}
|
||||
|
||||
unset($aFieldNames[array_search('oxid', $aFieldNames)]);
|
||||
|
||||
return $aFieldNames;
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\DataWizard\Application\Model;
|
||||
|
||||
use D3\DataWizard\Application\Model\Actions\FixArtextendsItems;
|
||||
use D3\DataWizard\Application\Model\Exports\InactiveCategories;
|
||||
use D3\DataWizard\Application\Model\Exports\KeyFigures;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
@ -39,6 +40,8 @@ class Configuration
|
||||
public function configure()
|
||||
{
|
||||
if (false === Registry::getConfig()->getConfigParam('d3datawizard_hideexamples', false)) {
|
||||
$this->registerAction(self::GROUP_ARTICLES, oxNew(FixArtextendsItems::class));
|
||||
|
||||
$this->registerExport(self::GROUP_CATEGORY, oxNew(InactiveCategories::class));
|
||||
$this->registerExport(self::GROUP_SHOP, oxNew(KeyFigures::class));
|
||||
}
|
||||
@ -81,16 +84,34 @@ class Configuration
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getGroups(): array
|
||||
public function getActionGroups(): array
|
||||
{
|
||||
return array_keys($this->actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getExportGroups(): array
|
||||
{
|
||||
return array_keys($this->exports);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $group
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActionsByGroup($group)
|
||||
{
|
||||
return $this->actions[$group];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $group
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getExportsByGroup($group)
|
||||
{
|
||||
return $this->exports[$group];
|
||||
@ -103,7 +124,7 @@ class Configuration
|
||||
{
|
||||
$all = [];
|
||||
|
||||
foreach ($this->getGroups() as $group) {
|
||||
foreach ($this->getActionGroups() as $group) {
|
||||
$all = array_merge($all, $this->getActionsByGroup($group));
|
||||
}
|
||||
|
||||
@ -117,7 +138,7 @@ class Configuration
|
||||
{
|
||||
$all = [];
|
||||
|
||||
foreach ($this->getGroups() as $group) {
|
||||
foreach ($this->getExportGroups() as $group) {
|
||||
$all = array_merge($all, $this->getExportsByGroup($group));
|
||||
}
|
||||
|
||||
@ -131,7 +152,7 @@ class Configuration
|
||||
*/
|
||||
public function getActionById($id) : ActionBase
|
||||
{
|
||||
return $this->getAllExports()[$id];
|
||||
return $this->getAllActions()[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,11 +19,6 @@ interface QueryBase
|
||||
{
|
||||
public function run();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getExportFilenameBase() : string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
@ -40,6 +40,8 @@ $aLang = array(
|
||||
'D3_DATAWIZARD_EXPORT_FORMAT_CSV' => 'CSV-Format',
|
||||
'D3_DATAWIZARD_EXPORT_FORMAT_PRETTY' => 'Pretty-Format',
|
||||
|
||||
'D3_DATAWIZARD_ACTION_SUBMIT' => 'Aktion starten',
|
||||
|
||||
'D3_DATAWIZARD_DEBUG' => 'Debug: %1$s',
|
||||
|
||||
'D3_DATAWIZARD_ERR_NOEXPORTSELECT' => 'Export kann nicht ausgeführt werden. Exporte erfordern SELECT Query.',
|
||||
@ -57,7 +59,9 @@ $aLang = array(
|
||||
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_BASKETSIZE' => 'Warenkorbhöhe',
|
||||
'D3_DATAWIZARD_EXPORTS_KEYFIGURES_MONTH' => 'Monat',
|
||||
|
||||
// Abracadata
|
||||
// Harry Potter
|
||||
// Magic
|
||||
'D3_DATAWIZARD_ERR_ACTIONSELECT' => 'Aktion kann nicht ausgeführt werden. Aktionen können keine SELECTs exportieren.',
|
||||
'D3_DATAWIZARD_ERR_NOACTION_INSTALLED' => 'Es sind keine Aktionen installiert oder aktiviert.',
|
||||
'D3_DATAWIZARD_ERR_ACTIONRESULT' => '%1$s Eintrag verändert',
|
||||
'D3_DATAWIZARD_ERR_ACTIONRESULTS' => '%1$s Einträge verändert',
|
||||
'D3_DATAWIZARD_ACTIONS_FIXARTEXTENDSITEMS' => 'fehlende oxartextends-Einträge nachtragen',
|
||||
);
|
||||
|
@ -26,7 +26,7 @@
|
||||
</style>
|
||||
|
||||
[{capture name="d3script"}][{strip}]
|
||||
function startExport(id, format) {
|
||||
function startAction(id) {
|
||||
let elements = document.getElementsByClassName('errorbox');
|
||||
for (var i = 0; i < elements.length; i++){
|
||||
elements[i].style.display = 'none';
|
||||
@ -37,8 +37,7 @@
|
||||
}, 3000);
|
||||
document.getElementById('mask').className='on';
|
||||
document.getElementById('popup2').className='d3loader-2 on';
|
||||
document.getElementById('exportid').value = id;
|
||||
document.getElementById('exportformat').value = format;
|
||||
document.getElementById('actionid').value = id;
|
||||
document.getElementById('myedit').submit();
|
||||
}
|
||||
[{/strip}][{/capture}]
|
||||
@ -47,9 +46,8 @@
|
||||
<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post" style="padding: 0;margin: 0;height:0;">
|
||||
[{$oViewConf->getHiddenSid()}]
|
||||
<input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
|
||||
<input type="hidden" name="fnc" value="doExport">
|
||||
<input type="hidden" name="exportid" id="exportid" value="">
|
||||
<input type="hidden" name="exportformat" id="exportformat" value="CSV">
|
||||
<input type="hidden" name="fnc" value="doAction">
|
||||
<input type="hidden" name="actionid" id="actionid" value="">
|
||||
|
||||
[{assign var="groups" value=$oView->getGroups()}]
|
||||
[{if $groups|@count}]
|
||||
@ -67,27 +65,21 @@
|
||||
<div id="collapse[{$group}]" class="collapse" aria-labelledby="heading[{$group}]" data-parent="#accordion">
|
||||
<div class="card-body pb-0">
|
||||
<div class="row">
|
||||
[{foreach from=$oView->getGroupActions($group) key="id" item="export"}]
|
||||
[{foreach from=$oView->getGroupActions($group) key="id" item="action"}]
|
||||
<div class="col-sm-6 col-md-4 col-lg-3 pb-4">
|
||||
<div class="card">
|
||||
<h5 class="card-header">
|
||||
[{$export->getTitle()}]
|
||||
[{$action->getTitle()}]
|
||||
</h5>
|
||||
<div class="card-body">
|
||||
<p class="card-text">
|
||||
[{$export->getDescription()}]
|
||||
[{$action->getDescription()}]
|
||||
</p>
|
||||
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary" onclick="startAction('[{$id}]')">
|
||||
<i class="fas fa-magic"></i>
|
||||
[{oxmultilang ident=$export->getButtonText()}]
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<span class="sr-only">
|
||||
<i class="fas fa-magic"></i>
|
||||
[{oxmultilang ident=$export->getButtonText()}]
|
||||
</span>
|
||||
[{oxmultilang ident=$action->getButtonText()}]
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user