Skip to content

Commit 3916c07

Browse files
committed
update
1 parent ad806b6 commit 3916c07

File tree

7 files changed

+195
-3
lines changed

7 files changed

+195
-3
lines changed

web/Modules/Caddy/App/Jobs/CaddyBuild.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ protected function generateCaddyfile(): void
195195
$domainLog = '/var/log/caddy/' . $domain->domain . '.log';
196196
shell_exec("chown caddy:caddy '/var/log/caddy/");
197197
shell_exec("chmod -R 777 /var/log/caddy/");
198-
//
198+
199199
shell_exec("sudo setfacl -R -m u:caddy:rx " . $domain->document_root);
200200
shell_exec("sudo setfacl -R -m u:caddy:rx " . $domain->domain_public);
201201
shell_exec("sudo setfacl -R -m u:caddy:rx " . $domain->home_root);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Modules\Microweber\App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Modules\Microweber\Jobs\RunInstallationCommands;
7+
8+
class RunInstallationCommand extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'microweber:run-command
16+
{command : The artisan/composer command to run}
17+
{--installation-id= : Run for a specific installation ID}';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Run artisan or composer commands for all Microweber installations';
25+
26+
/**
27+
* Execute the console command.
28+
*/
29+
public function handle()
30+
{
31+
$command = $this->argument('command');
32+
$installationId = $this->option('installation-id');
33+
34+
if ($installationId) {
35+
$this->info("Running '{$command}' for installation ID: " . $installationId);
36+
} else {
37+
$this->info("Running '{$command}' for all installations...");
38+
}
39+
40+
$job = new RunInstallationCommands(
41+
$command,
42+
$installationId ? (int)$installationId : null
43+
);
44+
45+
$job->handle();
46+
47+
$this->info('Command executed successfully!');
48+
}
49+
}
50+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Modules\Microweber\App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Modules\Microweber\Jobs\RunInstallationCommands;
7+
8+
class RunVendorAssetsSymlink extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'microweber:run-vendor-assets-symlink {--installation-id= : Run for a specific installation ID}';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Run microweber:vendor-assets-symlink command for all Microweber installations';
23+
24+
/**
25+
* Execute the console command.
26+
*/
27+
public function handle()
28+
{
29+
$installationId = $this->option('installation-id');
30+
31+
if ($installationId) {
32+
$this->info('Running microweber:vendor-assets-symlink for installation ID: ' . $installationId);
33+
} else {
34+
$this->info('Running microweber:vendor-assets-symlink for all installations...');
35+
}
36+
37+
$job = new RunInstallationCommands(
38+
'microweber:vendor-assets-symlink',
39+
$installationId ? (int)$installationId : null
40+
);
41+
42+
$job->handle();
43+
44+
$this->info('Command executed successfully!');
45+
}
46+
}
47+

web/Modules/Microweber/App/Providers/MicroweberServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Illuminate\Support\ServiceProvider;
1010
use Modules\Microweber\App\Console\Commands\DownloadMicroweber;
1111
use Modules\Microweber\App\Console\Commands\ReinstallMicroweberInstallations;
12+
use Modules\Microweber\App\Console\Commands\RunInstallationCommand;
13+
use Modules\Microweber\App\Console\Commands\RunVendorAssetsSymlink;
1214
use Modules\Microweber\Listeners\DomainIsCreatedListener;
1315
use Modules\Microweber\MicroweberApacheVirtualHostConfig;
1416
use Modules\Microweber\MicroweberBackupConfig;
@@ -62,6 +64,8 @@ protected function registerCommands(): void
6264
$this->commands([
6365
ReinstallMicroweberInstallations::class,
6466
DownloadMicroweber::class,
67+
RunVendorAssetsSymlink::class,
68+
RunInstallationCommand::class,
6569
]);
6670
}
6771

