-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c2de62
commit 2aae5fc
Showing
3 changed files
with
678 additions
and
0 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,66 @@ | ||
<?php | ||
|
||
namespace App\VersionsCleanup; | ||
|
||
use Exception; | ||
use Symbiote\QueuedJobs\Services\AbstractQueuedJob; | ||
use Symbiote\QueuedJobs\Services\QueuedJob; | ||
|
||
/** | ||
* @property array $versions | ||
* @property array $remainingVersions | ||
*/ | ||
class CleanupJob extends AbstractQueuedJob | ||
{ | ||
/** | ||
* @param array $versions | ||
*/ | ||
public function hydrate(array $versions): void | ||
{ | ||
$this->versions = $versions; | ||
} | ||
|
||
public function getTitle(): string | ||
{ | ||
return 'Delete old version records'; | ||
} | ||
|
||
public function getJobType(): int | ||
{ | ||
return QueuedJob::QUEUED; | ||
} | ||
|
||
public function setup(): void | ||
{ | ||
$this->remainingVersions = $this->versions; | ||
$this->totalSteps = count($this->versions); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function process(): void | ||
{ | ||
$remaining = $this->remainingVersions; | ||
|
||
if (count($remaining) > 0) { | ||
$item = array_shift($remaining); | ||
$id = $item['id']; | ||
$class = $item['class']; | ||
$versions = $item['versions']; | ||
|
||
$count = CleanupService::singleton()->deleteVersions($class, $id, $versions); | ||
$this->addMessage(sprintf('Deleted %d version records', $count)); | ||
|
||
// Mark item as processed | ||
$this->currentStep += 1; | ||
$this->remainingVersions = $remaining; | ||
} | ||
|
||
if (count($this->remainingVersions) > 0) { | ||
return; | ||
} | ||
|
||
$this->isComplete = true; | ||
} | ||
} |
Oops, something went wrong.