2021-05-05 23:20:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace D3\DataWizard\Application\Model;
|
|
|
|
|
|
|
|
use OxidEsales\Eshop\Core\DatabaseProvider;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
|
|
|
|
abstract class ActionBase implements QueryBase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDescription() : string
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
2021-06-22 13:26:51 +02:00
|
|
|
|
2021-05-05 23:20:42 +02:00
|
|
|
/**
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2021-06-22 13:26:51 +02:00
|
|
|
$this->executeAction( $this->getQuery() );
|
2021-05-05 23:20:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $query
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DatabaseErrorException
|
|
|
|
*/
|
2021-06-22 13:26:51 +02:00
|
|
|
public function executeAction( array $query ): int
|
2021-05-05 23:20:42 +02:00
|
|
|
{
|
|
|
|
[ $queryString, $parameters ] = $query;
|
|
|
|
|
|
|
|
$queryString = trim($queryString);
|
|
|
|
|
|
|
|
if ( strtolower( substr( $queryString, 0, 6 ) ) === 'select' ) {
|
|
|
|
throw oxNew(
|
|
|
|
Exceptions\TaskException::class,
|
|
|
|
$this,
|
|
|
|
Registry::getLang()->translateString( 'D3_DATAWIZARD_ERR_ACTIONSELECT' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-22 13:26:51 +02:00
|
|
|
$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";
|
2021-05-05 23:20:42 +02:00
|
|
|
}
|
|
|
|
}
|