Migration::whileAdmin
The intent with this function is to allow it to maintain it's own state while allowing you to execute your own arbitrary code within that state (i.e. while logged in as an administrator).
Ensures we have permissions to manipulate pages (gets around access issues with global state). Unfortunately, the creation of a default admin account below is necessary because SilverStripe will reference global state via Member::currentUser() and the only surefire way around this is to login as a default admin with full access.
Signature
protected function whileAdmin(callable
$closure )
Parameters
$closure
— callable- The closure (or class/method array) that you'd like to execute while logged in
as an admin.