b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / vendor / magento / framework / EntityManager / Sequence /
Filename/home/dev2.destoffenstraat.com/vendor/magento/framework/EntityManager/Sequence/SequenceManager.php
Size3.34 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified07-Jan-2021 21:08
Last accessed22-Aug-2025 18:23
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\EntityManager\Sequence;

use Psr\Log\LoggerInterface;
use Magento\Framework\EntityManager\MetadataPool;

/**
* Class SequenceManager
*/
class SequenceManager
{
/**
* @var SequenceRegistry
*/
private $sequenceRegistry;

/**
* @var MetadataPool
*/
private $metadataPool;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var \Magento\Framework\App\ResourceConnection
*/
private $appResource;

/**
* @param MetadataPool $metadataPool
* @param SequenceRegistry $sequenceRegistry
* @param LoggerInterface $logger
* @param \Magento\Framework\App\ResourceConnection $appResource
*/
public function __construct(
MetadataPool $metadataPool,
SequenceRegistry $sequenceRegistry,
LoggerInterface $logger,
\Magento\Framework\App\ResourceConnection $appResource
) {
$this->metadataPool = $metadataPool;
$this->sequenceRegistry = $sequenceRegistry;
$this->logger = $logger;
$this->appResource = $appResource;
}

/**
* Forces creation of a sequence value.
*
* @param string $entityType
* @param string|int $identifier
*
* @return int
*
* @throws \Exception
*/
public function force($entityType, $identifier)
{
$sequenceInfo = $this->sequenceRegistry->retrieve($entityType);

if (!isset($sequenceInfo['sequenceTable'])) {
throw new \Exception(
'TODO: use correct Exception class' . PHP_EOL . ' Sequence table doesn\'t exists'
);
}

try {
$metadata = $this->metadataPool->getMetadata($entityType);

$connection = $this->appResource->getConnectionByName(
$metadata->getEntityConnectionName()
);

return $connection->insert(
$this->appResource->getTableName($sequenceInfo['sequenceTable']),
['sequence_value' => $identifier]
);
} catch (\Exception $e) {
$this->logger->critical($e->getMessage(), $e->getTrace());

throw new \Exception('TODO: use correct Exception class' . PHP_EOL . $e->getMessage());
}
}

/**
* @param string $entityType
* @param int $identifier
* @return int
* @throws \Exception
*/
public function delete($entityType, $identifier)
{
$metadata = $this->metadataPool->getMetadata($entityType);
$sequenceInfo = $this->sequenceRegistry->retrieve($entityType);
if (!isset($sequenceInfo['sequenceTable'])) {
throw new \Exception('TODO: use correct Exception class' . PHP_EOL . ' Sequence table doesn\'t exists');
}
try {
$connection = $this->appResource->getConnectionByName($metadata->getEntityConnectionName());
return $connection->delete(
$this->appResource->getTableName($sequenceInfo['sequenceTable']),
['sequence_value = ?' => $identifier]
);
} catch (\Exception $e) {
$this->logger->critical($e->getMessage(), $e->getTrace());
throw new \Exception('TODO: use correct Exception class' . PHP_EOL . $e->getMessage());
}
}
}