create([ 'grant_id' => $grant->id, 'license_article_id' => $article->id, 'article_release_id' => $release->id, 'content_element_version_id' => $version->id, 'action' => $action, 'format' => $format, 'copy_id' => $copyId ?? self::newCopyId(), 'composition_version_id' => $compositionVersionId, 'checksum' => $checksum, 'marking' => $marking, 'delivered_at' => now(), ]); } /** * Schreibt nur dann, wenn zu diesem Anspruch und dieser Fassung innerhalb des Zeitfensters noch kein Nachweis der * Aktion steht. So zählt eine Wiedergabe einmal, auch wenn der Player nur Erneuerungen und Abschnitte abruft; ein * Abruf, der nie die Hauptliste holt, bleibt trotzdem nicht ohne Nachweis. * * @return bool true, wenn geschrieben wurde */ public function writeUnlessRecent( int $windowSeconds, Grant $grant, LicenseArticle $article, ArticleRelease $release, ContentElementVersion $version, string $action, string $format, string $marking, string|\Closure|null $checksum = null, ): bool { $recent = MediaDelivery::query() ->where('grant_id', $grant->id) ->where('content_element_version_id', $version->id) ->where('action', $action) ->where('delivered_at', '>=', now()->subSeconds($windowSeconds)) ->exists(); if ($recent) { return false; } $this->write($grant, $article, $release, $version, $action, $format, $checksum instanceof \Closure ? $checksum() : $checksum, $marking); return true; } public static function newCopyId(): string { return 'LK-'.strtoupper(bin2hex(random_bytes(6))); } }