This repository has been archived on 2026-07-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
LegalAssistance/scripts/AfterInstall.php
T
chaim 15602a976f chore: remove ai-gateway plugin deployment from install scripts
Legal tools (generate_initial_report) are now built into shira-hermes
(mcp_server/tools/legal_tools.py). The AfterInstall no longer needs to
deploy tools.json and prompts.json to ai-gateway's plugins/ directory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 19:47:30 +00:00

117 lines
4.0 KiB
PHP

<?php
/************************************************************************
* LegalAssistance Extension — AfterInstall
*
* 1. Create DocumentTemplate for the direct access report
* 2. Clear cache
*
* Note: ai-gateway plugin deployment removed — legal tools are now
* built into shira-hermes (api/services/legal_tools.py) since Phase 3.
************************************************************************/
use Espo\Core\Container;
use Espo\Core\DataManager;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Log;
class AfterInstall
{
public function run(Container $container): void
{
/** @var EntityManager $entityManager */
$entityManager = $container->getByClass(EntityManager::class);
/** @var Log $log */
$log = $container->getByClass(Log::class);
$log->info('LegalAssistance: Running AfterInstall...');
// 0. Ensure custom i18n directories exist for all supported locales
$config = $container->getByClass(Config::class);
$this->ensureI18nDirectories($config, $log);
// 1. Create DocumentTemplate
$this->createDocumentTemplate($entityManager, $log);
// 2. Clear cache
try {
$dataManager = $container->getByClass(DataManager::class);
$dataManager->clearCache();
$log->info('LegalAssistance: Cache cleared.');
} catch (\Throwable $e) {
$log->warning('LegalAssistance: Cache clear failed: ' . $e->getMessage());
}
$log->info('LegalAssistance: AfterInstall completed.');
}
private function ensureI18nDirectories(Config $config, Log $log): void
{
$basePath = 'custom/Espo/Custom/Resources/i18n';
$language = $config->get('language', 'en_US');
$locales = array_unique(['en_US', 'fa_IR', 'he_IL', $language]);
foreach ($locales as $locale) {
$dir = $basePath . '/' . $locale;
if (!is_dir($dir)) {
if (mkdir($dir, 0775, true)) {
$log->info("LegalAssistance: Created i18n directory: {$dir}");
} else {
$log->warning("LegalAssistance: Failed to create i18n directory: {$dir}");
}
}
}
}
private function createDocumentTemplate(EntityManager $entityManager, Log $log): void
{
// Check if template already exists
$existing = $entityManager
->getRDBRepository('DocumentTemplate')
->where(['name' => 'דוח גישה ישירה'])
->findOne();
if ($existing) {
$log->info('LegalAssistance: DocumentTemplate already exists, skipping.');
return;
}
// Find the template DOCX file
$templateFile = __DIR__ . '/../templates/direct-access-report.docx';
if (!file_exists($templateFile)) {
$log->warning("LegalAssistance: Template file not found at {$templateFile}");
return;
}
// Create attachment for the template file
$contents = file_get_contents($templateFile);
$attachment = $entityManager->getNewEntity('Attachment');
$attachment->set([
'name' => 'direct-access-report.docx',
'type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'role' => 'Attachment',
'size' => strlen($contents),
]);
$entityManager->saveEntity($attachment);
// Write file to storage
$filePath = 'data/upload/' . $attachment->getId();
file_put_contents($filePath, $contents);
// Create DocumentTemplate entity
$template = $entityManager->getNewEntity('DocumentTemplate');
$template->set([
'name' => 'דוח גישה ישירה',
'entityType' => 'Case',
'fileId' => $attachment->getId(),
]);
$entityManager->saveEntity($template);
$log->info("LegalAssistance: DocumentTemplate created: {$template->getId()}");
}
}