@@ -249,6 +249,9 @@ export class MauticDeployer {
249249 // Clear cache after installation
250250 await this . clearCache ( 'after installation' ) ;
251251
252+ // Fix media .htaccess files if they have incorrect configuration
253+ await this . fixMediaHtaccess ( ) ;
254+
252255 // Install themes and plugins if specified
253256 if ( this . config . mauticThemes || this . config . mauticPlugins ) {
254257 Logger . log ( '=== STARTING THEMES AND PLUGINS INSTALLATION ===' , '🎯' ) ;
@@ -975,21 +978,39 @@ echo "=== EXTRACTION PROCESS COMPLETE ==="`;
975978 }
976979 }
977980
981+ // Clear cache first to ensure autoloading works
982+ Logger . log ( `🧹 Clearing cache before plugin registration...` , '🧹' ) ;
983+ const preCacheResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'cd /var/www/html && rm -rf var/cache/prod/* var/cache/dev/*'` , { ignoreError : true } ) ;
984+
985+ if ( ! preCacheResult . success ) {
986+ Logger . log ( `⚠️ Warning: Pre-cache clear failed: ${ preCacheResult . output } ` , '⚠️' ) ;
987+ } else {
988+ Logger . log ( `✅ Pre-cache cleared successfully` , '✅' ) ;
989+ }
990+
978991 // Run Mautic plugin installation command
979992 Logger . log ( `🔧 Running Mautic plugin installation command...` , '🔧' ) ;
980- const consoleResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'cd /var/www/html && php bin/console mautic:plugins:install'` , { ignoreError : true } ) ;
993+ const consoleResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'cd /var/www/html && php bin/console mautic:plugins:install --force '` , { ignoreError : true } ) ;
981994
982995 if ( ! consoleResult . success ) {
983996 Logger . log ( `⚠️ Warning: Plugin console command failed: ${ consoleResult . output } ` , '⚠️' ) ;
984- // Don't throw error as plugin files are installed, console command might just need cache clear
997+ // Try alternative approach: just reload plugins
998+ Logger . log ( `🔄 Trying alternative plugin reload...` , '🔄' ) ;
999+ const reloadResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'cd /var/www/html && php bin/console mautic:plugins:reload'` , { ignoreError : true } ) ;
1000+ if ( reloadResult . success ) {
1001+ Logger . log ( `✅ Plugin reload successful` , '✅' ) ;
1002+ Logger . log ( reloadResult . output , '📄' ) ;
1003+ } else {
1004+ Logger . log ( `⚠️ Plugin reload also failed: ${ reloadResult . output } ` , '⚠️' ) ;
1005+ }
9851006 } else {
9861007 Logger . log ( `✅ Plugin registered with Mautic successfully` , '✅' ) ;
9871008 Logger . log ( consoleResult . output , '📄' ) ;
9881009 }
9891010
9901011 // Clear cache after plugin installation
9911012 Logger . log ( `🧹 Clearing cache after plugin installation...` , '🧹' ) ;
992- const cacheResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'cd /var/www/html && rm -rf var/cache/prod/*'` , { ignoreError : true } ) ;
1013+ const cacheResult = await ProcessManager . runShell ( `docker exec mautic_web bash -c 'cd /var/www/html && rm -rf var/cache/prod/* var/cache/dev/* '` , { ignoreError : true } ) ;
9931014
9941015 if ( ! cacheResult . success ) {
9951016 Logger . log ( `⚠️ Warning: Cache clear failed: ${ cacheResult . output } ` , '⚠️' ) ;
@@ -1088,6 +1109,80 @@ echo "=== EXTRACTION PROCESS COMPLETE ==="`;
10881109 }
10891110 }
10901111
1112+ /**
1113+ * Fix .htaccess files in media directories to use official Mautic configuration
1114+ */
1115+ private async fixMediaHtaccess ( ) : Promise < void > {
1116+ Logger . log ( '� Checking and fixing media .htaccess files...' , '�' ) ;
1117+
1118+ try {
1119+ // Use the official Mautic 6.x .htaccess for media directories
1120+ const officialMediaHtaccess = `<IfModule mod_authz_core.c>
1121+ Require all granted
1122+ </IfModule>
1123+ <IfModule !mod_authz_core.c>
1124+ Order allow,deny
1125+ Allow from all
1126+ </IfModule>` ;
1127+
1128+ // Check if images .htaccess needs fixing
1129+ const checkImagesHtaccess = await ProcessManager . runShell (
1130+ `docker exec mautic_web bash -c 'cat /var/www/html/docroot/media/images/.htaccess 2>/dev/null'` ,
1131+ { ignoreError : true }
1132+ ) ;
1133+
1134+ if ( checkImagesHtaccess . success && checkImagesHtaccess . output . includes ( 'deny from all' ) ) {
1135+ Logger . log ( `⚠️ Found incorrect .htaccess in images directory, fixing...` , '⚠️' ) ;
1136+
1137+ const fixImagesResult = await ProcessManager . runShell (
1138+ `docker exec mautic_web bash -c 'cat > /var/www/html/docroot/media/images/.htaccess << "EOF"
1139+ ${ officialMediaHtaccess }
1140+ EOF'` ,
1141+ { ignoreError : true }
1142+ ) ;
1143+
1144+ if ( fixImagesResult . success ) {
1145+ Logger . log ( `✅ Fixed .htaccess for images directory` , '✅' ) ;
1146+ } else {
1147+ Logger . log ( `⚠️ Warning: Could not fix images .htaccess: ${ fixImagesResult . output } ` , '⚠️' ) ;
1148+ }
1149+ } else {
1150+ Logger . log ( `✅ Images .htaccess appears to be correct` , '✅' ) ;
1151+ }
1152+
1153+ // Check if files .htaccess needs fixing
1154+ const checkFilesHtaccess = await ProcessManager . runShell (
1155+ `docker exec mautic_web bash -c 'cat /var/www/html/docroot/media/files/.htaccess 2>/dev/null'` ,
1156+ { ignoreError : true }
1157+ ) ;
1158+
1159+ if ( checkFilesHtaccess . success && checkFilesHtaccess . output . includes ( 'deny from all' ) ) {
1160+ Logger . log ( `⚠️ Found incorrect .htaccess in files directory, fixing...` , '⚠️' ) ;
1161+
1162+ const fixFilesResult = await ProcessManager . runShell (
1163+ `docker exec mautic_web bash -c 'cat > /var/www/html/docroot/media/files/.htaccess << "EOF"
1164+ ${ officialMediaHtaccess }
1165+ EOF'` ,
1166+ { ignoreError : true }
1167+ ) ;
1168+
1169+ if ( fixFilesResult . success ) {
1170+ Logger . log ( `✅ Fixed .htaccess for files directory` , '✅' ) ;
1171+ } else {
1172+ Logger . log ( `⚠️ Warning: Could not fix files .htaccess: ${ fixFilesResult . output } ` , '⚠️' ) ;
1173+ }
1174+ } else {
1175+ Logger . log ( `✅ Files .htaccess appears to be correct` , '✅' ) ;
1176+ }
1177+
1178+ Logger . success ( '✅ Media .htaccess check completed' ) ;
1179+ } catch ( error ) {
1180+ const errorMessage = error instanceof Error ? error . message : 'Unknown error' ;
1181+ Logger . error ( `⚠️ Media .htaccess check failed: ${ errorMessage } ` ) ;
1182+ // Don't throw error as this is not critical for basic functionality
1183+ }
1184+ }
1185+
10911186 /**
10921187 * Clear Mautic cache using simple file removal
10931188 */
0 commit comments