Compare commits
140 commits
Author | SHA1 | Date | |
---|---|---|---|
5e6f56552d | |||
6e7d100d51 | |||
3741781455 | |||
019bdcc9c7 | |||
fb9263ec68 | |||
cdded1c1e2 | |||
f9629557e4 | |||
69a860109e | |||
59229d8f3b | |||
7c8f8ff75a | |||
![]() |
81c93c2b06 | ||
![]() |
dba037df7f | ||
![]() |
1360b1b7bd | ||
![]() |
e9ff06a553 | ||
a4cddb619d | |||
![]() |
5d7f705828 | ||
c4621db5a7 | |||
b1e639af57 | |||
55898c3f8f | |||
b0980124e0 | |||
c74da756a6 | |||
968904e448 | |||
8492f2f926 | |||
ba62e2bc33 | |||
ab6ef4ba48 | |||
![]() |
e839d216ad | ||
![]() |
8396fa0db7 | ||
![]() |
b0dd57f693 | ||
![]() |
24016dd060 | ||
![]() |
9263cf0596 | ||
![]() |
586d603650 | ||
![]() |
f324e8c0ca | ||
![]() |
3fc0ddce1f | ||
![]() |
a34f5eb20b | ||
![]() |
03672e05c5 | ||
![]() |
d46c2ca7ff | ||
![]() |
71748c0d75 | ||
![]() |
19b58b9c26 | ||
![]() |
ced940247c | ||
![]() |
722111191f | ||
![]() |
2b15d25ebe | ||
![]() |
aab466ac17 | ||
![]() |
4164640182 | ||
![]() |
8da32c3969 | ||
![]() |
7767091426 | ||
![]() |
fcebb74344 | ||
![]() |
83839a1582 | ||
![]() |
d5f8b671d5 | ||
![]() |
258a754788 | ||
![]() |
24135e0982 | ||
![]() |
103d6fc007 | ||
13d517645a | |||
891da480a9 | |||
273789e187 | |||
d97849a4e2 | |||
75528b78b2 | |||
c9ce9a90fd | |||
8d2c150141 | |||
7c60f2f55e | |||
e8b75b33dd | |||
c180a50731 | |||
![]() |
3ee24e5381 | ||
![]() |
39a98c4814 | ||
![]() |
583b1f9d48 | ||
![]() |
3fcffcd1f3 | ||
![]() |
cabf69c595 | ||
![]() |
2e10a9450f | ||
![]() |
9b7f051307 | ||
![]() |
028429ae2f | ||
![]() |
7fbca6d65c | ||
![]() |
a0b5b74b36 | ||
![]() |
7e33de3131 | ||
![]() |
72d86162c8 | ||
![]() |
2b4ad3b09b | ||
![]() |
97245832bf | ||
![]() |
410ce5de97 | ||
![]() |
a409a00a3a | ||
![]() |
d501426770 | ||
![]() |
be1efbf3b9 | ||
![]() |
672528f45a | ||
![]() |
b81bb5bc3d | ||
![]() |
44ee3cde99 | ||
a94cb0d5f6 | |||
cc1e159614 | |||
![]() |
2856fa764b | ||
![]() |
da9d014c9d | ||
![]() |
8fa1e1089e | ||
![]() |
5465b39332 | ||
![]() |
1124d3626e | ||
![]() |
029d599577 | ||
![]() |
27b3bd9af1 | ||
![]() |
026a3d786a | ||
653badb31b | |||
4e05e51d4f | |||
![]() |
4ecdd6272c | ||
![]() |
33ec7a241c | ||
6a851fac61 | |||
![]() |
cda0def335 | ||
![]() |
71cf52d80e | ||
![]() |
dae7f83338 | ||
![]() |
bb8d35a132 | ||
![]() |
464380e18d | ||
![]() |
f3be919a57 | ||
![]() |
9da615e46c | ||
![]() |
33a2f4e880 | ||
![]() |
aa0508f9d0 | ||
![]() |
f4c36abc69 | ||
![]() |
777920d40f | ||
![]() |
b84620b6c3 | ||
![]() |
8364b273cf | ||
![]() |
73cabc5672 | ||
![]() |
44c984e2fa | ||
![]() |
0c912176bf | ||
![]() |
37d3856a3b | ||
![]() |
9b92e22589 | ||
236ec46342 | |||
d3e099213d | |||
f6bda77f1a | |||
cb05f74da3 | |||
fdaec4aaae | |||
09c8e421fa | |||
52f5040270 | |||
488e500c4d | |||
![]() |
91e1bfe2c9 | ||
![]() |
0210ffdfce | ||
![]() |
522a69acf6 | ||
![]() |
6eba57318f | ||
![]() |
04c35f67b4 | ||
![]() |
cd4d374b88 | ||
![]() |
218310a2da | ||
![]() |
9cca268fc8 | ||
![]() |
d479b8e1e5 | ||
![]() |
9c89d3875f | ||
![]() |
b6e578b00a | ||
![]() |
dd75433255 | ||
![]() |
ef4397156b | ||
![]() |
dd46b8f170 | ||
![]() |
af54938da3 | ||
![]() |
ce6b422093 | ||
9ae559ce99 |
21 changed files with 625 additions and 271 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
.svn
|
8
.woodpecker/code-style.yml
Normal file
8
.woodpecker/code-style.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
pipeline:
|
||||
code-style:
|
||||
image: composer
|
||||
commands:
|
||||
- composer global config repositories.repo-name vcs https://git.digital-competence.de/Packages/php-codesniffer
|
||||
- composer global config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
|
||||
- composer global require digicomp/php-codesniffer:@dev
|
||||
- composer global exec -- phpcs --runtime-set ignore_warnings_on_exit 1 --standard=DigiComp Classes/ Tests/
|
32
.woodpecker/functional-tests.yml
Normal file
32
.woodpecker/functional-tests.yml
Normal file
|
@ -0,0 +1,32 @@
|
|||
workspace:
|
||||
base: /woodpecker
|
||||
path: package
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- FLOW_VERSION: 6.3
|
||||
PHP_VERSION: 7.4
|
||||
- FLOW_VERSION: 7.3
|
||||
PHP_VERSION: 7.4
|
||||
- FLOW_VERSION: 7.3
|
||||
PHP_VERSION: 8.2
|
||||
- FLOW_VERSION: 8.2
|
||||
PHP_VERSION: 8.2
|
||||
|
||||
pipeline:
|
||||
functional-tests:
|
||||
image: "thecodingmachine/php:${PHP_VERSION}-v4-cli"
|
||||
environment:
|
||||
# Enable the PDO_SQLITE extension
|
||||
- "PHP_EXTENSION_PDO_SQLITE=1"
|
||||
- "FLOW_VERSION=${FLOW_VERSION}"
|
||||
- "NEOS_BUILD_DIR=/woodpecker/Build-${FLOW_VERSION}"
|
||||
commands:
|
||||
- "sudo mkdir $NEOS_BUILD_DIR"
|
||||
- "sudo chown -R docker:docker $NEOS_BUILD_DIR"
|
||||
- "cd $NEOS_BUILD_DIR"
|
||||
- "composer create-project --no-install neos/flow-base-distribution:^$FLOW_VERSION ."
|
||||
- "composer config repositories.repo-name path /woodpecker/package"
|
||||
- "composer remove --dev --no-update neos/behat || composer remove --no-update neos/behat"
|
||||
- "composer require digicomp/sequence:@dev"
|
||||
- "bin/phpunit --configuration Build/BuildEssentials/PhpUnit/FunctionalTests.xml Packages/Application/DigiComp.Sequence/Tests/Functional"
|
|
@ -1,3 +0,0 @@
|
|||
new in 1.0:
|
||||
|
||||
- taken from DigiComp.Controls
|
82
Classes/Command/SequenceCommandController.php
Normal file
82
Classes/Command/SequenceCommandController.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DigiComp\Sequence\Command;
|
||||
|
||||
use DigiComp\Sequence\Domain\Model\SequenceEntry;
|
||||
use DigiComp\Sequence\Service\Exception\InvalidSourceException;
|
||||
use DigiComp\Sequence\Service\SequenceGenerator;
|
||||
use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException;
|
||||
use Doctrine\DBAL\Exception as DoctrineDBALException;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Neos\Flow\Annotations as Flow;
|
||||
use Neos\Flow\Cli\CommandController;
|
||||
|
||||
/**
|
||||
* @Flow\Scope("singleton")
|
||||
*/
|
||||
class SequenceCommandController extends CommandController
|
||||
{
|
||||
/**
|
||||
* @Flow\Inject
|
||||
* @var SequenceGenerator
|
||||
*/
|
||||
protected $sequenceGenerator;
|
||||
|
||||
/**
|
||||
* @Flow\Inject
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* Set last number for sequence generator.
|
||||
*
|
||||
* @param string $type
|
||||
* @param int $number
|
||||
* @throws DoctrineDBALDriverException
|
||||
* @throws DoctrineDBALException
|
||||
* @throws InvalidSourceException
|
||||
*/
|
||||
public function setLastNumberForCommand(string $type, int $number): void
|
||||
{
|
||||
if ($this->sequenceGenerator->setLastNumberFor($type, $number)) {
|
||||
$this->outputLine('Last number successfully set.');
|
||||
} else {
|
||||
$this->outputLine('Failed to set last number.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up sequence table.
|
||||
*
|
||||
* @param string[] $types
|
||||
* @throws DoctrineDBALDriverException
|
||||
* @throws DoctrineDBALException
|
||||
* @throws InvalidSourceException
|
||||
*/
|
||||
public function cleanUpCommand(array $types = []): void
|
||||
{
|
||||
if ($types === []) {
|
||||
foreach (
|
||||
$this
|
||||
->entityManager
|
||||
->createQuery('SELECT DISTINCT(se.type) type FROM ' . SequenceEntry::class . ' se')
|
||||
->execute()
|
||||
as $result
|
||||
) {
|
||||
$types[] = $result['type'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($types as $type) {
|
||||
$rowCount = $this
|
||||
->entityManager
|
||||
->createQuery('DELETE FROM ' . SequenceEntry::class . ' se WHERE se.type = ?0 AND se.number < ?1')
|
||||
->execute([$type, $this->sequenceGenerator->getLastNumberFor($type)]);
|
||||
|
||||
$this->outputLine('Deleted ' . $rowCount . ' row(s) for type "' . $type . '".');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
namespace DigiComp\Sequence\Command;
|
||||
|
||||
/* *
|
||||
* This script belongs to the FLOW3 package "DigiComp.Sequence". *
|
||||
* *
|
||||
* */
|
||||
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use TYPO3\Flow\Annotations as Flow;
|
||||
|
||||
/**
|
||||
* A SequenceNumber generator (should be DB-agnostic)
|
||||
*
|
||||
* @Flow\Scope("singleton")
|
||||
*/
|
||||
class SequenceCommandController extends \TYPO3\Flow\Cli\CommandController {
|
||||
|
||||
/**
|
||||
* @var \DigiComp\Sequence\Service\SequenceGenerator
|
||||
* @Flow\Inject
|
||||
*/
|
||||
protected $sequenceGenerator;
|
||||
|
||||
/**
|
||||
* Sets minimum number for sequence generator
|
||||
*
|
||||
* @param int $to
|
||||
* @param string $type
|
||||
*/
|
||||
public function advanceCommand($to, $type) {
|
||||
$this->sequenceGenerator->advanceTo($to, $type);
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
<?php
|
||||
namespace DigiComp\Sequence\Domain\Model;
|
||||
|
||||
/* *
|
||||
* This script belongs to the FLOW3 package "DigiComp.Sequence". *
|
||||
* *
|
||||
* */
|
||||
|
||||
use TYPO3\Flow\Annotations as Flow;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
/**
|
||||
* SequenceInsert
|
||||
*
|
||||
* @author fcool
|
||||
* @Flow\Scope("prototype")
|
||||
* @Flow\Entity
|
||||
*/
|
||||
class Insert {
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @Flow\Identity
|
||||
*/
|
||||
protected $number;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Id
|
||||
* @Flow\Identity
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @param int $number
|
||||
* @param string $type
|
||||
*/
|
||||
public function __construct($number, $type) {
|
||||
$this->setType($type);
|
||||
$this->setNumber($number);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $number
|
||||
*/
|
||||
public function setNumber($number) {
|
||||
$this->number = $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getNumber() {
|
||||
return $this->number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|object $type
|
||||
*/
|
||||
public function setType($type) {
|
||||
if (is_object($type)) {
|
||||
$type = get_class($type);
|
||||
}
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType() {
|
||||
return $this->type;
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
namespace DigiComp\Sequence\Service;
|
||||
|
||||
/* *
|
||||
* This script belongs to the FLOW3 package "DigiComp.Sequence". *
|
||||
* *
|
||||
* */
|
||||
|
||||
use TYPO3\Flow\Annotations as Flow;
|
||||
/**
|
||||
* SequenceException
|
||||
*/
|
||||
class Exception extends \Exception {
|
||||
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
namespace DigiComp\Sequence\Service;
|
||||
|
||||
/* *
|
||||
* This script belongs to the FLOW3 package "DigiComp.Sequence". *
|
||||
* *
|
||||
* */
|
||||
|
||||
use Doctrine\DBAL\DBALException;
|
||||
use TYPO3\Flow\Annotations as Flow;
|
||||
|
||||
/**
|
||||
* A SequenceNumber generator (should be DB-agnostic)
|
||||
*
|
||||
*
|
||||
* Thoughts: We could make the step-range configurable, and if > 1 we could return new keys immediately for this request,
|
||||
* as we "reserved" the space between.
|
||||
*
|
||||
* @Flow\Scope("singleton")
|
||||
*/
|
||||
class SequenceGenerator {
|
||||
|
||||
/**
|
||||
* @var \Doctrine\Common\Persistence\ObjectManager
|
||||
* @Flow\Inject
|
||||
*/
|
||||
protected $_em;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\Flow\Reflection\ReflectionService
|
||||
* @Flow\Inject
|
||||
*/
|
||||
protected $reflectionService;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\Flow\Log\SystemLoggerInterface
|
||||
* @Flow\Inject
|
||||
*/
|
||||
protected $systemLogger;
|
||||
|
||||
/**
|
||||
* @param string|object $type
|
||||
* @throws \DigiComp\Sequence\Service\Exception
|
||||
* @return int
|
||||
*/
|
||||
public function getNextNumberFor($type) {
|
||||
if (is_object($type)) {
|
||||
$type = $this->reflectionService->getClassNameByObject($type);
|
||||
}
|
||||
if (!$type) {
|
||||
throw new Exception('No Type given');
|
||||
}
|
||||
$count = $this->getLastNumberFor($type);
|
||||
|
||||
//TODO: Check for maximal tries, or similar
|
||||
do {
|
||||
$count = $count+1;
|
||||
} while (! $this->validateFreeNumber($count, $type));
|
||||
return $count;
|
||||
}
|
||||
|
||||
protected function validateFreeNumber($count, $type) {
|
||||
$em = $this->_em;
|
||||
/** @var $em \Doctrine\ORM\EntityManager */
|
||||
try {
|
||||
$em->getConnection()->insert('digicomp_sequence_domain_model_insert', array('number' => $count, 'type' => $type));
|
||||
return true;
|
||||
} catch (\PDOException $e) {
|
||||
return false;
|
||||
} catch (DBALException $e) {
|
||||
if ($e->getPrevious() && $e->getPrevious() instanceof \PDOException) {
|
||||
// Do nothing, new Doctrine handling hides the above error
|
||||
} else {
|
||||
$this->systemLogger->logException($e);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->systemLogger->logException($e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function advanceTo($to, $type) {
|
||||
return ($this->validateFreeNumber($to, $type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @return int
|
||||
*/
|
||||
public function getLastNumberFor($type) {
|
||||
/** @var $em \Doctrine\ORM\EntityManager */
|
||||
$em = $this->_em;
|
||||
|
||||
$result = $em->getConnection()->executeQuery('SELECT MAX(number) AS count FROM digicomp_sequence_domain_model_insert WHERE type=:type', array('type' => $type));
|
||||
$count = $result->fetchAll();
|
||||
$count = $count[0]['count'];
|
||||
return $count;
|
||||
}
|
||||
|
||||
}
|
28
Classes/Domain/Model/SequenceEntry.php
Normal file
28
Classes/Domain/Model/SequenceEntry.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DigiComp\Sequence\Domain\Model;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Neos\Flow\Annotations as Flow;
|
||||
|
||||
/**
|
||||
* This class is only here to set up the table. We never create an instance of this class.
|
||||
*
|
||||
* @Flow\Entity
|
||||
*/
|
||||
class SequenceEntry
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @var string
|
||||
*/
|
||||
protected string $type;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @var int
|
||||
*/
|
||||
protected int $number;
|
||||
}
|
11
Classes/Exception.php
Normal file
11
Classes/Exception.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DigiComp\Sequence;
|
||||
|
||||
use Neos\Flow\Exception as NeosFlowException;
|
||||
|
||||
class Exception extends NeosFlowException
|
||||
{
|
||||
}
|
11
Classes/Service/Exception/InvalidSourceException.php
Normal file
11
Classes/Service/Exception/InvalidSourceException.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DigiComp\Sequence\Service\Exception;
|
||||
|
||||
use DigiComp\Sequence\Exception;
|
||||
|
||||
class InvalidSourceException extends Exception
|
||||
{
|
||||
}
|
137
Classes/Service/SequenceGenerator.php
Normal file
137
Classes/Service/SequenceGenerator.php
Normal file
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DigiComp\Sequence\Service;
|
||||
|
||||
use DigiComp\Sequence\Domain\Model\SequenceEntry;
|
||||
use DigiComp\Sequence\Service\Exception\InvalidSourceException;
|
||||
use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException;
|
||||
use Doctrine\DBAL\Exception as DoctrineDBALException;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Neos\Flow\Annotations as Flow;
|
||||
use Neos\Utility\TypeHandling;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* A sequence number generator working for transactional databases.
|
||||
*
|
||||
* Thoughts: We could make the step-range configurable, and if > 1 we could return new keys immediately for this
|
||||
* request, as we "reserved" the space between.
|
||||
*
|
||||
* @Flow\Scope("singleton")
|
||||
*/
|
||||
class SequenceGenerator
|
||||
{
|
||||
/**
|
||||
* @Flow\Inject
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* @Flow\Inject
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @param string|object $source
|
||||
* @return int
|
||||
* @throws DoctrineDBALDriverException
|
||||
* @throws DoctrineDBALException
|
||||
* @throws InvalidSourceException
|
||||
*/
|
||||
public function getNextNumberFor($source): int
|
||||
{
|
||||
$type = $this->inferTypeFromSource($source);
|
||||
$number = $this->getLastNumberFor($type);
|
||||
|
||||
// TODO: Check for maximal tries, or similar?
|
||||
// TODO: Let increment be configurable per type?
|
||||
do {
|
||||
$number++;
|
||||
} while (!$this->insertFor($type, $number));
|
||||
|
||||
return $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param int $number
|
||||
* @return bool
|
||||
*/
|
||||
protected function insertFor(string $type, int $number): bool
|
||||
{
|
||||
try {
|
||||
$this->entityManager->getConnection()->insert(
|
||||
$this->entityManager->getClassMetadata(SequenceEntry::class)->getTableName(),
|
||||
['type' => $type, 'number' => $number]
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (\PDOException $exception) {
|
||||
} catch (DoctrineDBALException $exception) {
|
||||
if (!$exception->getPrevious() instanceof \PDOException) {
|
||||
$this->logger->critical('Exception occurred: ' . $exception->getMessage());
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
$this->logger->critical('Exception occurred: ' . $exception->getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|object $source
|
||||
* @param int $number
|
||||
* @return bool
|
||||
* @throws DoctrineDBALDriverException
|
||||
* @throws DoctrineDBALException
|
||||
* @throws InvalidSourceException
|
||||
*/
|
||||
public function setLastNumberFor($source, int $number): bool
|
||||
{
|
||||
$type = $this->inferTypeFromSource($source);
|
||||
|
||||
if ($this->getLastNumberFor($type) >= $number) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->insertFor($type, $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|object $source
|
||||
* @throws DoctrineDBALDriverException
|
||||
* @throws DoctrineDBALException
|
||||
* @throws InvalidSourceException
|
||||
*/
|
||||
public function getLastNumberFor($source): int
|
||||
{
|
||||
return (int)$this->entityManager->getConnection()->executeQuery(
|
||||
'SELECT MAX(number) FROM '
|
||||
. $this->entityManager->getClassMetadata(SequenceEntry::class)->getTableName()
|
||||
. ' WHERE type = :type',
|
||||
['type' => $this->inferTypeFromSource($source)]
|
||||
)->fetchOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|object $source
|
||||
* @return string
|
||||
* @throws InvalidSourceException
|
||||
*/
|
||||
protected function inferTypeFromSource($source): string
|
||||
{
|
||||
if (\is_string($source)) {
|
||||
return $source;
|
||||
}
|
||||
|
||||
if (\is_object($source)) {
|
||||
return TypeHandling::getTypeForValue($source);
|
||||
}
|
||||
|
||||
throw new InvalidSourceException('Could not infer type from source.', 1632216173);
|
||||
}
|
||||
}
|
6
Configuration/Testing/Settings.yaml
Normal file
6
Configuration/Testing/Settings.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
Neos:
|
||||
Flow:
|
||||
persistence:
|
||||
backendOptions:
|
||||
driver: "pdo_sqlite"
|
||||
path: "%FLOW_PATH_DATA%Temporary/testing.db"
|
19
License.txt
Normal file
19
License.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2016 Ferdinand Kuhl <f.kuhl@digital-competence.de>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -1,33 +1,37 @@
|
|||
<?php
|
||||
namespace TYPO3\Flow\Persistence\Doctrine\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration,
|
||||
Doctrine\DBAL\Schema\Schema;
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your need!
|
||||
*/
|
||||
class Version20140505093853 extends AbstractMigration {
|
||||
namespace Neos\Flow\Persistence\Doctrine\Migrations;
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @return void
|
||||
*/
|
||||
public function up(Schema $schema) {
|
||||
// this up() migration is autogenerated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
|
||||
|
||||
$this->addSql("CREATE TABLE digicomp_sequence_domain_model_insert (number INT NOT NULL, type VARCHAR(255) NOT NULL, PRIMARY KEY(number, type)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
|
||||
}
|
||||
use Doctrine\DBAL\Exception as DoctrineDBALException;
|
||||
use Doctrine\DBAL\Migrations\AbortMigrationException;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @return void
|
||||
*/
|
||||
public function down(Schema $schema) {
|
||||
// this down() migration is autogenerated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
|
||||
|
||||
$this->addSql("DROP TABLE digicomp_sequence_domain_model_insert");
|
||||
}
|
||||
}
|
||||
class Version20140505093853 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @throws AbortMigrationException
|
||||
* @throws DoctrineDBALException
|
||||
*/
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on "mysql".');
|
||||
|
||||
$this->addSql('CREATE TABLE digicomp_sequence_domain_model_insert (number INT NOT NULL, type VARCHAR(255) NOT NULL, PRIMARY KEY(number, type))');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @throws AbortMigrationException
|
||||
* @throws DoctrineDBALException
|
||||
*/
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on "mysql".');
|
||||
|
||||
$this->addSql('DROP TABLE digicomp_sequence_domain_model_insert');
|
||||
}
|
||||
}
|
||||
|
|
37
Migrations/Mysql/Version20160624203903.php
Normal file
37
Migrations/Mysql/Version20160624203903.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Neos\Flow\Persistence\Doctrine\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Exception as DoctrineDBALException;
|
||||
use Doctrine\DBAL\Migrations\AbortMigrationException;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
class Version20160624203903 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @throws AbortMigrationException
|
||||
* @throws DoctrineDBALException
|
||||
*/
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on "mysql".');
|
||||
|
||||
$this->addSql('CREATE INDEX type_idx ON digicomp_sequence_domain_model_insert (type)');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @throws AbortMigrationException
|
||||
* @throws DoctrineDBALException
|
||||
*/
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on "mysql".');
|
||||
|
||||
$this->addSql('DROP INDEX type_idx ON digicomp_sequence_domain_model_insert');
|
||||
}
|
||||
}
|
41
Migrations/Mysql/Version20210922110814.php
Normal file
41
Migrations/Mysql/Version20210922110814.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Neos\Flow\Persistence\Doctrine\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Exception as DoctrineDBALException;
|
||||
use Doctrine\DBAL\Migrations\AbortMigrationException;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
class Version20210922110814 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @throws AbortMigrationException
|
||||
* @throws DoctrineDBALException
|
||||
*/
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on "mysql".');
|
||||
|
||||
$this->addSql('CREATE TABLE digicomp_sequence_domain_model_sequenceentry (type VARCHAR(255) NOT NULL, number INT NOT NULL, PRIMARY KEY(type, number))');
|
||||
$this->addSql('INSERT INTO digicomp_sequence_domain_model_sequenceentry (type, number) SELECT i.type, MAX(i.number) FROM digicomp_sequence_domain_model_insert AS i GROUP BY i.type');
|
||||
$this->addSql('DROP TABLE digicomp_sequence_domain_model_insert');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
* @throws AbortMigrationException
|
||||
* @throws DoctrineDBALException
|
||||
*/
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on "mysql".');
|
||||
|
||||
$this->addSql('CREATE TABLE digicomp_sequence_domain_model_insert (number INT NOT NULL, type VARCHAR(255) NOT NULL, INDEX type_idx (type), PRIMARY KEY(number, type))');
|
||||
$this->addSql('INSERT INTO digicomp_sequence_domain_model_insert (number, type) SELECT MAX(se.number), se.type FROM digicomp_sequence_domain_model_sequenceentry AS se GROUP BY se.type');
|
||||
$this->addSql('DROP TABLE digicomp_sequence_domain_model_sequenceentry');
|
||||
}
|
||||
}
|
23
README.md
Normal file
23
README.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# DigiComp.Sequence
|
||||
|
||||

|
||||
|
||||
This is a very simple tool, helping in generation of gapless sequences. For this task it relies on key integrity of the
|
||||
database of your choice.
|
||||
|
||||
Usage is quite simple also:
|
||||
|
||||
```php
|
||||
/**
|
||||
* @param SequenceGenerator $sequenceGenerator
|
||||
*/
|
||||
public function __construct(SequenceGenerator $sequenceNumberGenerator)
|
||||
{
|
||||
$this->orderId = $sequenceGenerator->getNextNumberFor($this);
|
||||
}
|
||||
```
|
||||
|
||||
`getNextNumberFor` allows you to give an object (which will be resolved to its FQCN) or a custom sequence name.
|
||||
|
||||
The `SequenceCommandController` helps you to set the last sequence number, in case of migrations or similar. See
|
||||
`./flow help sequence:setlastnumberfor` if interested.
|
69
Tests/Functional/SequenceTest.php
Normal file
69
Tests/Functional/SequenceTest.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DigiComp\Sequence\Tests\Functional;
|
||||
|
||||
use DigiComp\Sequence\Service\Exception\InvalidSourceException;
|
||||
use DigiComp\Sequence\Service\SequenceGenerator;
|
||||
use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException;
|
||||
use Doctrine\DBAL\Exception as DoctrineDBALException;
|
||||
use Neos\Flow\Tests\FunctionalTestCase;
|
||||
|
||||
class SequenceTest extends FunctionalTestCase
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected static $testablePersistenceEnabled = true;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws DoctrineDBALDriverException
|
||||
* @throws DoctrineDBALException
|
||||
* @throws InvalidSourceException
|
||||
*/
|
||||
public function sequenceTest(): void
|
||||
{
|
||||
$sequenceGenerator = $this->objectManager->get(SequenceGenerator::class);
|
||||
|
||||
self::assertEquals(0, $sequenceGenerator->getLastNumberFor($sequenceGenerator));
|
||||
self::assertEquals(1, $sequenceGenerator->getNextNumberFor($sequenceGenerator));
|
||||
|
||||
$pIds = [];
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$pId = \pcntl_fork();
|
||||
if ($pId > 0) {
|
||||
$pIds[] = $pId;
|
||||
} else {
|
||||
for ($j = 0; $j < 10; $j++) {
|
||||
$sequenceGenerator->getNextNumberFor($sequenceGenerator);
|
||||
}
|
||||
// making a hard exit to avoid phpunit having the tables cleaned up again
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($pIds as $pId) {
|
||||
$status = 0;
|
||||
\pcntl_waitpid($pId, $status);
|
||||
}
|
||||
|
||||
self::assertEquals(101, $sequenceGenerator->getLastNumberFor($sequenceGenerator));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws DoctrineDBALDriverException
|
||||
* @throws DoctrineDBALException
|
||||
* @throws InvalidSourceException
|
||||
*/
|
||||
public function setLastNumberForTest(): void
|
||||
{
|
||||
$sequenceGenerator = $this->objectManager->get(SequenceGenerator::class);
|
||||
$sequenceGenerator->setLastNumberFor($sequenceGenerator, 100);
|
||||
|
||||
self::assertEquals(100, $sequenceGenerator->getLastNumberFor($sequenceGenerator));
|
||||
self::assertEquals(0, $sequenceGenerator->getLastNumberFor('otherSequence'));
|
||||
}
|
||||
}
|
106
composer.json
106
composer.json
|
@ -1,21 +1,93 @@
|
|||
{
|
||||
"name":"digicomp/sequence",
|
||||
"type":"typo3-flow-package",
|
||||
"description":"",
|
||||
"require":{
|
||||
"typo3/flow":"~2.0"
|
||||
},
|
||||
"require-dev":{
|
||||
"phpunit/phpunit": "3.7.*"
|
||||
},
|
||||
"autoload":{
|
||||
"psr-0":{
|
||||
"DigiComp\\Sequence":"Classes"
|
||||
}
|
||||
},
|
||||
"name": "digicomp/sequence",
|
||||
"description": "Sequence is a very simple database agnostic but database based sequence generator",
|
||||
"type": "neos-package",
|
||||
"keywords": [
|
||||
"Neos",
|
||||
"Flow",
|
||||
"doctrine",
|
||||
"sequence"
|
||||
],
|
||||
"homepage": "https://github.com/digital-competence/DigiComp.Sequence",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ferdinand Kuhl",
|
||||
"email": "f.kuhl@digital-competence.de",
|
||||
"homepage": "https://www.digital-competence.de",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.4.0",
|
||||
"ext-pdo": "*",
|
||||
"neos/flow": "^6.3.5 || ^7.0 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-pcntl": "*",
|
||||
"mikey179/vfsstream": "^1.6.1",
|
||||
"neos/buildessentials": "^7.0.0",
|
||||
"phpunit/phpunit": "~8.5",
|
||||
"vimeo/psalm": "~4.22.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"DigiComp\\Sequence\\": "Classes/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"DigiComp\\Sequence\\Tests\\": "Tests/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true,
|
||||
"platform-check": true
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
"dev-develop": "4.0.x-dev",
|
||||
"dev-version/2.x-dev": "2.1.x-dev",
|
||||
"dev-version/1.x-dev": "1.1.x-dev"
|
||||
},
|
||||
"neos": {
|
||||
"package-key": "DigiComp.Sequence"
|
||||
},
|
||||
"applied-flow-migrations": [
|
||||
"Inwebs.Basket-201409170938",
|
||||
"TYPO3.FLOW3-201201261636",
|
||||
"TYPO3.Fluid-201205031303",
|
||||
"TYPO3.FLOW3-201205292145",
|
||||
"TYPO3.FLOW3-201206271128",
|
||||
"TYPO3.FLOW3-201209201112",
|
||||
"TYPO3.Flow-201209251426",
|
||||
"TYPO3.Flow-201211151101",
|
||||
"TYPO3.Flow-201212051340",
|
||||
"TYPO3.Flow-201310031523",
|
||||
"TYPO3.Flow-201405111147",
|
||||
"TYPO3.Fluid-20141113120800",
|
||||
"TYPO3.Flow-20141113121400",
|
||||
"TYPO3.Fluid-20141121091700",
|
||||
"TYPO3.Fluid-20150214130800",
|
||||
"TYPO3.Flow-20151113161300",
|
||||
"TYPO3.Flow-20161115140400",
|
||||
"TYPO3.Flow-20161115140430",
|
||||
"Neos.Flow-20161124204700",
|
||||
"Neos.Flow-20161124204701",
|
||||
"Neos.Flow-20161124224015",
|
||||
"Neos.Eel-20161124230101",
|
||||
"Neos.Imagine-20161124231742",
|
||||
"Neos.Media-20161124233100",
|
||||
"Neos.Flow-20161125124112",
|
||||
"Neos.SwiftMailer-20161130105617",
|
||||
"TYPO3.FluidAdaptor-20161130112935",
|
||||
"Neos.Media-20161219094126",
|
||||
"Neos.Flow-20170125103800",
|
||||
"Neos.Flow-20170127183102",
|
||||
"DigiComp.SettingValidator-20170603120900",
|
||||
"Neos.Flow-20180415105700",
|
||||
"Neos.Flow-20190425144900",
|
||||
"Neos.Flow-20190515215000"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue