song_id !== null) { return false; } $song = null; if ($serviceSong->cts_ccli_id !== null && $serviceSong->cts_ccli_id !== '') { $song = Song::where('ccli_id', $serviceSong->cts_ccli_id)->first(); } if ($song === null && $serviceSong->cts_song_id) { $song = Song::where('cts_song_id', $serviceSong->cts_song_id)->first(); } if ($song === null) { return false; } $serviceSong->update([ 'song_id' => $song->id, 'matched_at' => Carbon::now(), 'use_translation' => $song->has_translation, ]); return true; } /** * Manually assign a song to a service song. * Overwrites any existing assignment. */ public function manualAssign(ServiceSong $serviceSong, Song $song): void { $serviceSong->update([ 'song_id' => $song->id, 'matched_at' => Carbon::now(), 'use_translation' => $song->has_translation, ]); } /** * Send a missing song request email and record the timestamp. */ public function requestCreation(ServiceSong $serviceSong): void { $service = $serviceSong->service; $recipientEmail = (string) Config::get('services.song_request.email', 'songs@example.com'); Mail::to($recipientEmail)->send(new MissingSongRequest( songName: $serviceSong->cts_song_name, ccliId: $serviceSong->cts_ccli_id, service: $service, )); $serviceSong->update([ 'request_sent_at' => Carbon::now(), ]); } /** * Remove song assignment from a service song. */ public function unassign(ServiceSong $serviceSong): void { $serviceSong->update([ 'song_id' => null, 'matched_at' => null, ]); } }