ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract database handler for integration tests
|
||||
*/
|
||||
namespace Magento\TestFramework\Db;
|
||||
|
||||
abstract class AbstractDb
|
||||
{
|
||||
/**
|
||||
* DB host name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_host = '';
|
||||
|
||||
/**
|
||||
* DB credentials -- user name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_user = '';
|
||||
|
||||
/**
|
||||
* DB credentials -- password
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_password = '';
|
||||
|
||||
/**
|
||||
* DB name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_schema = '';
|
||||
|
||||
/**
|
||||
* Path to a temporary directory in the file system
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_varPath = '';
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Shell
|
||||
*/
|
||||
protected $_shell;
|
||||
|
||||
/**
|
||||
* Set initial essential parameters
|
||||
*
|
||||
* @param string $host
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $schema
|
||||
* @param string $varPath
|
||||
* @param \Magento\Framework\Shell $shell
|
||||
*/
|
||||
public function __construct($host, $user, $password, $schema, $varPath, \Magento\Framework\Shell $shell)
|
||||
{
|
||||
$this->_host = $host;
|
||||
$this->_user = $user;
|
||||
$this->_password = $password;
|
||||
$this->_schema = $schema;
|
||||
$this->_varPath = $varPath;
|
||||
$this->_shell = $shell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all DB objects
|
||||
*/
|
||||
abstract public function cleanup();
|
||||
|
||||
/**
|
||||
* Get filename for setup db dump
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getSetupDbDumpFilename();
|
||||
|
||||
/**
|
||||
* Is dump exists
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function isDbDumpExists();
|
||||
|
||||
/**
|
||||
* Store setup db dump
|
||||
*/
|
||||
abstract public function storeDbDump();
|
||||
|
||||
/**
|
||||
* Restore db from setup db dump
|
||||
*/
|
||||
abstract public function restoreFromDbDump();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getVendorName();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSchema()
|
||||
{
|
||||
return $this->_schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->_host;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->_user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->_password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create file with sql script content.
|
||||
* Utility method that is used in children classes
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $content
|
||||
* @return int
|
||||
*/
|
||||
protected function _createScript($file, $content)
|
||||
{
|
||||
return file_put_contents($file, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \LogicException
|
||||
*/
|
||||
protected function assertVarPathWritable()
|
||||
{
|
||||
if (!is_dir($this->_varPath) || !is_writable($this->_varPath)) {
|
||||
throw new \LogicException("The specified '{$this->_varPath}' is not a directory or not writable.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
// @codingStandardsIgnoreFile
|
||||
|
||||
/**
|
||||
* See \Magento\TestFramework\Db\Adapter\TransactionInterface
|
||||
*/
|
||||
namespace Magento\TestFramework\Db\Adapter;
|
||||
|
||||
class Mysql extends \Magento\Framework\DB\Adapter\Pdo\Mysql implements \Magento\TestFramework\Db\Adapter\TransactionInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_levelAdjustment = 0;
|
||||
|
||||
/**
|
||||
* See \Magento\TestFramework\Db\Adapter\TransactionInterface
|
||||
*
|
||||
* @return \Magento\TestFramework\Db\Adapter\Mysql
|
||||
*/
|
||||
public function beginTransparentTransaction()
|
||||
{
|
||||
$this->_levelAdjustment += 1;
|
||||
return $this->beginTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
* See \Magento\TestFramework\Db\Adapter\TransactionInterface
|
||||
*
|
||||
* @return \Magento\TestFramework\Db\Adapter\Mysql
|
||||
*/
|
||||
public function commitTransparentTransaction()
|
||||
{
|
||||
$this->_levelAdjustment -= 1;
|
||||
return $this->commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* See \Magento\TestFramework\Db\Adapter\TransactionInterface
|
||||
*
|
||||
* @return \Magento\TestFramework\Db\Adapter\Mysql
|
||||
*/
|
||||
public function rollbackTransparentTransaction()
|
||||
{
|
||||
$this->_levelAdjustment -= 1;
|
||||
return $this->rollback();
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* DB adapter transaction interface that allows starting transaction with adjusted level,
|
||||
* transparently to the application
|
||||
*/
|
||||
namespace Magento\TestFramework\Db\Adapter;
|
||||
|
||||
interface TransactionInterface
|
||||
{
|
||||
/**
|
||||
* Increment "transparent" transaction counter and start real transaction
|
||||
*
|
||||
* @return \Magento\Framework\DB\Adapter\Pdo\Mysql
|
||||
*/
|
||||
public function beginTransparentTransaction();
|
||||
|
||||
/**
|
||||
* Decrement "transparent" transaction counter and commit real transaction
|
||||
*
|
||||
* @return \Magento\Framework\DB\Adapter\Pdo\Mysql
|
||||
*/
|
||||
public function commitTransparentTransaction();
|
||||
|
||||
/**
|
||||
* Decrement "transparent" transaction counter and rollback real transaction
|
||||
*
|
||||
* @return \Magento\Framework\DB\Adapter\Pdo\Mysql
|
||||
*/
|
||||
public function rollbackTransparentTransaction();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestFramework\Db;
|
||||
|
||||
/**
|
||||
* Test framework custom connection adapter
|
||||
*/
|
||||
class ConnectionAdapter extends \Magento\Framework\Model\ResourceModel\Type\Db\Pdo\Mysql
|
||||
{
|
||||
/**
|
||||
* Retrieve DB connection class name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDbConnectionClassName()
|
||||
{
|
||||
return \Magento\TestFramework\Db\Adapter\Mysql::class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* MySQL platform database handler
|
||||
*/
|
||||
namespace Magento\TestFramework\Db;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
|
||||
class Mysql extends \Magento\TestFramework\Db\AbstractDb
|
||||
{
|
||||
/**
|
||||
* Mysql default Port.
|
||||
*/
|
||||
const DEFAULT_PORT = 3306;
|
||||
|
||||
/**
|
||||
* Name of configuration file.
|
||||
*/
|
||||
const DEFAULTS_EXTRA_FILE_NAME = 'defaults_extra.cnf';
|
||||
|
||||
/**
|
||||
* MySQL DB dump file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_dbDumpFile;
|
||||
|
||||
/**
|
||||
* A file that contains credentials to database, to obscure them from logs
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_defaultsExtraFile;
|
||||
|
||||
/**
|
||||
* Port number for connection
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_port;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isMysqldumpVersion8;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isUsingAuroraDb;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param string $host
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $schema
|
||||
* @param string $varPath
|
||||
* @param \Magento\Framework\Shell $shell
|
||||
*/
|
||||
public function __construct($host, $user, $password, $schema, $varPath, \Magento\Framework\Shell $shell)
|
||||
{
|
||||
parent::__construct($host, $user, $password, $schema, $varPath, $shell);
|
||||
$this->_port = self::DEFAULT_PORT;
|
||||
if (strpos($this->_host, ':') !== false) {
|
||||
list($host, $port) = explode(':', $this->_host);
|
||||
$this->_host = $host;
|
||||
$this->_port = (int) $port;
|
||||
}
|
||||
$this->_dbDumpFile = $this->_varPath . '/setup_dump_' . $this->_schema . '.sql';
|
||||
$this->_defaultsExtraFile = rtrim($this->_varPath, '\\/') . '/' . self::DEFAULTS_EXTRA_FILE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all DB objects
|
||||
*/
|
||||
public function cleanup()
|
||||
{
|
||||
$this->ensureDefaultsExtraFile();
|
||||
$this->_shell->execute(
|
||||
'mysql --defaults-file=%s --host=%s --port=%s %s -e %s',
|
||||
[
|
||||
$this->_defaultsExtraFile,
|
||||
$this->_host,
|
||||
$this->_port,
|
||||
$this->_schema,
|
||||
"DROP DATABASE `{$this->_schema}`; CREATE DATABASE `{$this->_schema}`"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filename for setup db dump
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSetupDbDumpFilename()
|
||||
{
|
||||
return $this->_dbDumpFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is dump exists
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDbDumpExists()
|
||||
{
|
||||
return file_exists($this->getSetupDbDumpFilename());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store setup db dump
|
||||
*/
|
||||
public function storeDbDump()
|
||||
{
|
||||
$this->ensureDefaultsExtraFile();
|
||||
$additionalArguments = [];
|
||||
|
||||
if ($this->isMysqlDumpVersion8()) {
|
||||
$additionalArguments[] = '--column-statistics=0';
|
||||
}
|
||||
|
||||
if ($this->isUsingAuroraDb()) {
|
||||
$additionalArguments[] = '--set-gtid-purged=OFF';
|
||||
}
|
||||
|
||||
$format = sprintf(
|
||||
'%s %s %s %s',
|
||||
'mysqldump --defaults-file=%s --host=%s --port=%s',
|
||||
'--no-tablespaces',
|
||||
implode(' ', $additionalArguments),
|
||||
'%s > %s'
|
||||
);
|
||||
|
||||
$this->_shell->execute(
|
||||
$format,
|
||||
[
|
||||
$this->_defaultsExtraFile,
|
||||
$this->_host,
|
||||
$this->_port,
|
||||
$this->_schema,
|
||||
$this->getSetupDbDumpFilename()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function restoreFromDbDump()
|
||||
{
|
||||
$this->ensureDefaultsExtraFile();
|
||||
if (!$this->isDbDumpExists()) {
|
||||
throw new \LogicException("DB dump file does not exist: " . $this->getSetupDbDumpFilename());
|
||||
}
|
||||
$this->_shell->execute(
|
||||
'mysql --defaults-file=%s --host=%s --port=%s %s < %s',
|
||||
[$this->_defaultsExtraFile, $this->_host, $this->_port, $this->_schema, $this->getSetupDbDumpFilename()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getVendorName()
|
||||
{
|
||||
return 'mysql';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create defaults extra file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function ensureDefaultsExtraFile()
|
||||
{
|
||||
if (!file_exists($this->_defaultsExtraFile)) {
|
||||
$this->assertVarPathWritable();
|
||||
$extraConfig = [
|
||||
'[client]',
|
||||
'user=' . $this->_user,
|
||||
'password="' . $this->_password . '"'
|
||||
];
|
||||
file_put_contents($this->_defaultsExtraFile, implode(PHP_EOL, $extraConfig));
|
||||
chmod($this->_defaultsExtraFile, 0640);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mysql dump is version 8.
|
||||
*
|
||||
* @return bool
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
private function isMysqlDumpVersion8(): bool
|
||||
{
|
||||
if (!$this->isMysqldumpVersion8) {
|
||||
$version = $this->_shell->execute(
|
||||
'mysqldump --version'
|
||||
);
|
||||
|
||||
$this->isMysqldumpVersion8 = (bool) preg_match('/8\.0\./', $version);
|
||||
}
|
||||
|
||||
return $this->isMysqldumpVersion8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the DB connection Aurora RDS?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isUsingAuroraDb(): bool
|
||||
{
|
||||
if (!isset($this->isUsingAuroraDb)) {
|
||||
try {
|
||||
$this->_shell->execute(
|
||||
'mysql --defaults-file=%s --host=%s --port=%s %s --execute="SELECT AURORA_VERSION()"',
|
||||
[
|
||||
$this->_defaultsExtraFile,
|
||||
$this->_host,
|
||||
$this->_port,
|
||||
$this->_schema
|
||||
]
|
||||
);
|
||||
|
||||
$this->isUsingAuroraDb = true;
|
||||
} catch (LocalizedException $e) {
|
||||
$this->isUsingAuroraDb = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->isUsingAuroraDb;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestFramework\Db;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection as AppResource;
|
||||
use Magento\Framework\DB\Ddl\Sequence as DdlSequence;
|
||||
|
||||
/**
|
||||
* Class Sequence
|
||||
*/
|
||||
class Sequence
|
||||
{
|
||||
/**
|
||||
* @var AppResource
|
||||
*/
|
||||
protected $appResource;
|
||||
|
||||
/**
|
||||
* @var DdlSequence
|
||||
*/
|
||||
protected $ddlSequence;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $entities = [
|
||||
'order',
|
||||
'invoice',
|
||||
'shipment',
|
||||
'rma_item'
|
||||
];
|
||||
|
||||
/**
|
||||
* @param AppResource $appResource
|
||||
* @param DdlSequence $ddlSequence
|
||||
*/
|
||||
public function __construct(
|
||||
AppResource $appResource,
|
||||
DdlSequence $ddlSequence
|
||||
) {
|
||||
$this->appResource = $appResource;
|
||||
$this->ddlSequence = $ddlSequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $n
|
||||
* @return void
|
||||
*/
|
||||
public function generateSequences($n = 10)
|
||||
{
|
||||
$connection = $this->appResource->getConnection();
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
foreach ($this->entities as $entityName) {
|
||||
$sequenceName = $this->appResource->getTableName(sprintf('sequence_%s_%s', $entityName, $i));
|
||||
if (!$connection->isTableExists($sequenceName)) {
|
||||
$connection->query($this->ddlSequence->getCreateSequenceDdl($sequenceName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestFramework\Db\Sequence;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
use Magento\Framework\Webapi\Exception;
|
||||
use Magento\SalesSequence\Model\ResourceModel\Meta as ResourceMetadata;
|
||||
use Magento\Framework\App\ResourceConnection as AppResource;
|
||||
use Magento\Framework\DB\Ddl\Sequence as DdlSequence;
|
||||
use Magento\SalesSequence\Model\ProfileFactory;
|
||||
use Magento\SalesSequence\Model\MetaFactory;
|
||||
|
||||
/**
|
||||
* Class Builder
|
||||
*/
|
||||
class Builder extends \Magento\SalesSequence\Model\Builder
|
||||
{
|
||||
/**
|
||||
* @var resourceMetadata
|
||||
*/
|
||||
protected $resourceMetadata;
|
||||
|
||||
/**
|
||||
* @var ProfileFactory
|
||||
*/
|
||||
protected $profileFactory;
|
||||
|
||||
/**
|
||||
* @var MetaFactory
|
||||
*/
|
||||
protected $metaFactory;
|
||||
|
||||
/**
|
||||
* @var AppResource
|
||||
*/
|
||||
protected $appResource;
|
||||
|
||||
/**
|
||||
* @var DdlSequence
|
||||
*/
|
||||
protected $ddlSequence;
|
||||
|
||||
/**
|
||||
* List of required sequence attribute
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $required = [
|
||||
'entityType',
|
||||
'storeId'
|
||||
];
|
||||
|
||||
/**
|
||||
* Default pattern for sequence creation, full list of attributes that can be defined by customer
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $pattern = [
|
||||
'entity_type',
|
||||
'store_id',
|
||||
'prefix',
|
||||
'suffix',
|
||||
'start_value',
|
||||
'step',
|
||||
'max_value',
|
||||
'warning_value',
|
||||
];
|
||||
|
||||
/**
|
||||
* Concrete data of sequence
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data = [];
|
||||
|
||||
/**
|
||||
* @param ResourceMetadata $resourceMetadata
|
||||
* @param MetaFactory $metaFactory
|
||||
* @param ProfileFactory $profileFactory
|
||||
* @param AppResource $appResource
|
||||
* @param DdlSequence $ddlSequence
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceMetadata $resourceMetadata,
|
||||
MetaFactory $metaFactory,
|
||||
ProfileFactory $profileFactory,
|
||||
AppResource $appResource,
|
||||
DdlSequence $ddlSequence
|
||||
) {
|
||||
$this->resourceMetadata = $resourceMetadata;
|
||||
$this->metaFactory = $metaFactory;
|
||||
$this->profileFactory = $profileFactory;
|
||||
$this->appResource = $appResource;
|
||||
$this->ddlSequence = $ddlSequence;
|
||||
$this->data = array_flip($this->pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $entityType
|
||||
* @return $this
|
||||
*/
|
||||
public function setEntityType($entityType)
|
||||
{
|
||||
$this->data['entity_type'] = $entityType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $storeId
|
||||
* @return $this
|
||||
*/
|
||||
public function setStoreId($storeId)
|
||||
{
|
||||
$this->data['store_id'] = $storeId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $prefix
|
||||
* @return $this
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->data['prefix'] = $prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $suffix
|
||||
* @return $this
|
||||
*/
|
||||
public function setSuffix($suffix)
|
||||
{
|
||||
$this->data['suffix'] = $suffix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $startValue
|
||||
* @return $this
|
||||
*/
|
||||
public function setStartValue($startValue)
|
||||
{
|
||||
$this->data['start_value'] = $startValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $step
|
||||
* @return $this
|
||||
*/
|
||||
public function setStep($step)
|
||||
{
|
||||
$this->data['step'] = $step;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $maxValue
|
||||
* @return $this
|
||||
*/
|
||||
public function setMaxValue($maxValue)
|
||||
{
|
||||
$this->data['max_value'] = $maxValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $warningValue
|
||||
* @return $this
|
||||
*/
|
||||
public function setWarningValue($warningValue)
|
||||
{
|
||||
$this->data['warning_value'] = $warningValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate sequence before save
|
||||
*
|
||||
* @throws \Magento\Framework\Exception\AlreadyExistsException
|
||||
* @return void
|
||||
*/
|
||||
protected function validate()
|
||||
{
|
||||
$metadata = $this->resourceMetadata->loadByEntityTypeAndStore(
|
||||
$this->data['entity_type'],
|
||||
$this->data['store_id']
|
||||
);
|
||||
$connection = $this->appResource->getConnection();
|
||||
if ($metadata->getId() && !$connection->isTableExists($this->getSequenceName())) {
|
||||
throw new \Magento\Framework\Exception\AlreadyExistsException(
|
||||
__('Sequence with this metadata already exists')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getSequenceName()
|
||||
{
|
||||
return $this->appResource->getTableName(
|
||||
sprintf(
|
||||
'sequence_%s_%s',
|
||||
$this->data['entity_type'],
|
||||
$this->data['store_id']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create sequence with metadata and profile
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws \Magento\Framework\Exception\AlreadyExistsException
|
||||
* @return void
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$metadata = $this->resourceMetadata->loadByEntityTypeAndStore(
|
||||
$this->data['entity_type'],
|
||||
$this->data['store_id']
|
||||
);
|
||||
if ($metadata->getSequenceTable() == $this->getSequenceName()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->data['sequence_table'] = $this->getSequenceName();
|
||||
$this->data['is_active'] = 1;
|
||||
$profile = $this->profileFactory->create(
|
||||
[
|
||||
'data' => array_intersect_key(
|
||||
$this->data,
|
||||
array_flip(
|
||||
[
|
||||
'prefix', 'suffix', 'start_value', 'step', 'max_value', 'warning_value',
|
||||
'is_active', 'active_profile'
|
||||
]
|
||||
)
|
||||
)
|
||||
]
|
||||
);
|
||||
$profile->setHasDataChanges(true);
|
||||
$this->data['active_profile'] = $profile;
|
||||
$metadata = $this->metaFactory->create(
|
||||
[
|
||||
'data' => array_intersect_key(
|
||||
$this->data,
|
||||
array_flip(['entity_type', 'store_id', 'sequence_table', 'active_profile'])
|
||||
)
|
||||
]
|
||||
);
|
||||
$metadata->setHasDataChanges(true);
|
||||
try {
|
||||
$this->resourceMetadata->save($metadata);
|
||||
} catch (Exception $e) {
|
||||
$this->resourceMetadata->delete($metadata);
|
||||
throw $e;
|
||||
}
|
||||
$this->data = array_flip($this->pattern);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user