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
Clone assets #6684
Clone assets #6684
Conversation
flonou
commented
Dec 6, 2019
| Q | A |
|---|---|
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #6682 |
|
Some simple unit tests must be added within this feature (should test cloning of several objects types). Tell us if you need help on that. |
|
Working on tests now |
|
@cedric-anne I would like to have more information about the Toolbox::addslashes_deep call. It messes with some fields (for exemple the helpdesk_item_type of profiles is badly cloned). Is this call necessary ? |
|
All HTTP request contents ( If you mix POST'ed data with some values from the database in a same array you want to store, you have to ensure you will not escape twice. |
|
Hmm ok. Seems like adding the addSlashes_deep call is messing with some fields on my test instance so I removed it but the test is still failing |
|
I will not have time to dig into this; but as far as I see, your issue comes from a "dbarray" that is handled in a specific manner in glpi (see importArrayFromDB and maybe Toolbox:decodeArrayFromInput). |
|
Ok I removed the clone ability on profiles because the add method resets the rights, I guessed for security reasons. I need to add tests on non assets types to ensure they all work correctly |
|
Note : some items (specifically CommonDBChild) have a cloneItem method which is used by their parent containers to clone them when using templates. However, this method is not the one called when cloning the child inside the parent by my method (ex: cloning a network port). Should I try to merge both behaviors ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just made a technical review of the code, this seems correct; good job
I'll do a functional review asap.
I did not understand your last comment, I'm not sure this is still relevant.
|
@trasher Some classes already have a clone method named cloneItem. Specifically for templates I guess (when you instantiate a template, the template is cloned). Seems like many commondbchild subclasses need this to clone their subelements. My instantiation also need this cloning of the subitems (done in the post_clone method in my case) I was wondering if I should leave the cloning methods used for templates or try to homogenize it with my contribution |
Oh OK; thanks for the explanation :) |
|
I'm waiting for @flonou to homogenize th code as it was proposed |
|
@flonou |
|
H! |
|
@trasher Hi, I'm trying to get rid of the cloneItem methods and replace them with my clone method but I'm having trouble finding out how to update CommonDBRelation items. An alternative way (which would require less modifications on my part) of doing the same thing (meaning cloning sub-elements of a computer for example) would be for me to call the cloneItem methods when trying to clone a CommonDBRelation or CommonDBChild but I'm not quite convinced that these methods a nicely implemented in the sense that they are not part of the interface of CommonDBRelation or CommonDBChild. They are just declared in the sub-classes which seems prone to inconsistency if new sub-classes need to be added. Also I don't know if plugins rely on these methods or not. EDIT : A third alternative I'm thinking about would be to have an optional parameter in my clone method where we could override parts of the input parameters copied from the object to be cloned (in my case, I would override 'items_id' and 'itemtype') |
|
I went with the third option in the end, because otherwise, cloning would be blocked due to unicity of some parameters list in the database |
|
Hi @flonou; Tests are currently failing because you deprecate the |
|
Also, you have a lot of CS issues than can be fixed with phpcbf: |
|
Yes, the cloneItem method is used directly in the tests. I also need to merge the targeted branch in the process because it has changed. Should be done this week |
|
So I have two tests failing and I'm not sure if I should change them or not.
|
As far as I know, this is not the only place where you'll find an
This seems to be a "non standard" use case; it should work, but only for Software I guess. I do not have in mind any other cases like this one; maybe @cedric-anne or @orthagh would have a point of view on this one. |
|
You should take care your database is up to date, this may cause difficult to find issues. |
|
Yeah I tried to use the cli commands but after using the ui so it was somehow blocked. I must have messed up somewhere |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
This sounds correct, thank you :)
Just a few points left:
- you should add the
@deprecated 9.5on phpdoc for methods that are deprecated, - you should list deprecated methods in changelog file.
|
@vollkommenIrrelevant this PR is almost finished now I guess, maybe could you test the feature and give us feedbacks. Thank you. |
|
@trasher |
|
This is a work in progress; nothing is stable as it need to be tested. |
|
ok, ich will check for a solution. |
You can download sources archive from @flonou branch (clone or dowload => dowload zip): As said, it's source; not release. Main difference is third party libs (php, js, etc) are not provided, you have to install them, see https://github.com/glpi-project/glpi/blob/9.5/bugfixes/INSTALL.md Do not use this branch on production! |
|
Tests are now failing because of the merge I've done to fix the conflict on changelog file. Dashboards feature has been recently merge in the 9.5 branch, and I had not in mind it would break here. |
|
I guess it would be better to not redefine the clone method but instead prepareInputForClone() ? |
|
ok, i'll redo this, a new method is preferable i think |
|
Yes, I've had a look, it seems like the dashboard class is not quite behaving as a standard CommonDBTM (no use of add for example) and clone relies on this (although you can completely redefine the behaviour of clone if needed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! :)
First implementation of the clone functionality Updating tests to take into account the new action removing missed debug log Fixing code quality issues Fixing test case, we now have one more action possible Simplifying the clone method Adding test for the clone method on various types of items error in test code same ; missing on another line fixing code issues Adding a prepareInputForClone method that's useful for some types (user for example) Fixing the tests typo fixing some code quality issues and tests date to string comparison is not working getting a profile item was not correctly done (was trying to get a user instead) moving prepareInputForClone before the addslashes_deep method Trying to get the date fields comparisons right Still working on date comparison maybe dates can't be compared ? turns out date is not outputing a date but a string ! Fixing the cloning issue Removing clone capability on profiles because rights are automatically unset after add and that might be a security issue updating test case adding more test cases and cloning capabilities working on tests trying to get more information on why a test fails updating cloning Fixing code identation empty line fixing Homogenization of cloning with the new method (removing calls to cloneItem methods for templates instanciation) Handling legacy cloning requests (calling add with id or _oldID set) Fixing code quality Adding @SInCE and @deprecated markers in the phpdoc Updating the CHANGELOG.md file Fix cs fix defition on Dashboard::clone rename method Fixing dashboard test
|
i've rebased+squashed the PR, I was not able to merge it from GH inteface |
|
due to lack of infrastructure no testing possible, sorry. |