feat: LegalAssistance extension v1.0.0 — Direct Access Report
- DirectAccessReport entity (48 fields, status lifecycle, Case relationship) - Case fields: cLegalAidType, cAppointmentDate, cAidType, cUrgencyLevel, cFilingDeadline - Auto-tasks hook: creates 3 tasks when case set to Direct Access - DOCX template with 72 placeholders (converted from original form) - Shira plugin: generate_initial_report tool with structured conversation flow - AfterInstall/AfterUninstall scripts for plugin deployment - Hebrew + English translations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* LegalAssistance Extension — AfterInstall
|
||||
*
|
||||
* 1. Deploy plugin files to ai-gateway plugins/ directory
|
||||
* 2. Create DocumentTemplate for the direct access report
|
||||
* 3. Clear cache
|
||||
************************************************************************/
|
||||
|
||||
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...');
|
||||
|
||||
// 1. Deploy ai-gateway plugin files
|
||||
$this->deployPluginFiles($log);
|
||||
|
||||
// 2. Create DocumentTemplate
|
||||
$this->createDocumentTemplate($entityManager, $log);
|
||||
|
||||
// 3. 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 deployPluginFiles(Log $log): void
|
||||
{
|
||||
// Source: extension's plugins/ directory (relative to EspoCRM root after install)
|
||||
$sourceDir = 'custom/Espo/Modules/LegalAssistance/../../../../../../plugins/legal-assistance';
|
||||
|
||||
// Try common ai-gateway locations
|
||||
$gatewayPaths = [
|
||||
'/home/chaim/ai-gateway/plugins/legal-assistance',
|
||||
'/opt/ai-gateway/plugins/legal-assistance',
|
||||
];
|
||||
|
||||
// Find actual source files within the extension package
|
||||
$extPluginDir = __DIR__ . '/../plugins/legal-assistance';
|
||||
|
||||
if (!is_dir($extPluginDir)) {
|
||||
$log->warning("LegalAssistance: Plugin source directory not found at {$extPluginDir}");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($gatewayPaths as $targetDir) {
|
||||
$parentDir = dirname($targetDir);
|
||||
if (!is_dir($parentDir)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_dir($targetDir)) {
|
||||
mkdir($targetDir, 0755, true);
|
||||
}
|
||||
|
||||
$files = ['tools.json', 'prompts.json'];
|
||||
foreach ($files as $file) {
|
||||
$src = $extPluginDir . '/' . $file;
|
||||
$dst = $targetDir . '/' . $file;
|
||||
if (file_exists($src)) {
|
||||
copy($src, $dst);
|
||||
$log->info("LegalAssistance: Deployed {$file} to {$targetDir}");
|
||||
}
|
||||
}
|
||||
|
||||
$log->info("LegalAssistance: Plugin files deployed to {$targetDir}");
|
||||
return;
|
||||
}
|
||||
|
||||
$log->warning('LegalAssistance: Could not find ai-gateway plugins directory. Deploy manually.');
|
||||
}
|
||||
|
||||
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()}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* LegalAssistance Extension — AfterUninstall
|
||||
*
|
||||
* 1. Remove plugin files from ai-gateway
|
||||
* 2. Clear cache
|
||||
************************************************************************/
|
||||
|
||||
use Espo\Core\Container;
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Utils\Log;
|
||||
|
||||
class AfterUninstall
|
||||
{
|
||||
public function run(Container $container): void
|
||||
{
|
||||
/** @var Log $log */
|
||||
$log = $container->getByClass(Log::class);
|
||||
|
||||
$log->info('LegalAssistance: Running AfterUninstall...');
|
||||
|
||||
// Remove ai-gateway plugin files
|
||||
$gatewayPaths = [
|
||||
'/home/chaim/ai-gateway/plugins/legal-assistance',
|
||||
'/opt/ai-gateway/plugins/legal-assistance',
|
||||
];
|
||||
|
||||
foreach ($gatewayPaths as $dir) {
|
||||
if (is_dir($dir)) {
|
||||
$files = glob($dir . '/*');
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
rmdir($dir);
|
||||
$log->info("LegalAssistance: Removed plugin files from {$dir}");
|
||||
}
|
||||
}
|
||||
|
||||
// Clear cache
|
||||
try {
|
||||
$dataManager = $container->getByClass(DataManager::class);
|
||||
$dataManager->clearCache();
|
||||
} catch (\Throwable $e) {
|
||||
$log->warning('LegalAssistance: Cache clear failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$log->info('LegalAssistance: AfterUninstall completed.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user