Path: blob/1.0-develop/app/Services/Activity/ActivityLogBatchService.php
10264 views
<?php12namespace Pterodactyl\Services\Activity;34use Ramsey\Uuid\Uuid;56class ActivityLogBatchService7{8protected int $transaction = 0;9protected ?string $uuid = null;1011/**12* Returns the UUID of the batch, or null if there is not a batch currently13* being executed.14*/15public function uuid(): ?string16{17return $this->uuid;18}1920/**21* Starts a new batch transaction. If there is already a transaction present22* this will be nested.23*/24public function start(): void25{26if ($this->transaction === 0) {27$this->uuid = Uuid::uuid4()->toString();28}2930++$this->transaction;31}3233/**34* Ends a batch transaction, if this is the last transaction in the stack35* the UUID will be cleared out.36*/37public function end(): void38{39$this->transaction = max(0, $this->transaction - 1);4041if ($this->transaction === 0) {42$this->uuid = null;43}44}4546/**47* Executes the logic provided within the callback in the scope of an activity48* log batch transaction.49*/50public function transaction(\Closure $callback): mixed51{52$this->start();53$result = $callback($this->uuid());54$this->end();5556return $result;57}58}596061