get('entityManager'); $log = $container->get('log'); $resourceFile = __DIR__ . '/../files/custom/Espo/Modules/SmartAssistant/Resources/data/default-prompts.json'; if (!is_file($resourceFile)) { // Fall back to the module Resources path when the extension is // installed (Resources/ is the canonical location at runtime). $resourceFile = dirname(__DIR__) . '/files/custom/Espo/Modules/SmartAssistant/Resources/data/default-prompts.json'; } if (!is_file($resourceFile)) { // Final fallback: the module's installed Resources path. $resourceFile = 'custom/Espo/Modules/SmartAssistant/Resources/data/default-prompts.json'; } if (!is_file($resourceFile)) { $log->warning("[SmartAssistant] AfterInstall: default-prompts.json not found, skipping seed"); return; } $json = file_get_contents($resourceFile); $defaults = json_decode($json, true); if (!is_array($defaults)) { $log->warning("[SmartAssistant] AfterInstall: default-prompts.json invalid JSON"); return; } $created = 0; $skipped = 0; foreach ($defaults as $row) { $key = $row['key'] ?? null; if (!$key) { continue; } $existing = $entityManager->getRDBRepository('AssistantPrompt') ->where(['key' => $key, 'deleted' => false]) ->findOne(); if ($existing) { $skipped++; continue; } $entity = $entityManager->getNewEntity('AssistantPrompt'); $entity->set([ 'key' => $key, 'name' => $row['name'] ?? $key, 'description' => $row['description'] ?? null, 'mode' => $row['mode'] ?? 'both', 'displayOrder' => $row['displayOrder'] ?? 100, 'content' => $row['content'] ?? '', 'isActive' => true, ]); $entityManager->saveEntity($entity); $created++; } $log->info("[SmartAssistant] AfterInstall: seeded $created AssistantPrompt rows, $skipped already existed"); } }