Skip to content

Commit e148041

Browse files
committed
Merge branch 'release/v0.0.2'
2 parents 92f2325 + ab5b701 commit e148041

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+871
-478
lines changed

Config/config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"name"=> "Saas",
55
"title"=> "Multi-tenancy SaaS Module",
66
"slug"=> "saas",
7-
"thumbnail"=> "https://placehold.jp/300x160.png",
7+
"thumbnail"=> "https://img.site/p/300/160",
88
"excerpt"=> "Module for multi-tenancy SaaS product development",
99
"description"=> "Module for multi-tenancy SaaS product development",
1010
"download_link"=> "https://github.com/webreinvent/vaahcms-module-saas/archive/master.zip",
1111
"author_name"=> "saas",
1212
"author_website"=> "https://vaah.dev",
13-
"version"=> "0.0.1",
13+
"version"=> "0.0.2",
1414
"is_migratable"=> true,
1515
"is_sample_data_available"=> true,
1616
"db_table_prefix"=> "vh_saas_",

Database/Migrations/2020_11_16_194130_vh_saas_tenants.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public function up()
2020

2121
$table->integer('vh_saas_server_id')->nullable()->index();
2222

23-
24-
25-
2623
$table->string('name')->nullable()->index();
2724
$table->string('slug')->nullable()->index();
2825
$table->string('path')->nullable()->index();
@@ -48,7 +45,7 @@ public function up()
4845
$table->dateTime('activated_at')->nullable();
4946
$table->boolean('is_active')->nullable();
5047
$table->dateTime('is_deactivated_at')->nullable();
51-
$table->string('notes')->nullable();
48+
$table->string('notes',255)->nullable();
5249

5350
$table->text('meta')->nullable();
5451

Database/Migrations/2020_11_19_133232_vh_saas_apps.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function up()
2020
$table->string('app_type')->nullable();
2121
$table->string('name')->nullable();
2222
$table->string('slug')->nullable()->index();
23-
$table->string('excerpt')->nullable();
23+
$table->string('excerpt',255)->nullable();
2424

2525
$table->string('version')->nullable();
2626
$table->integer('version_number')->nullable();
@@ -38,7 +38,7 @@ public function up()
3838
$table->boolean('is_active')->nullable();
3939

4040
$table->dateTime('is_deactivated_at')->nullable();
41-
$table->string('notes')->nullable();
41+
$table->string('notes',255)->nullable();
4242

4343
// COMMON FIELDS
4444
$table->integer('created_by')->nullable();

Database/Migrations/2020_11_19_133353_vh_saas_tenant_apps.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function up()
2828
$table->dateTime('last_migrated_at')->nullable();
2929
$table->dateTime('last_seeded_at')->nullable();
3030

31-
$table->string('notes')->nullable();
31+
$table->string('notes',255)->nullable();
3232
$table->text('meta')->nullable();
3333

3434
// COMMON FIELDS

Entities/App.php

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,48 @@ public static function createItem($request)
191191
return $response;
192192

