Skip to content

Commit 0053835

Browse files
committed
feat: improve upgrade-version, implement detachPermissions functions
1 parent a0eae25 commit 0053835

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

src/Commands/UpgradeVersions.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,58 @@
22

33
namespace EragPermission\Commands;
44

5+
namespace EragPermission\Commands;
6+
57
use Illuminate\Console\Command;
68
use Illuminate\Support\Facades\File;
9+
use Symfony\Component\Process\Process;
710

811
class UpgradeVersions extends Command
912
{
1013
protected $signature = 'erag:upgrade-version';
1114

12-
protected $description = 'Upgrades the version by publishing migration files.';
15+
protected $description = 'Upgrades the version by publishing migration files and updating the package.';
1316

1417
public function __construct()
1518
{
1619
parent::__construct();
1720
}
1821

1922
public function handle(): void
23+
{
24+
$this->info('Starting the upgrade process for the Erag Laravel Role Permission package...');
25+
26+
$this->updatePackage();
27+
28+
$this->publishMigrations();
29+
30+
$this->info('Upgrade process completed.');
31+
}
32+
33+
protected function updatePackage(): void
34+
{
35+
$this->info('Updating the erag/laravel-role-permission package...');
36+
37+
$process = new Process(['composer', 'update', 'erag/laravel-role-permission']);
38+
39+
$process->run();
40+
41+
if (! $process->isSuccessful()) {
42+
$this->error('Failed to update the package. Please check your Composer configuration.');
43+
} else {
44+
$this->info('Package updated successfully.');
45+
}
46+
}
47+
48+
protected function publishMigrations(): void
2049
{
2150
$migrationFile = database_path('migrations/06_users_permissions_add_column.php');
2251

2352
if (file_exists($migrationFile)) {
2453
$this->info('✅ The system is up to date.');
2554
} else {
55+
$this->info('Publishing migration files...');
56+
2657
$this->info('🔄 Upgrading the version by publishing new migration files...');
2758

2859
$stubPath = __DIR__.'/../database/06_users_permissions_add_column.php.stub';

src/PermissionServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function boot(Router $router): void
8888

8989
}
9090

91-
protected function ModelBindings()
91+
protected function ModelBindings(): void
9292
{
9393
$this->app->bind(RoleContract::class, function ($app) {
9494
return new Role;

src/Traits/HasPermissionsTrait.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ public function givePermissionsTo(array $permissions, string|array|null $expires
3535
return $this;
3636
}
3737

38-
public function withdrawPermissionsTo(...$permissions): static
38+
public function detachPermissions(string|array $permissions): static
3939
{
40-
$permissions = $this->getAllPermissions($permissions);
41-
$this->permissions()->detach($permissions);
40+
$arrayPermissions = CoreUtility::stringArray($permissions);
41+
42+
$getPermissions = $this->getAllPermissions($arrayPermissions);
43+
$this->permissions()->detach($getPermissions);
4244

4345
return $this;
4446
}

0 commit comments

Comments
 (0)