|
@@ -2,10 +2,75 @@
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
-use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
+use App\ShellApi;
|
|
|
+use Sushi\Sushi;
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
class HostingDatabase extends Model
|
|
|
{
|
|
|
- use HasFactory;
|
|
|
+ use Sushi;
|
|
|
+
|
|
|
+ protected $fillable = [
|
|
|
+ 'database_name',
|
|
|
+ 'database_username',
|
|
|
+ 'database_password'
|
|
|
+ ];
|
|
|
+
|
|
|
+ protected $schema = [
|
|
|
+ 'database_name' => 'string',
|
|
|
+ 'database_username' => 'string',
|
|
|
+ 'database_password' => 'string'
|
|
|
+ ];
|
|
|
+
|
|
|
+ public static function boot()
|
|
|
+ {
|
|
|
+ parent::boot();
|
|
|
+
|
|
|
+ static::creating(function ($model) {
|
|
|
+
|
|
|
+ $createDbAndUser = ShellApi::callBin('mysql-create-db-and-user', [
|
|
|
+ $model->database_name,
|
|
|
+ $model->database_username,
|
|
|
+ $model->database_password
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (empty($createDbAndUser)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ static::deleting(function ($model) {
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function sushiShouldCache()
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getRows()
|
|
|
+ {
|
|
|
+// $websitesList = ShellApi::callBin('nginx-websites-list');
|
|
|
+//
|
|
|
+// $rows = [];
|
|
|
+// if (!empty($websitesList)) {
|
|
|
+// $websitesList = json_decode($websitesList, true);
|
|
|
+// if (!empty($websitesList)) {
|
|
|
+// foreach ($websitesList as $website) {
|
|
|
+// if (isset($website['file'])) {
|
|
|
+// $rows[] = [
|
|
|
+// 'file' => $website['file'],
|
|
|
+// 'domain' => $website['server_name'],
|
|
|
+// 'root' => $website['root']
|
|
|
+// ];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
}
|