|
@@ -0,0 +1,41 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+$content = file_get_contents('app/Services/UnitService.php');
|
|
|
|
|
+$replacement = <<<'REPLACE'
|
|
|
|
|
+ // Clona os perfis customizados a partir do arquivo de configuração gerado
|
|
|
|
|
+ $templateRoles = config('default_franchisee_roles', []);
|
|
|
|
|
+
|
|
|
|
|
+ if (!empty($templateRoles)) {
|
|
|
|
|
+ foreach ($templateRoles as $templateRole) {
|
|
|
|
|
+ $newRole = UserType::create([
|
|
|
|
|
+ 'unit_id' => $unit->id,
|
|
|
|
|
+ 'system_key' => $templateRole['system_key'],
|
|
|
|
|
+ 'scope_key' => "unit:{$unit->id}",
|
|
|
|
|
+ 'slug' => \Illuminate\Support\Str::slug($templateRole['label'] . '-' . $unit->id),
|
|
|
|
|
+ 'label' => $templateRole['label'],
|
|
|
|
|
+ 'is_system' => false,
|
|
|
|
|
+ 'access_scope' => 'unit',
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($templateRole['permissions'] as $p) {
|
|
|
|
|
+ \App\Models\UserTypePermission::create([
|
|
|
|
|
+ 'user_type' => $newRole->slug,
|
|
|
|
|
+ 'user_type_id' => $newRole->id,
|
|
|
|
|
+ 'permission_id' => $p['permission_id'],
|
|
|
|
|
+ 'bits' => $p['bits'],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+REPLACE;
|
|
|
|
|
+
|
|
|
|
|
+// The original content to replace starts from "// Clona os perfis customizados" up to the end of the if statement
|
|
|
|
|
+$startString = "// Clona os perfis customizados (Neurotrainer, Financeiro, Gestor) baseados na unidade da Andreia";
|
|
|
|
|
+$endString = " }\n\n \$franchisee = Franchisee::create(\$franchiseeData);";
|
|
|
|
|
+
|
|
|
|
|
+$startPos = strpos($content, $startString);
|
|
|
|
|
+$endPos = strpos($content, $endString) + strlen(" }");
|
|
|
|
|
+
|
|
|
|
|
+$contentToReplace = substr($content, $startPos, $endPos - $startPos);
|
|
|
|
|
+$content = str_replace($contentToReplace, $replacement, $content);
|
|
|
|
|
+
|
|
|
|
|
+file_put_contents('app/Services/UnitService.php', $content);
|