Passed
Push — master ( 702f24...55adc1 )
by Yannick
09:28
created

SettingsValueTemplateFixtures   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 791
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 483
dl 0
loc 791
rs 10
c 1
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
B load() 0 38 6
A getGroups() 0 3 1
B getTemplatesGrouped() 0 736 1
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\DataFixtures;
8
9
use Chamilo\CoreBundle\Entity\SettingsCurrent;
10
use Chamilo\CoreBundle\Entity\SettingsValueTemplate;
11
use Doctrine\Bundle\FixturesBundle\Fixture;
12
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
13
use Doctrine\Persistence\ObjectManager;
14
15
class SettingsValueTemplateFixtures extends Fixture implements FixtureGroupInterface
16
{
17
    public static function getGroups(): array
18
    {
19
        return ['settings-value-template'];
20
    }
21
22
    /**
23
     * Returns the list of JSON templates grouped by category.
24
     */
25
    public static function getTemplatesGrouped(): array
26
    {
27
        return [
28
            'platform' => [
29
                [
30
                    'name' => 'push_notification_settings',
31
                    'json_example' => [
32
                        'gotify_url' => 'http://localhost:8080',
33
                        'gotify_token' => 'A0yWWfe_8YRLv_B',
34
                        'enabled' => true,
35
                        'vapid_public_key' => 'BNg54MTyDZSdyFq99EmppT606jKVDS5o7jGVxMLW3Qir937A98sxtrK4VMt1ddNlK93MUenK0kM3aiAMu9HRcjQ=',
36
                        'vapid_private_key' => 'UgS5-xSneOcSyNJVq4c9wmEGaCoE1Y8oh-7ZGXPgs8o'
37
                    ]
38
                ],
39
                [
40
                    'name' => 'proxy_settings',
41
                    'json_example' => [
42
                        'stream_context_create' => [
43
                            'http' => [
44
                                'proxy' => 'tcp://example.com:8080',
45
                                'request_fulluri' => true
46
                            ]
47
                        ],
48
                        'curl_setopt_array' => [
49
                            'CURLOPT_PROXY' => 'http://example.com',
50
                            'CURLOPT_PROXYPORT' => '8080'
51
                        ]
52
                    ]
53
                ],
54
                [
55
                    'name' => 'video_features',
56
                    'json_example' => [
57
                        'features' => ['speed']
58
                    ]
59
                ],
60
                [
61
                    'name' => 'table_row_list',
62
                    'json_example' => [
63
                        'options' => [50, 100, 200, 500]
64
                    ]
65
                ],
66
                [
67
                    'name' => 'extldap_config',
68
                    'json_example' => [
69
                        'host' => '',
70
                        'port' => ''
71
                    ]
72
                ],
73
                [
74
                    'name' => 'update_student_expiration_x_date',
75
                    'json_example' => [
76
                        'days' => 0,
77
                        'months' => 0
78
                    ]
79
                ],
80
                [
81
                    'name' => 'user_status_show_option',
82
                    'json_example' => [
83
                        'COURSEMANAGER' => true,
84
                        'STUDENT' => true,
85
                        'DRH' => false,
86
                        'SESSIONADMIN' => false,
87
                        'STUDENT_BOSS' => false,
88
                        'INVITEE' => false
89
                    ]
90
                ],
91
                [
92
                    'name' => 'user_number_of_days_for_default_expiration_date_per_role',
93
                    'json_example' => [
94
                        'COURSEMANAGER' => 365,
95
                        'STUDENT' => 31,
96
                        'DRH' => 31,
97
                        'SESSIONADMIN' => 60,
98
                        'STUDENT_BOSS' => 60,
99
                        'INVITEE' => 31
100
                    ]
101
                ],
102
                [
103
                    'name' => 'show_tabs_per_role',
104
                    'json_example' => [
105
                        'SESSIONADMIN' => ['session_admin', 'my_courses'],
106
                        'ADMIN' => ['platform_administration']
107
                    ]
108
                ],
109
            ],
110
            'agenda' => [
111
                [
112
                    'name' => 'agenda_legend',
113
                    'json_example' => [
114
                        'red' => 'red caption',
115
                        '#f0f' => 'another caption'
116
                    ],
117
                ],
118
                [
119
                    'name' => 'agenda_colors',
120
                    'json_example' => [
121
                        'platform' => 'red',
122
                        'course' => '#458B00',
123
                        'group' => '#A0522D',
124
                        'session' => '#00496D',
125
                        'other_session' => '#999',
126
                        'personal' => 'steel blue',
127
                        'student_publication' => '#FF8C00',
128
                    ],
129
                ],
130
                [
131
                    'name' => 'agenda_on_hover_info',
132
                    'json_example' => [
133
                        'options' => [
134
                            'comment' => true,
135
                            'description' => true,
136
                        ],
137
                    ],
138
                ],
139
                [
140
                    'name' => 'fullcalendar_settings',
141
                    'json_example' => [
142
                        'settings' => [
143
                            'businessHours' => [
144
                                'dow' => [0, 1, 2, 3, 4],
145
                                'start' => '10:00',
146
                                'end' => '18:00',
147
                            ],
148
                            'firstDay' => 0,
149
                        ],
150
                    ],
151
                ],
152
            ],
153
            'admin' => [
154
                [
155
                    'name' => 'user_status_option_show_only_for_admin',
156
                    'json_example' => [
157
                        'COURSEMANAGER' => false,
158
                        'STUDENT' => false,
159
                        'DRH' => false,
160
                        'SESSIONADMIN' => true,
161
                        'STUDENT_BOSS' => false,
162
                        'INVITEE' => false,
163
                    ],
164
                ],
165
            ],
166
            'aihelpers' => [
167
                [
168
                    'name' => 'ai_providers',
169
                    'json_example' => [
170
                        'openai' => [
171
                            'url' => 'https://api.openai.com/v1/chat/completions',
172
                            'api_key' => 'your-key',
173
                            'model' => 'gpt-4o',
174
                            'temperature' => 0.7,
175
                            'organization_id' => 'org123',
176
                            'monthly_token_limit' => 10000,
177
                        ],
178
                        'deepseek' => [
179
                            'url' => 'https://api.deepseek.com/chat/completions',
180
                            'api_key' => 'your-key',
181
                            'model' => 'deepseek-chat',
182
                            'temperature' => 0.7,
183
                            'organization_id' => 'org456',
184
                            'monthly_token_limit' => 5000,
185
                        ],
186
                    ],
187
                ],
188
            ],
189
            'announcement' => [
190
                [
191
                    'name' => 'send_all_emails_to',
192
                    'json_example' => [
193
                        'emails' => [
194
                            '[email protected]',
195
                            '[email protected]',
196
                        ],
197
                    ],
198
                ],
199
            ],
200
            'course' => [
201
                [
202
                    'name' => 'course_log_hide_columns',
203
                    'json_example' => ['columns' => [1, 9]],
204
                ],
205
                [
206
                    'name' => 'course_student_info',
207
                    'json_example' => [
208
                        'score' => false,
209
                        'progress' => false,
210
                        'certificate' => false,
211
                    ],
212
                ],
213
                [
214
                    'name' => 'course_catalog_settings',
215
                    'json_example' => [
216
                        'link_settings' => [
217
                            'info_url' => 'course_description_popup',
218
                            'title_url' => 'course_home',
219
                            'image_url' => 'course_about',
220
                        ],
221
                        'hide_course_title' => false,
222
                        'redirect_after_subscription' => 'course_home',
223
                        'extra_fields_in_search_form' => ['variable1', 'variable2'],
224
                        'extra_fields_in_course_block' => ['variable3', 'variable4'],
225
                        'standard_sort_options' => [
226
                            'title' => 1,
227
                            'creation_date' => -1,
228
                            'count_users' => -1,
229
                            'point_info/point_average' => -1,
230
                            'point_info/total_score' => -1,
231
                            'point_info/users' => -1,
232
                        ],
233
                        'extra_field_sort_options' => [
234
                            'variable5' => -1,
235
                            'variable6' => 1,
236
                        ],
237
                    ],
238
                ],
239
                [
240
                    'name' => 'course_log_default_extra_fields',
241
                    'json_example' => ['extra_fields' => ['office_address', 'office_phone_extension']],
242
                ],
243
                [
244
                    'name' => 'courses_catalogue_show_only_category',
245
                    'json_example' => ['Cat1', 'Cat2'],
246
                ],
247
                [
248
                    'name' => 'course_creation_by_teacher_extra_fields_to_show',
249
                    'json_example' => ['fields' => ['ExtrafieldLabel1', 'ExtrafieldLabel2']],
250
                ],
251
                [
252
                    'name' => 'course_creation_form_set_extra_fields_mandatory',
253
                    'json_example' => ['fields' => ['fieldLabel1', 'fieldLabel2']],
254
                ],
255
                [
256
                    'name' => 'course_configuration_tool_extra_fields_to_show_and_edit',
257
                    'json_example' => ['fields' => ['ExtrafieldLabel1', 'ExtrafieldLabel2']],
258
                ],
259
                [
260
                    'name' => 'course_creation_user_course_extra_field_relation_to_prefill',
261
                    'json_example' => [
262
                        'fields' => [
263
                            'CourseExtrafieldLabel1' => 'UserExtrafieldLabel1',
264
                            'CourseExtrafieldLabel2' => 'UserExtrafieldLabel2',
265
                        ],
266
                    ],
267
                ],
268
            ],
269
            'document' => [
270
                [
271
                    'name' => 'compilatio_tool',
272
                    'json_example' => [
273
                        'settings' => [
274
                            'key' => '',
275
                            'soap_url' => '',
276
                            'proxy_host' => '',
277
                            'proxy_port' => '',
278
                            'max_filesize' => '',
279
                            'transport_mode' => '',
280
                            'wget_uri' => '',
281
                            'wget_login' => '',
282
                            'wget_password' => '',
283
                        ],
284
                    ],
285
                ],
286
                [
287
                    'name' => 'documents_custom_cloud_link_list',
288
                    'json_example' => [
289
                        'links' => ['example.com', 'example2.com'],
290
                    ],
291
                ],
292
            ],
293
            'editor' => [
294
                [
295
                    'name' => 'editor_driver_list',
296
                    'json_example' => ['PersonalDriver', 'CourseDriver'],
297
                ],
298
                [
299
                    'name' => 'editor_settings',
300
                    'json_example' => [
301
                        'config' => [
302
                            'youtube_responsive' => true,
303
                            'image_responsive' => true,
304
                        ],
305
                    ],
306
                ],
307
                [
308
                    'name' => 'video_player_renderers',
309
                    'json_example' => [
310
                        'renderers' => ['dailymotion', 'facebook', 'twitch', 'vimeo', 'youtube'],
311
                    ],
312
                ],
313
            ],
314
            'exercise' => [
315
                [
316
                    'name' => 'exercise_additional_teacher_modify_actions',
317
                    'json_example' => [
318
                        'myplugin' => ['MyPlugin', 'urlGeneratorCallback'],
319
                    ],
320
                ],
321
                [
322
                    'name' => 'quiz_image_zoom',
323
                    'json_example' => [
324
                        'options' => [
325
                            'zoomWindowWidth' => 400,
326
                            'zoomWindowHeight' => 400,
327
                        ],
328
                    ],
329
                ],
330
                [
331
                    'name' => 'add_exercise_best_attempt_in_report',
332
                    'json_example' => [
333
                        'courses' => [
334
                            'ABC' => [88, 89],
335
                        ],
336
                    ],
337
                ],
338
                [
339
                    'name' => 'exercise_category_report_user_extra_fields',
340
                    'json_example' => [
341
                        'fields' => ['skype', 'rssfeeds'],
342
                    ],
343
                ],
344
                [
345
                    'name' => 'score_grade_model',
346
                    'json_example' => [
347
                        'models' => [
348
                            [
349
                                'id' => 1,
350
                                'name' => 'ThisIsMyModel',
351
                                'score_list' => [
352
                                    [
353
                                        'name' => 'VeryBad',
354
                                        'css_class' => 'btn-danger',
355
                                        'min' => 0,
356
                                        'max' => 20,
357
                                        'score_to_qualify' => 0,
358
                                    ],
359
                                    [
360
                                        'name' => 'Bad',
361
                                        'css_class' => 'btn-danger',
362
                                        'min' => 21,
363
                                        'max' => 50,
364
                                        'score_to_qualify' => 25,
365
                                    ],
366
                                    [
367
                                        'name' => 'Good',
368
                                        'css_class' => 'btn-warning',
369
                                        'min' => 51,
370
                                        'max' => 70,
371
                                        'score_to_qualify' => 60,
372
                                    ],
373
                                    [
374
                                        'name' => 'VeryGood',
375
                                        'css_class' => 'btn-success',
376
                                        'min' => 71,
377
                                        'max' => 100,
378
                                        'score_to_qualify' => 100,
379
                                    ],
380
                                ],
381
                            ],
382
                        ],
383
                    ],
384
                ],
385
                [
386
                    'name' => 'exercise_embeddable_extra_types',
387
                    'json_example' => [
388
                        'types' => [],
389
                    ],
390
                ],
391
            ],
392
            'gradebook' => [
393
                [
394
                    'name' => 'gradebook_dependency_mandatory_courses',
395
                    'json_example' => [
396
                        'courses' => [1, 2],
397
                    ],
398
                ],
399
                [
400
                    'name' => 'gradebook_badge_sidebar',
401
                    'json_example' => [
402
                        'gradebooks' => [1, 2, 3],
403
                    ],
404
                ],
405
                [
406
                    'name' => 'gradebook_flatview_extrafields_columns',
407
                    'json_example' => [
408
                        'variables' => [],
409
                    ],
410
                ],
411
                [
412
                    'name' => 'gradebook_pdf_export_settings',
413
                    'json_example' => [
414
                        'hide_score_weight' => true,
415
                        'hide_feedback_textarea' => true,
416
                    ],
417
                ],
418
                [
419
                    'name' => 'gradebook_display_extra_stats',
420
                    'json_example' => [
421
                        'columns' => [1, 2, 3],
422
                    ],
423
                ],
424
            ],
425
            'learningpath' => [
426
                [
427
                    'name' => 'lp_subscription_settings',
428
                    'json_example' => [
429
                        'options' => [
430
                            'allow_add_users_to_lp' => true,
431
                            'allow_add_users_to_lp_category' => true,
432
                        ],
433
                    ],
434
                ],
435
                [
436
                    'name' => 'lp_view_settings',
437
                    'json_example' => [
438
                        'display' => [
439
                            'show_reporting_icon' => true,
440
                            'hide_lp_arrow_navigation' => false,
441
                            'show_toolbar_by_default' => false,
442
                            'navigation_in_the_middle' => false,
443
                        ],
444
                    ],
445
                ],
446
                [
447
                    'name' => 'download_files_after_all_lp_finished',
448
                    'json_example' => [
449
                        'courses' => [
450
                            'ABC' => [1, 100],
451
                        ],
452
                    ],
453
                ],
454
                [
455
                    'name' => 'my_progress_course_tools_order',
456
                    'json_example' => [
457
                        'order' => ['quizzes', 'learning_paths', 'skills'],
458
                    ],
459
                ],
460
            ],
461
            'mail' => [
462
                [
463
                    'name' => 'cron_notification_help_desk',
464
                    'json_example' => [
465
                        'emails' => [
466
                            '[email protected]',
467
                            '[email protected]',
468
                        ],
469
                    ],
470
                ],
471
                [
472
                    'name' => 'notifications_extended_footer_message',
473
                    'json_example' => [
474
                        'english' => [
475
                            'paragraphs' => [
476
                                'Change or delete this paragraph or add another one',
477
                            ],
478
                        ],
479
                    ],
480
                ],
481
            ],
482
            'profile' => [
483
                [
484
                    'name' => 'hide_user_field_from_list',
485
                    'json_example' => [
486
                        'fields' => ['username'],
487
                    ],
488
                ],
489
                [
490
                    'name' => 'send_notification_when_user_added',
491
                    'json_example' => [
492
                        'admins' => [1],
493
                    ],
494
                ],
495
                [
496
                    'name' => 'show_conditions_to_user',
497
                    'json_example' => [
498
                        'conditions' => [
499
                            [
500
                                'variable' => 'gdpr',
501
                                'display_text' => 'GDPRTitle',
502
                                'text_area' => 'GDPRTextArea',
503
                            ],
504
                            [
505
                                'variable' => 'my_terms',
506
                                'display_text' => 'My test conditions',
507
                                'text_area' => 'This is a long text area, with lot of terms and conditions ... ',
508
                            ],
509
                        ],
510
                    ],
511
                ],
512
                [
513
                    'name' => 'profile_fields_visibility',
514
                    'json_example' => [
515
                        'options' => [
516
                            'vcard' => false,
517
                            'firstname' => true,
518
                            'lastname' => true,
519
                            'photo' => true,
520
                            'email' => false,
521
                            'language' => true,
522
                            'chat' => true,
523
                            'terms_ville' => true,
524
                            'terms_datedenaissance' => true,
525
                            'terms_paysresidence' => false,
526
                            'filiere_user' => true,
527
                            'terms_villedustage' => true,
528
                            'hobbies' => true,
529
                            'langue_cible' => true,
530
                        ],
531
                    ],
532
                ],
533
                [
534
                    'name' => 'user_import_settings',
535
                    'json_example' => [
536
                        'options' => [
537
                            'send_mail_default_option' => '1',
538
                        ],
539
                    ],
540
                ],
541
                [
542
                    'name' => 'user_search_on_extra_fields',
543
                    'json_example' => [
544
                        'extra_fields' => ['variable1', 'variable2'],
545
                    ],
546
                ],
547
                [
548
                    'name' => 'community_managers_user_list',
549
                    'json_example' => [
550
                        'users' => [1],
551
                    ],
552
                ],
553
                [
554
                    'name' => 'allow_social_map_fields',
555
                    'json_example' => [
556
                        'fields' => ['terms_villedustage', 'terms_ville'],
557
                    ],
558
                ],
559
            ],
560
            'registration' => [
561
                [
562
                    'name' => 'required_extra_fields_in_inscription',
563
                    'json_example' => [
564
                        'options' => [
565
                            'terms_adresse',
566
                            'terms_codepostal',
567
                            'terms_ville',
568
                            'terms_paysresidence',
569
                            'terms_datedenaissance',
570
                            'terms_genre',
571
                            'filiere_user',
572
                            'terms_formation_niveau',
573
                            'langue_cible',
574
                        ],
575
                    ],
576
                ],
577
                [
578
                    'name' => 'allow_fields_inscription',
579
                    'json_example' => [
580
                        'fields' => [
581
                            'lastname',
582
                            'firstname',
583
                            'email',
584
                            'language',
585
                            'phone',
586
                            'address',
587
                        ],
588
                        'extra_fields' => [
589
                            'terms_nationalite',
590
                            'terms_numeroderue',
591
                            'terms_nomderue',
592
                            'terms_codepostal',
593
                            'terms_paysresidence',
594
                            'terms_ville',
595
                            'terms_datedenaissance',
596
                            'terms_genre',
597
                            'filiere_user',
598
                            'terms_formation_niveau',
599
                            'terms_villedustage',
600
                            'terms_adresse',
601
                            'gdpr',
602
                            'langue_cible',
603
                        ],
604
                    ],
605
                ],
606
                [
607
                    'name' => 'redirect_after_login',
608
                    'json_example' => [
609
                        'COURSEMANAGER' => '',
610
                        'STUDENT' => '',
611
                        'DRH' => '',
612
                        'SESSIONADMIN' => 'admin-dashboard',
613
                        'STUDENT_BOSS' => '',
614
                        'INVITEE' => '',
615
                        'ADMIN' => 'admin-dashboard',
616
                    ],
617
                ],
618
            ],
619
            'security' => [
620
                [
621
                    'name' => 'password_requirements',
622
                    'json_example' => [
623
                        'min' => [
624
                            'lowercase' => 2,
625
                            'uppercase' => 2,
626
                            'numeric' => 2,
627
                            'length' => 8,
628
                        ],
629
                    ],
630
                ],
631
                [
632
                    'name' => 'allow_online_users_by_status',
633
                    'json_example' => [
634
                        'status' => [1, 5],
635
                    ],
636
                ],
637
            ],
638
            'session' => [
639
                [
640
                    'name' => 'my_courses_session_order',
641
                    'json_example' => [
642
                        'field' => 'end_date',
643
                        'order' => 'desc',
644
                    ],
645
                ],
646
                [
647
                    'name' => 'session_import_settings',
648
                    'json_example' => [
649
                        'options' => [
650
                            'session_exists_default_option' => '1',
651
                            'send_mail_default_option' => '1',
652
                        ],
653
                    ],
654
                ],
655
                [
656
                    'name' => 'catalog_settings',
657
                    'json_example' => [
658
                        'sessions' => [
659
                            'by_title' => true,
660
                            'by_date' => true,
661
                            'by_tag' => true,
662
                            'show_session_info' => true,
663
                            'show_session_date' => true,
664
                        ],
665
                        'courses' => [
666
                            'by_title' => true,
667
                        ],
668
                    ],
669
                ],
670
                [
671
                    'name' => 'tracking_columns',
672
                    'json_example' => [
673
                        'course_session' => [
674
                            'course_title' => true,
675
                            'published_exercises' => true,
676
                            'new_exercises' => true,
677
                            'my_average' => true,
678
                            'average_exercise_result' => true,
679
                            'time_spent' => true,
680
                            'lp_progress' => true,
681
                            'score' => true,
682
                            'best_score' => true,
683
                            'last_connection' => true,
684
                            'details' => true,
685
                        ],
686
                        'my_students_lp' => [
687
                            'lp' => true,
688
                            'time' => true,
689
                            'best_score' => true,
690
                            'latest_attempt_avg_score' => true,
691
                            'progress' => true,
692
                            'last_connection' => true,
693
                        ],
694
                        'my_progress_lp' => [
695
                            'lp' => true,
696
                            'time' => true,
697
                            'progress' => true,
698
                            'score' => true,
699
                            'best_score' => true,
700
                            'last_connection' => true,
701
                        ],
702
                        'my_progress_courses' => [
703
                            'course_title' => true,
704
                            'time_spent' => true,
705
                            'progress' => true,
706
                            'best_score_in_lp' => true,
707
                            'best_score_not_in_lp' => true,
708
                            'latest_login' => true,
709
                            'details' => true,
710
                        ],
711
                    ],
712
                ],
713
                [
714
                    'name' => 'session_creation_user_course_extra_field_relation_to_prefill',
715
                    'json_example' => [
716
                        'fields' => [
717
                            'client' => 'client',
718
                            'region' => 'region',
719
                        ],
720
                    ],
721
                ],
722
                [
723
                    'name' => 'session_creation_form_set_extra_fields_mandatory',
724
                    'json_example' => [
725
                        'fields' => ['client', 'region'],
726
                    ],
727
                ],
728
            ],
729
            'skill' => [
730
                [
731
                    'name' => 'skill_levels_names',
732
                    'json_example' => [
733
                        'levels' => [
734
                            1 => 'Skills',
735
                            2 => 'Capability',
736
                            3 => 'Dimension',
737
                        ],
738
                    ],
739
                ],
740
            ],
741
            'survey' => [
742
                [
743
                    'name' => 'hide_survey_edition',
744
                    'json_example' => [
745
                        'codes' => [],
746
                    ],
747
                ],
748
                [
749
                    'name' => 'survey_additional_teacher_modify_actions',
750
                    'json_example' => [
751
                        'myplugin' => ['MyPlugin', 'urlGeneratorCallback'],
752
                    ],
753
                ],
754
            ],
755
            'ticket' => [
756
                [
757
                    'name' => 'ticket_project_user_roles',
758
                    'json_example' => [
759
                        'permissions' => [
760
                            1 => [17, 1],
761
                        ],
762
                    ],
763
                ],
764
            ],
765
        ];
766
    }
767
768
    public function load(ObjectManager $manager): void
769
    {
770
        $groupedTemplates = self::getTemplatesGrouped();
771
772
        $settingsRepo = $manager->getRepository(SettingsCurrent::class);
773
        $templateRepo = $manager->getRepository(SettingsValueTemplate::class);
774
775
        foreach ($groupedTemplates as $category => $templates) {
776
            foreach ($templates as $data) {
777
                // Check if the template already exists
778
                $template = $templateRepo->findOneBy(['name' => $data['name']]);
779
780
                if (!$template) {
781
                    $template = new SettingsValueTemplate();
782
                    $template->setCreatedAt(new \DateTime());
783
                }
784
785
                $template
786
                    ->setName($data['name'])
787
                    ->setJsonExample(json_encode($data['json_example'], JSON_PRETTY_PRINT))
788
                    ->setUpdatedAt(new \DateTime());
789
790
                $manager->persist($template);
791
                $manager->flush(); // ensure ID is generated for linking
792
793
                // Now update the settings table to link this template
794
                $settings = $settingsRepo->findBy(['variable' => $data['name']]);
795
796
                foreach ($settings as $setting) {
797
                    if ($setting->getValueTemplate()?->getId() !== $template->getId()) {
798
                        $setting->setValueTemplate($template);
799
                        $manager->persist($setting);
800
                    }
801
                }
802
            }
803
        }
804
805
        $manager->flush();
806
    }
807
}
808