BaseMigration.php
1 year ago
BatchMigration.php
1 year ago
Migration.php
1 year ago
ReversibleMigration.php
1 year ago
BatchMigration.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\Migrations\Contracts; |
| 4 | |
| 5 | /** |
| 6 | * Extend this class when you need database migration to run in batches. |
| 7 | * |
| 8 | * @since 4.0.0 |
| 9 | */ |
| 10 | abstract class BatchMigration extends BaseMigration |
| 11 | { |
| 12 | /** |
| 13 | * Get the number of items per batch |
| 14 | * |
| 15 | * @since 4.0.0 |
| 16 | */ |
| 17 | abstract public function getBatchSize(): int; |
| 18 | |
| 19 | /** |
| 20 | * |
| 21 | * Get the total items count |
| 22 | * |
| 23 | * @since 4.0.0 |
| 24 | */ |
| 25 | abstract public function getItemsCount(): int; |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * Get the first and the last item ID for a batch |
| 31 | * |
| 32 | * @since 4.0.0 |
| 33 | * |
| 34 | * @return array{0: int, 1: int} the first value is the first id and the second value is the last id of a batch |
| 35 | */ |
| 36 | abstract public function getBatchItemsAfter($lastId): ?array; |
| 37 | |
| 38 | /** |
| 39 | * Run batch |
| 40 | * |
| 41 | * @param $firstId - first item ID in batch |
| 42 | * @param $lastId - last item ID in batch |
| 43 | * |
| 44 | * @since 4.0.0 |
| 45 | */ |
| 46 | abstract public function runBatch($firstId, $lastId); |
| 47 | |
| 48 | /** |
| 49 | * Last step of the migration process |
| 50 | * |
| 51 | * The purpose of this method is to check if we have new items that came during the migration. |
| 52 | * |
| 53 | * @since 4.0.0 |
| 54 | * |
| 55 | * @param $lastProcessedId |
| 56 | * |
| 57 | * @return bool - true if there are new items, otherwise false |
| 58 | */ |
| 59 | abstract public function hasMoreItemsToBatch($lastProcessedId): ?bool; |
| 60 | } |
| 61 |