{
"event": "PreToolUse",
"tool_name": "Read",
"tool_input": {
"file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Controller\/SemanticExplorerController.php"
}
}
{
"tool_response": {
"type": "text",
"file": {
"filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/UseCases\/Pipeline\/RunPipelineUseCase.php",
"content": "<?php\n\ndeclare(strict_types=1);\n\nnamespace UseCases\\Pipeline;\n\n\/\/ @responsibility: Startet und verwaltet Pipeline-Ausführungen\n\nuse Domain\\Repository\\PipelineRepositoryInterface;\n\nclass RunPipelineUseCase\n{\n private const PYTHON_BIN = '\/var\/www\/scripts\/pipeline\/venv\/bin\/python';\n private const PIPELINE_SCRIPT = '\/var\/www\/scripts\/pipeline\/pipeline.py';\n private const LOG_DIR = '\/tmp';\n\n public function __construct(\n private PipelineRepositoryInterface $repository\n ) {\n }\n\n \/**\n * Start a new pipeline run.\n *\n * @param int $pipelineId Pipeline ID\n * @return array{success: bool, run_id?: int, error?: string}\n *\/\n public function start(int $pipelineId): array\n {\n $pipeline = $this->repository->findById($pipelineId);\n\n if ($pipeline === null) {\n return ['success' => false, 'error' => 'Pipeline nicht gefunden'];\n }\n\n $runId = $this->repository->createRun($pipelineId);\n\n $this->executeInBackground($pipelineId, $runId);\n\n return ['success' => true, 'run_id' => $runId];\n }\n\n \/**\n * Cancel a running pipeline.\n *\n * @param int $pipelineId Pipeline ID\n * @param int $runId Run ID\n * @return array{success: bool, error?: string}\n *\/\n public function cancel(int $pipelineId, int $runId): array\n {\n $run = $this->repository->findRunById($runId);\n\n if ($run === null || (int) $run['pipeline_id'] !== $pipelineId) {\n return ['success' => false, 'error' => 'Run nicht gefunden'];\n }\n\n if ($run['status'] !== 'running') {\n return [\n 'success' => false,\n 'error' => 'Run kann nicht abgebrochen werden (Status: ' . $run['status'] . ')',\n ];\n }\n\n $this->repository->updateRun($runId, [\n 'status' => 'cancelled',\n 'completed_at' => date('Y-m-d H:i:s'),\n ]);\n\n return ['success' => true];\n }\n\n \/**\n * Get simple status for a pipeline (latest run).\n *\n * @param int $pipelineId Pipeline ID\n * @return array{success: bool, error?: string, run?: array}\n *\/\n public function getStatus(int $pipelineId): array\n {\n $pipeline = $this->repository->findById($pipelineId);\n\n if ($pipeline === null) {\n return ['success' => false, 'error' => 'Pipeline nicht gefunden'];\n }\n\n return [\n 'success' => true,\n 'pipeline_id' => $pipelineId,\n 'run' => $this->repository->findLatestRun($pipelineId),\n ];\n }\n\n \/**\n * Execute pipeline script in background.\n *\/\n private function executeInBackground(int $pipelineId, int $runId): void\n {\n $logFile = sprintf('%s\/pipeline_run_%d.log', self::LOG_DIR, $runId);\n\n \/\/ Get DB password from environment or .env file\n $dbPassword = $_ENV['DB_PASSWORD'] ?? $_ENV['MARIADB_ROOT_PASSWORD'] ?? '';\n if ($dbPassword === '' && file_exists('\/var\/www\/dev.campus.systemische-tools.de\/.env')) {\n $envContent = file_get_contents('\/var\/www\/dev.campus.systemische-tools.de\/.env');\n if (preg_match('\/^MARIADB_ROOT_PASSWORD=(.+)$\/m', $envContent, $matches)) {\n $dbPassword = trim($matches[1]);\n }\n }\n\n $cmd = sprintf(\n 'nohup env DB_PASSWORD=%s %s %s all --pipeline-id=%d --run-id=%d > %s 2>&1 &',\n escapeshellarg($dbPassword),\n escapeshellarg(self::PYTHON_BIN),\n escapeshellarg(self::PIPELINE_SCRIPT),\n $pipelineId,\n $runId,\n escapeshellarg($logFile)\n );\n\n exec($cmd);\n }\n}\n",
"numLines": 123,
"startLine": 1,
"totalLines": 123
}
}
}