Download the PHP package ang3/doctrine-orm-batch-process without Composer
On this page you can find all versions of the php package ang3/doctrine-orm-batch-process. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ang3/doctrine-orm-batch-process
More information about ang3/doctrine-orm-batch-process
Files in ang3/doctrine-orm-batch-process
Package doctrine-orm-batch-process
Short Description Doctrine ORM Batch component
License MIT
Homepage https://github.com/Ang3/doctrine-orm-batch-process
Informations about the package doctrine-orm-batch-process
Doctrine ORM Batch Component
This component helps you to deal with batch-processing in the context of Doctrine ORM transactions.
The main problem with bulk operations is usually not to run out of memory and this is especially what the strategies presented here provide help with. -- Doctrine ORM documentation
The batch process component allows you to build bulk operations very easily with some advanced features.
Installation
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Usage
A batch process is a basic loop using an iterator to do some logic with a handler. The iterator is mandatory and the handler is optional.
In all cases, the entity manager is flushed and cleared when the buffer size is reached (by default: 20).
Create a process
To create a process, use the constructor with the entity manager and an iterator, or use one of defined static shortcut methods as to your needs:
To execute the process:
Advanced options
This component provides some useful advanced options.
Handlers
A handler is a class implementing the interface . This class is called on each iteration. It allows you to persist/remove entities, or whatever you need with custom handlers.
This interface describes the method called by the batch process: .
The component provides some useful built-in handlers.
Persist entity handler
This handler persists entities into database.
Callable arguments:
- The entity
- The iteration.
Remove entity handler
This handler removes entities into database.
Callable arguments:
- The entity
- The iteration.
Callable handler
This handler holds a simple callable.
Callable arguments:
- Iterator data
- The iteration.
Chain handler
This handler allows you to chain handlers in a specific order.
Custom handler
Create a class implementing the interface .
Use the trait to enable options:
Buffer size
You can modify the default buffer size:
Disable ID generators
You can turn off the ID generator for one or more entities, useful to migrate data.
You can restore some disabled ID generators like below:
Transactional entities
The entity manager could be cleared many times. That's why during the process, all entities loaded before the execution will be detached from the manager.
To avoid reloading your entities, this component helps you to keep your entities in memory (by variable reference) in order to reload it automatically.
On flush
You can pass a callable to the batch to execute some logic on each flush/clear operations.
Callable arguments:
- The current batch
- The iteration (NULL in case of last flush/clear).