pp-planer/app/Jobs/ConvertPowerPointJob.php
Thorsten Bus 57d54ec06b feat: Wave 1 Foundation - Database, OAuth, Sync, Files, Layout, Email (T2-T7)
T2: Database Schema + All Migrations
- 10 migrations: users extension, services, songs, song_groups, song_slides,
  song_arrangements, song_arrangement_groups, service_songs, slides, cts_sync_log
- 9 Eloquent models with relationships and casts
- 9 factory classes for testing
- Tests: DatabaseSchemaTest (2 tests, 26 assertions) 

T3: ChurchTools OAuth Provider
- Custom Socialite provider for ChurchTools OAuth2
- AuthController with redirect/callback/logout
- Replaced Breeze login with OAuth-only (German UI)
- Removed all Breeze register/password-reset pages
- Tests: OAuthTest (9 tests, 54 assertions) 

T4: CTS API Service + Sync Command
- ChurchToolsService wrapping 5pm-HDH/churchtools-api
- SyncChurchToolsCommand (php artisan cts:sync)
- SyncController for refresh button
- CCLI-based song matching
- Tests: ChurchToolsSyncTest (2 tests) 

T5: File Conversion Service
- FileConversionService with letterbox/pillarbox to 1920×1080
- ConvertPowerPointJob (queued) with LibreOffice + spatie/pdf-to-image
- ZIP extraction and recursive processing
- Thumbnail generation (320×180)
- Tests: FileConversionTest (2 tests, 21 assertions) 

T6: Shared Vue Components
- AuthenticatedLayout with nav, user info, refresh button
- useAutoSave composable (500ms debounce)
- FlashMessage, ConfirmDialog, LoadingSpinner components
- HandleInertiaRequests middleware with shared props
- Tests: SharedPropsTest (7 tests) 

T7: Email Configuration
- MissingSongRequest mailable (German)
- Email template with song info and service link
- SONG_REQUEST_EMAIL config
- Tests: MissingSongMailTest (2 tests, 10 assertions) 

All tests passing: 30/30 (233 assertions)
All UI text in German with 'Du' form
Wave 1 complete: 7/7 tasks 
2026-03-01 19:39:26 +01:00

117 lines
3.4 KiB
PHP

<?php
namespace App\Jobs;
use App\Events\PowerPointConversionProgress;
use App\Services\FileConversionService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use RuntimeException;
use Symfony\Component\Process\Process;
class ConvertPowerPointJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
public function __construct(
public string $inputPath,
public string $jobId,
) {
}
public function handle(FileConversionService $conversionService): void
{
event(new PowerPointConversionProgress($this->jobId, 'started'));
$tempDir = storage_path('app/temp/ppt-' . $this->jobId);
if (! is_dir($tempDir) && ! mkdir($tempDir, 0775, true) && ! is_dir($tempDir)) {
throw new RuntimeException('Temporaires Verzeichnis konnte nicht erstellt werden.');
}
$process = new Process([
'soffice',
'--headless',
'--convert-to',
'pdf',
'--outdir',
$tempDir,
$this->inputPath,
]);
$process->setTimeout(300);
$process->run();
if (! $process->isSuccessful()) {
throw new RuntimeException('PowerPoint-Konvertierung fehlgeschlagen: ' . $process->getErrorOutput());
}
$pdfPath = $tempDir . DIRECTORY_SEPARATOR . pathinfo($this->inputPath, PATHINFO_FILENAME) . '.pdf';
if (! is_file($pdfPath)) {
throw new RuntimeException('PDF wurde von LibreOffice nicht erzeugt.');
}
$pdfClass = implode('\\', ['Spatie', 'PdfToImage', 'Pdf']);
$pdf = new $pdfClass($pdfPath);
$pageCount = $pdf->pageCount();
$convertedFiles = [];
for ($page = 1; $page <= $pageCount; $page++) {
$slidePath = $tempDir . DIRECTORY_SEPARATOR . 'slide-' . $page . '.jpg';
$pdf->selectPage($page)->save($slidePath);
$convertedFiles[] = $conversionService->convertImage($slidePath);
event(new PowerPointConversionProgress($this->jobId, 'processing', $page, $pageCount, $convertedFiles));
}
event(new PowerPointConversionProgress($this->jobId, 'finished', $pageCount, $pageCount, $convertedFiles));
$this->cleanup($tempDir);
@unlink($this->inputPath);
}
public function failed(\Throwable $exception): void
{
event(new PowerPointConversionProgress($this->jobId, 'failed'));
Log::error('PowerPoint-Konvertierung fehlgeschlagen', [
'job_id' => $this->jobId,
'input_path' => $this->inputPath,
'error' => $exception->getMessage(),
]);
}
private function cleanup(string $tempDir): void
{
if (! is_dir($tempDir)) {
return;
}
$entries = scandir($tempDir);
if ($entries === false) {
return;
}
foreach ($entries as $entry) {
if ($entry === '.' || $entry === '..') {
continue;
}
$path = $tempDir . DIRECTORY_SEPARATOR . $entry;
if (is_file($path)) {
@unlink($path);
}
}
@rmdir($tempDir);
}
}