Skip to content

Commit

Permalink
Update RunRepair.php
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Sep 13, 2024
1 parent 7208590 commit e1091f2
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions web/app/Console/Commands/RunRepair.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
use App\ApacheParser;
use App\Jobs\ApacheBuild;
use App\Models\Backup;
use App\Models\Database;
use App\Models\Domain;
use App\Models\HostingSubscription;
use App\PhyreConfig;
use App\UniversalDatabaseExecutor;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Database\Schema\Blueprint;
Expand Down Expand Up @@ -45,6 +48,8 @@ public function handle()
// }
// }

$this->fixDatabaseRootUsers();

$this->fixPhpMyAdmin();

// Overwrite supervisor config file
Expand Down Expand Up @@ -85,6 +90,48 @@ public function fixPhpMyAdmin()
}
}

public function fixDatabaseRootUsers()
{
$findDatabases = Database::all();
if ($findDatabases->count() > 0) {
foreach ($findDatabases as $database) {
if ($database->is_remote_database_server == 1) {
// TODO
continue;
}

$findHostingSubscription = HostingSubscription::where('id', $database->hosting_subscription_id)->first();
if (!$findHostingSubscription) {
continue;
}

$universalDatabaseExecutor = new UniversalDatabaseExecutor(
PhyreConfig::get('MYSQL_HOST', '127.0.0.1'),
PhyreConfig::get('MYSQL_PORT', 3306),
PhyreConfig::get('MYSQL_ROOT_USERNAME'),
PhyreConfig::get('MYSQL_ROOT_PASSWORD'),
);
$universalDatabaseExecutor->fixPasswordPolicy();

// Check main database user exists
$mainDatabaseUser = $universalDatabaseExecutor->getUserByUsername($findHostingSubscription->system_username);
if (!$mainDatabaseUser) {
$createMainDatabaseUser = $universalDatabaseExecutor->createUser($findHostingSubscription->system_username, $findHostingSubscription->system_password);
if (!isset($createMainDatabaseUser['success'])) {
throw new \Exception($createMainDatabaseUser['message']);
}
}

$databaseName = Str::slug($database->database_name, '_');
$databaseName = $database->database_name_prefix . $databaseName;
$databaseName = strtolower($databaseName);

$universalDatabaseExecutor->userGrantPrivilegesToDatabase($findHostingSubscription->system_username, [$databaseName]);

}
}
}

public function fixApacheErrors()
{
$findHostingSubscriptions = HostingSubscription::get();
Expand Down

0 comments on commit e1091f2

Please sign in to comment.