-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Name validation error while trying to save an edited command #76
Fix: Name validation error while trying to save an edited command #76
Conversation
…slation for the flash message to start a command immediately
@DieWallSoCom Can you describe a bit more specific how i can reproduce the issue? |
Codecov Report
@@ Coverage Diff @@
## master #76 +/- ##
============================================
+ Coverage 82.88% 83.01% +0.12%
- Complexity 276 277 +1
============================================
Files 30 30
Lines 1239 1248 +9
============================================
+ Hits 1027 1036 +9
Misses 212 212
|
I removed the translation change and will make a separate pull request for it. |
Thanks. i will have a closer look as soon i have some free time. |
…n editing a command
Thank you for your time. |
I tried to reproduce this. But i do not know how. The name is unique on purpose. As the name is used as identifier in cli commands. I see no edit button in the list view. To edit a command with a form, you have to call /command-scheduler/detail/edit/ID If i create or edit a command, the Can you please post |
First, I'm using the version 5.0.7. Maybe I didn't provide this information. As for the edit button. It's not a usual button. First you have to click on the "plus"-icon in the command list on the leftmost column and then on the "pencil"-icon. The url will be something like "/command-scheduler/detail/edit/ID". Now I often want to modify the cron expression of an existing command. Wouldn't it be better if a command could be edited one time for changing the cron expression. I think I will prepare a few screenshots for clarification. I will try to post them this week. |
I made a video to clarify the issue I'm having: Command Scheduler Scheduled commands - Google Chrome 2023-10-13 10-54-51.zip In the video you can see that the command Example Command 1 is being edited. The only thing that needs to be changed is the cron expression and I would like to keep the command name. The UniqueConstraint in the ScheduledCommand entity prevents the usage of the same name in the form, even if the form is used to edit a command and not to create a new one. My PullRequest modifies the form, so that the UniqueConstraint is only used when a new command is created but not when it's edited so that the name of the command does not have to be changed while editing it. Further I added modifications to disable the name field in the form while editing a command. This was necessary because the UniqueConstraint validator is not used while editing a command. A user could change the name of the command while editing it and choose a name that is already used for another command. |
Maybe the custom entity manager was the missing info, because i could not recreate the problem on my side. @DieWallSoCom Do you use a custom entity manager? |
@Chris53897 ...
entity_managers:
default:
connection: dynamic
naming_strategy: doctrine.orm.naming_strategy.underscore
...
main:
connection: main
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
main:
is_bundle: false
dir: "%kernel.project_dir%/src/Entity/main"
prefix: 'App\Entity\main'
DukecityCommandSchedulerBundle: ~
... Does it answer your question? Do you use a different doctrine configuration for the entity manager? |
Thanks for sharing, that helps me. Yes i use it under the This Bundle needs more tests for this I have integrated it in 5.x and 6.x |
I did test 5.x and 6.x with my @DieWallSoCom @fautor |
Hi, it works for me. Now I can edit commands without the need to rename them. @Chris53897: Would it be possible to add the following prs to the 5.x-branch? |
Can you please provide a PR against |
Fix: While trying to save an edited command from the command list (command-scheduler/list) an validation error occurs because a command with the same already exists.
The cause of this Problem is the "UniqueEntity" annotation found in the "ScheduledCommand" entity. Its irrelevant whether a new scheduled command is created or an existing one is edited.
This issue is fixed by using a validation group. The "UniqueEntity" constraint now has the validation group "new". This group is added to the form for creating a command, but not to the form to edit an existing command.
To reproduce the fixed problem you have to edit a command in the command list on "/command-scheduler/list". Change something other then the name and try to save the change. It will not work and a note will appear near the name field on the form that will say something like "the name already exists". To work around that issue you have to change the name every time you want to edit a command, even if only to change the cron expression, for example.
The cause of this Problem is the symfony constraint "UniqueEntity". Even if a form is edited (the record shall only be changed) it will see that a command with the same name already exists in the scheduled_command table. The fix will enable the "UniqueEntity" constraint only for a form to create a new command, but not if an existing command is edited.