web/Modules/Microweber/COMMANDS.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Microweber Console Commands
2+
3+
## Available Commands
4+
5+
### 1. Run Vendor Assets Symlink for All Installations
6+
7+
This command runs `microweber:vendor-assets-symlink` for all Microweber installations on the server.
8+
9+
```bash
10+
php artisan microweber:run-vendor-assets-symlink
11+
```
12+
13+
To run for a specific installation:
14+
```bash
15+
php artisan microweber:run-vendor-assets-symlink --installation-id=123
16+
```
17+
18+
### 2. Run Any Command for All Installations (Generic)
19+
20+
This is a generic command that can run any artisan or composer command for all installations.
21+
22+
```bash
23+
php artisan microweber:run-command "cache:clear"
24+
```
25+
26+
To run for a specific installation:
27+
```bash
28+
php artisan microweber:run-command "cache:clear" --installation-id=123
29+
```
30+
31+
#### Supported Commands:
32+
- `cache:clear` - Clear cache
33+
- `microweber:vendor-assets-symlink` - Create vendor assets symlinks
34+
- `microweber:reload-database` - Reload database
35+
- `composer:dump` - Run composer dump-autoload
36+
- `composer:publish-assets` - Publish composer assets
37+
- Any other artisan command
38+
39+
#### Examples:
40+
```bash
41+
# Clear cache for all installations
42+
php artisan microweber:run-command "cache:clear"
43+
44+
# Create vendor symlinks for all installations
45+
php artisan microweber:run-command "microweber:vendor-assets-symlink"
46+
47+
# Reload database for specific installation
48+
php artisan microweber:run-command "microweber:reload-database" --installation-id=5
49+
50+
# Run composer dump-autoload for all installations
51+
php artisan microweber:run-command "composer:dump"
52+
```
53+
54+
## How It Works
55+
56+
These commands use the `RunInstallationCommands` job which:
57+
1. Fetches all Microweber installations (or a specific one)
58+
2. For each installation, it:
59+
- Finds the associated domain and hosting subscription
60+
- Gets the system username
61+
- Executes the command in the installation path as the correct user
62+
- Logs the results
63+
64+
## Notes
65+
66+
- Commands are executed synchronously (not queued)
67+
- All operations are logged
68+
- Commands run with proper user permissions (sudo -u username)
69+
- Installation paths are validated before execution
70+

web/Modules/Microweber/Jobs/RunInstallationCommands.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ private function runArtisanCommand(string $installationPath, string $command, st
118118

119119
$result = ShellApi::exec($fullCommand);
120120

121+
// chown to the user
122+
123+
$chownCommand = "chown -R {$username}:{$username} {$installationPath}";
124+
\Log::info("Executing chown command: {$chownCommand}");
125+
ShellApi::exec($chownCommand);
126+
127+
128+
$storagePath = $installationPath . '/public/storage';
129+
if (is_dir($storagePath)) {
130+
$chmodCommand = "chmod -R 775 {$storagePath}";
131+
\Log::info("Executing chmod command: {$chmodCommand}");
132+
ShellApi::exec($chmodCommand);
133+
}
134+
$storagePath = $installationPath . '/storage';
135+
136+
if (is_dir($storagePath)) {
137+
$chmodCommand = "chmod -R 775 {$storagePath}";
138+
\Log::info("Executing chmod command: {$chmodCommand}");
139+
ShellApi::exec($chmodCommand);
140+
}
141+
121142
if (is_array($result) and $result['exit_code'] !== 0) {
122143
throw new \Exception('Artisan command failed: ' . $result['output']);
123144
}

web/Modules/Microweber/Listeners/DomainIsChangedListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public function handle(DomainIsChanged $event): void
4646
shell_exec('php ' . $findMicroweberInstallation->installation_path . '/artisan cache:clear');
4747

4848
//fix permissions
49-
shell_exec('chown -R ' . $chown_user . ':' . $chown_user . ' ' . $chown_path);
49+
// shell_exec('chown -R ' . $chown_user . ':' . $chown_user . ' ' . $chown_path);
5050

5151
// chmod
52-
shell_exec('chmod -R 755 ' . $chown_path);
52+
// shell_exec('chmod -R 755 ' . $chown_path);
5353

5454

5555

0 commit comments

Comments
 (0)