-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AKM-32: Move data from messages/RMQ to jobs/Database (#63)
- Loading branch information
Showing
18 changed files
with
332 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: PHP Composer | ||
|
||
on: | ||
push: | ||
branches: [ master 4.2 4.1 3.1 1.6 ] | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install dependencies | ||
run: php -r "copy('https://cs.symfony.com/download/php-cs-fixer-v3.phar', 'php-cs-fixer.phar');" | ||
|
||
- name: Run php-cs-fixer | ||
run: php php-cs-fixer.phar fix --dry-run --config=.php_cs.php --cache-file=.php_cs.cache --verbose --show-progress=dots --diff --allow-risky=yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace Oro\Bundle\AkeneoBundle\Command; | ||
|
||
use Oro\Bundle\BatchBundle\ORM\Query\BufferedIdentityQueryResultIterator; | ||
use Oro\Bundle\CronBundle\Command\CronCommandInterface; | ||
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper; | ||
use Oro\Bundle\IntegrationBundle\Entity\FieldsChanges; | ||
use Oro\Bundle\MessageQueueBundle\Entity\Job; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Clears old records from oro_integration_fields_changes table before repack. | ||
*/ | ||
class CleanupCommand extends Command implements CronCommandInterface | ||
{ | ||
/** @var string */ | ||
protected static $defaultName = 'oro:akeneo:cleanup'; | ||
|
||
/** @var DoctrineHelper */ | ||
private $doctrineHelper; | ||
|
||
public function __construct(DoctrineHelper $doctrineHelper) | ||
{ | ||
$this->doctrineHelper = $doctrineHelper; | ||
parent::__construct(); | ||
} | ||
|
||
public function isActive() | ||
{ | ||
return true; | ||
} | ||
|
||
public function getDefaultDefinition() | ||
{ | ||
return '0 2 * * 6'; | ||
} | ||
|
||
public function configure() | ||
{ | ||
$this | ||
->setDescription('Clears old records from oro_integration_fields_changes table.') | ||
->setHelp( | ||
<<<'HELP' | ||
The <info>%command.name%</info> command clears fields changes for complete job records | ||
from <comment>oro_integration_fields_changes</comment> table. | ||
<info>php %command.full_name%</info> | ||
HELP | ||
); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$output->writeln(sprintf( | ||
'<comment>Number of fields changes that has been deleted:</comment> %d', | ||
$this->deleteRecords() | ||
)); | ||
|
||
$output->writeln('<info>Fields changes cleanup complete</info>'); | ||
} | ||
|
||
private function deleteRecords(): int | ||
{ | ||
$qb = $this->doctrineHelper | ||
->getEntityManagerForClass(FieldsChanges::class) | ||
->getRepository(FieldsChanges::class) | ||
->createQueryBuilder('fc'); | ||
|
||
$qb | ||
->delete(FieldsChanges::class, 'fc') | ||
->where($qb->expr()->eq('fc.entityClass', ':class')) | ||
->setParameter('class', Job::class) | ||
->andWhere($qb->expr()->in('fc.entityId', ':ids')); | ||
|
||
$jqb = $this->doctrineHelper | ||
->getEntityManagerForClass(Job::class) | ||
->getRepository(Job::class) | ||
->createQueryBuilder('j'); | ||
|
||
$jqb | ||
->select('j.id') | ||
->where($jqb->expr()->in('j.status', ':statuses')) | ||
->setParameter('statuses', [Job::STATUS_SUCCESS, Job::STATUS_CANCELLED, Job::STATUS_FAILED, Job::STATUS_STALE]) | ||
->orderBy($jqb->expr()->desc('j.id')); | ||
|
||
$iterator = new BufferedIdentityQueryResultIterator($jqb->getQuery()); | ||
|
||
$result = 0; | ||
$iterator->setPageLoadedCallback(function (array $rows) use ($qb, &$result): array { | ||
$ids = array_column($rows, 'id'); | ||
|
||
$result = $result + $qb->setParameter('ids', $ids)->getQuery()->execute(); | ||
|
||
return $ids; | ||
}); | ||
|
||
iterator_to_array($iterator); | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.