patch_unitservice.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. $content = file_get_contents('app/Services/UnitService.php');
  3. $replacement = <<<'REPLACE'
  4. // Clona os perfis customizados a partir do arquivo de configuração gerado
  5. $templateRoles = config('default_franchisee_roles', []);
  6. if (!empty($templateRoles)) {
  7. foreach ($templateRoles as $templateRole) {
  8. $newRole = UserType::create([
  9. 'unit_id' => $unit->id,
  10. 'system_key' => $templateRole['system_key'],
  11. 'scope_key' => "unit:{$unit->id}",
  12. 'slug' => \Illuminate\Support\Str::slug($templateRole['label'] . '-' . $unit->id),
  13. 'label' => $templateRole['label'],
  14. 'is_system' => false,
  15. 'access_scope' => 'unit',
  16. ]);
  17. foreach ($templateRole['permissions'] as $p) {
  18. \App\Models\UserTypePermission::create([
  19. 'user_type' => $newRole->slug,
  20. 'user_type_id' => $newRole->id,
  21. 'permission_id' => $p['permission_id'],
  22. 'bits' => $p['bits'],
  23. ]);
  24. }
  25. }
  26. }
  27. REPLACE;
  28. // The original content to replace starts from "// Clona os perfis customizados" up to the end of the if statement
  29. $startString = "// Clona os perfis customizados (Neurotrainer, Financeiro, Gestor) baseados na unidade da Andreia";
  30. $endString = " }\n\n \$franchisee = Franchisee::create(\$franchiseeData);";
  31. $startPos = strpos($content, $startString);
  32. $endPos = strpos($content, $endString) + strlen(" }");
  33. $contentToReplace = substr($content, $startPos, $endPos - $startPos);
  34. $content = str_replace($contentToReplace, $replacement, $content);
  35. file_put_contents('app/Services/UnitService.php', $content);