repository = $repository; $this->connection = $connection; $this->daemonBackupRepository = $daemonBackupRepository; } /** * Sets the files to be ignored by this backup. * * @param string[]|null $ignored * @return $this */ public function setIgnoredFiles(?array $ignored) { if (is_array($ignored)) { foreach ($ignored as $value) { Assert::string($value); } } // Set the ignored files to be any values that are not empty in the array. Don't use // the PHP empty function here incase anything that is "empty" by default (0, false, etc.) // were passed as a file or folder name. $this->ignoredFiles = is_null($ignored) ? [] : array_filter($ignored, function ($value) { return strlen($value) > 0; }); return $this; } /** * Initiates the backup process for a server on the daemon. * * @param \Pterodactyl\Models\Server $server * @param string|null $name * @return \Pterodactyl\Models\Backup * * @throws \Throwable */ public function handle(Server $server, string $name = null): Backup { return $this->connection->transaction(function () use ($server, $name) { /** @var \Pterodactyl\Models\Backup $backup */ $backup = $this->repository->create([ 'server_id' => $server->id, 'uuid' => Uuid::uuid4()->toString(), 'name' => trim($name) ?: sprintf('Backup at %s', CarbonImmutable::now()->toDateTimeString()), 'ignored_files' => is_array($this->ignoredFiles) ? array_values($this->ignoredFiles) : [], 'disk' => 'local', ], true, true); $this->daemonBackupRepository->setServer($server)->backup($backup); return $backup; }); } }