transaction(function()use($host,$p){$count=0;foreach($p['grants_per_book']as$g){$where=$p['scope']+$g;$rows=$host->table('permission_grants')->where($where)->get();foreach($rows as$row){$host->table('permission_grants')->where('id',$row->id)->delete();App\Modules\Identity\Services\Audit::record('access.remuneration_qa_retracted',null,1,2,2,$row->user_id,['permission'=>$row->permission,'reason'=>'Directiva expressa: RH autónomo com perfis distintos; revogar só as concessões novas deste bloco ainda não disponibilizado.']);$count++;}}return$count;}); file_put_contents($work.'/remunerations-finance-retracted.json',json_encode(['passed'=>true,'book'=>$book,'removed_only_new_financial_profile_grants'=>$removed,'business_writes'=>0,'new_hr_grants'=>0],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'book'=>$book,'removed'=>$removed,'proof'=>$work.'/remunerations-finance-retracted.json']).PHP_EOL;