193193
}
194+
195+
196+
public static function recountRelations()
197+
{
198+
$list = static::withTrashed()->select('id')->get();
199+
200+
if($list)
201+
{
202+
foreach ($list as $item)
203+
{
204+
$item->count_tenants_active = static::countActiveTenants($item->id);
205+
$item->count_tenants = Tenant::all()->count();
206+
$item->save();
207+
}
208+
}
209+
210+
}
211+
212+
213+
//-------------------------------------------------
214+
public static function countActiveTenants($id)
215+
{
216+
217+
$app = static::withTrashed()->where('id', $id)->first();
218+
219+
if(!$app)
220+
{
221+
return 0;
222+
}
223+
224+
return $app->tenants()->wherePivot('is_active', 1)->count();
225+
}
226+
//-------------------------------------------------
194227
//-------------------------------------------------
195228
public static function getList($request)
196229
{
197230

231+
if(isset($request->recount) && $request->recount == true)
232+
{
233+
static::recountRelations();
234+
Tenant::recountRelations();
235+
}
198236

199237
$list = static::orderBy('id', 'desc');
200238

@@ -220,11 +258,16 @@ public static function getList($request)
220258

221259
if(isset($request->q))
222260
{
261+
if(isset($request['search_by']) && $request['search_by'])
262+
{
263+
$list->where($request['search_by'], 'LIKE', '%'.$request->q.'%');
223264

224-
$list->where(function ($q) use ($request){
225-
$q->where('name', 'LIKE', '%'.$request->q.'%')
226-
->orWhere('slug', 'LIKE', '%'.$request->q.'%');
227-
});
265+
}else{
266+
$list->where(function ($q) use ($request){
267+
$q->where('name', 'LIKE', '%'.$request->q.'%')
268+
->orWhere('slug', 'LIKE', '%'.$request->q.'%');
269+
});
270+
}
228271
}
229272

230273

@@ -288,7 +331,7 @@ public static function postStore($request,$id)
288331

289332
$update = static::where('id',$id)->withTrashed()->first();
290333

291-
$update->name = $input['name'];
334+
$update->fill($input);
292335
$update->slug = Str::slug($input['slug']);
293336
$update->save();
294337

@@ -429,11 +472,9 @@ public static function bulkDelete($request)
429472

430473
foreach($request->inputs as $id)
431474
{
432-
$item = static::where('id', $id)->withTrashed()->first();
433-
if($item)
434-
{
435-
$item->forceDelete();
436-
}
475+
476+
$item = static::where('id', $id)->withTrashed()->forceDelete();
477+
437478
}
438479

439480
$response['status'] = 'success';
@@ -452,6 +493,12 @@ public static function validation($inputs)
452493
$rules = array(
453494
'name' => 'required|max:150',
454495
'slug' => 'required|max:150',
496+
'relative_path' => 'required|max:150',
497+
'migration_path' => 'max:150',
498+
'seed_class' => 'max:150',
499+
'sample_data_class' => 'max:150',
500+
'excerpt' => 'max:255',
501+
'notes' => 'max:255',
455502
);
456503

457504
$validator = \Validator::make( $inputs, $rules);

Entities/Server.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,18 @@ public static function getList($request)
233233

234234
if(isset($request->q))
235235
{
236+
if(isset($request['search_by']) && $request['search_by'])
237+
{
238+
$list->where($request['search_by'], 'LIKE', '%'.$request->q.'%');
236239

237-
$list->where(function ($q) use ($request){
238-
$q->where('name', 'LIKE', '%'.$request->q.'%')
239-
->orWhere('slug', 'LIKE', '%'.$request->q.'%');
240-
});
240+
}else{
241+
$list->where(function ($q) use ($request){
242+
$q->where('name', 'LIKE', '%'.$request->q.'%')
243+
->orWhere('slug', 'LIKE', '%'.$request->q.'%');
244+
});
245+
}
241246
}
242247

243-
244248
$data['list'] = $list->paginate(config('vaahcms.per_page'));
245249

246250
$response['status'] = 'success';

Entities/Tenant.php

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class Tenant extends Model {
4040
'path',
4141
'domain',
4242
'sub_domain',
43-
4443
'database_name',
4544
'database_username',
4645
'database_password',
@@ -54,17 +53,20 @@ class Tenant extends Model {
5453
'is_active',
5554
'is_deactivated_at',
5655
'notes',
57-
5856
'meta',
5957
'created_by',
6058
'updated_by',
6159
'deleted_by'
6260
];
6361

62+
//-------------------------------------------------
63+
protected $hidden = [
64+
'database_password',
65+
];
6466
//-------------------------------------------------
6567
protected $appends = [
6668

67-
'db_connection_name'
69+
'db_connection_name',
6870

6971
];
7072
//-------------------------------------------------
@@ -75,7 +77,7 @@ public function setDatabasePasswordAttribute($value)
7577
$this->attributes['database_password'] = Crypt::encrypt($value);
7678
}
7779
}
78-
80+
//-------------------------------------------------
7981
//-------------------------------------------------
8082
public function setMetaAttribute($value)
8183
{
@@ -257,10 +259,47 @@ public static function createItem($request)
257259
return $response;
258260

259261
}
262+
263+
public static function recountRelations()
264+
{
265+
$list = static::withTrashed()->select('id')->get();
266+
267+
if($list)
268+
{
269+
foreach ($list as $item)
270+
{
271+
$item->count_apps_active = static::countActiveApps($item->id);
272+
$item->count_apps = App::all()->count();
273+
$item->save();
274+
}
275+
}
276+
277+
}
278+
279+
280+
//-------------------------------------------------
281+
public static function countActiveApps($id)
282+
{
283+
284+
$tenant = static::withTrashed()->where('id', $id)->first();
285+
286+
if(!$tenant)
287+
{
288+
return 0;
289+
}
290+
291+
return $tenant->apps()->wherePivot('is_active', 1)->count();
292+
}
260293
//-------------------------------------------------
261294
public static function getList($request)
262295
{
263296

297+
if(isset($request->recount) && $request->recount == true)
298+
{
299+
static::recountRelations();
300+
App::recountRelations();
301+
}
302+
264303

265304
if($request['sort_by'])
266305
{
@@ -284,14 +323,18 @@ public static function getList($request)
284323

285324
if(isset($request->q))
286325
{
326+
if(isset($request['search_by']) && $request['search_by'])
327+
{
328+
$list->where($request['search_by'], 'LIKE', '%'.$request->q.'%');
287329

288-
$list->where(function ($q) use ($request){
289-
$q->where('name', 'LIKE', '%'.$request->q.'%')
290-
->orWhere('slug', 'LIKE', '%'.$request->q.'%');
291-
});
330+
}else{
331+
$list->where(function ($q) use ($request){
332+
$q->where('name', 'LIKE', '%'.$request->q.'%')
333+
->orWhere('slug', 'LIKE', '%'.$request->q.'%');
334+
});
335+
}
292336
}
293337

294-
295338
$data['list'] = $list->paginate(config('vaahcms.per_page'));
296339

297340
$response['status'] = 'success';
@@ -514,11 +557,17 @@ public static function validation($inputs)
514557
{
515558

516559
$rules = array(
560+
'vh_saas_server_id' => 'required|max:150',
517561
'name' => 'required|max:150',
518562
'slug' => 'required|max:150',
519-
'vh_saas_server_id' => 'required|max:150',
563+
'path' => 'max:150',
564+
'domain' => 'max:150',
565+
'sub_domain' => 'max:150',
520566
'database_name' => 'required|alpha_dash|max:20',
521567
'database_username' => 'required|alpha_dash|max:20',
568+
'database_charset' => 'max:150',
569+
'database_collation' => 'max:150',
570+
'notes' => 'max:255',
522571
);
523572

524573
$validator = \Validator::make( $inputs, $rules);
@@ -773,7 +822,7 @@ public static function migrate($inputs, $tenant_column_value, $tenant_column_nam
773822

774823
$db_connection_name = $tenant->db_connection_name;
775824

776-
$response = \VaahArtisan::migrate($inputs['command'], $db_connection_name, $inputs['path']);
825+
$response = \VaahArtisan::migrate($inputs['command'], $inputs['path'], $db_connection_name);
777826

778827
return $response;
779828

@@ -834,7 +883,9 @@ public static function seed($inputs, $tenant_column_value, $tenant_column_name='
834883
$inputs['class'] = null;
835884
}
836885

837-
$response = \VaahArtisan::seed($inputs['command'], $db_connection_name, $inputs['class']);
886+
887+
$response = \VaahArtisan::seed($inputs['command'], $inputs['class'], $db_connection_name );
888+
838889

839890
return $response;
840891

Entities/TenantApp.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public static function getList($request)
170170
$list = static::orderBy('id', $request['sort_order']);
171171
}
172172

173-
$list->with(['tenant', 'app']);
173+
$list->with(['tenant', 'app'])->has('tenant')->has('app');
174174

175175
if($request['trashed'] == 'true')
176176
{
@@ -421,6 +421,7 @@ public static function validation($inputs)
421421
$rules = array(
422422
'vh_saas_tenant_id' => 'required|max:150',
423423
'vh_saas_app_id' => 'required|max:150',
424+
'notes' => 'max:255',
424425
);
425426

426427
$validator = \Validator::make( $inputs, $rules);

Http/Controllers/Backend/TenantAppsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function postActions(Request $request, $action)
8888
//------------------------------------
8989
case 'sync-tenant-apps':
9090

91-
$response = TenantApp::syncTenantApps($request);
91+
$response = TenantApp::syncTenantApps();
9292

9393
break;
9494
//------------------------------------

0 commit comments

Comments
 (0)