Skip to content

Commit

Permalink
add updater script
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Jul 10, 2024
1 parent 1a0e3c4 commit 79882c1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ServiceProvider extends AddonServiceProvider
protected $updateScripts = [
UpdateScripts\ChangePermissionNames::class,
UpdateScripts\MigrateBlueprints::class,
UpdateScripts\AddManagePublishStatesPermissionToRoles::class,
];

protected $vite = [
Expand Down
35 changes: 35 additions & 0 deletions src/UpdateScripts/AddManagePublishStatesPermissionToRoles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace StatamicRadPack\Runway\UpdateScripts;

use Statamic\Facades\Role;
use Statamic\UpdateScripts\UpdateScript;
use StatamicRadPack\Runway\Resource;
use StatamicRadPack\Runway\Runway;

class AddManagePublishStatesPermissionToRoles extends UpdateScript
{
public function shouldUpdate($newVersion, $oldVersion)
{
return $this->isUpdatingTo('7.5.4');
}

public function update()
{
Role::all()->each(function ($role) {
$requiresSave = false;

Runway::allResources()->each(function (Resource $resource) use ($role, &$requiresSave) {
if ($role->hasPermission("create {$resource->handle()}")) {
$role->addPermission("publish {$resource->handle()}");
$requiresSave = true;
}

});

if ($requiresSave) {
$role->save();
}
});
}
}

0 comments on commit 79882c1

Please sign in to comment.