| Total Complexity | 6 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 96.3% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class FlushRows implements ShouldQueue |
||
| 12 | { |
||
| 13 | use Dispatchable, Queueable; |
||
| 14 | |||
| 15 | private string $apiKey; |
||
| 16 | |||
| 17 | private string $baseId; |
||
| 18 | |||
| 19 | private string $tableName; |
||
| 20 | |||
| 21 | private bool $debug = false; |
||
| 22 | |||
| 23 | 5 | public function __construct(string $apiKey, string $baseId, string $tableName) |
|
| 24 | { |
||
| 25 | 5 | $this->apiKey = $apiKey; |
|
| 26 | 5 | $this->baseId = $baseId; |
|
| 27 | 5 | $this->tableName = $tableName; |
|
| 28 | 5 | } |
|
| 29 | |||
| 30 | 1 | public function handle(AirTable $airTable) |
|
| 31 | { |
||
| 32 | 1 | $airTable->setApiKey($this->apiKey); |
|
| 33 | 1 | $airTable->setBaseId($this->baseId); |
|
| 34 | 1 | $airTable->setTableName($this->tableName); |
|
| 35 | 1 | $this->log('Retrieving IDs'); |
|
| 36 | 1 | $ids = $airTable->getIdsFromTable(); |
|
| 37 | 1 | $this->log('Retrieved IDs'); |
|
| 38 | 1 | $this->log('Deleting Rows'); |
|
| 39 | 1 | foreach(array_chunk($ids, 50) as $idsToDelete) { |
|
| 40 | 1 | dispatch((new DeleteRows( |
|
| 41 | 1 | $idsToDelete, |
|
| 42 | 1 | $this->apiKey, |
|
| 43 | 1 | $this->baseId, |
|
| 44 | 1 | $this->tableName) |
|
| 45 | 1 | )->withDebug($this->debug)); |
|
| 46 | } |
||
| 47 | 1 | } |
|
| 48 | |||
| 49 | 4 | public function withDebug(bool $debug) |
|
| 53 | } |
||
| 54 | |||
| 55 | 1 | private function log(string $string) |
|
| 61 | } |