Skip to content

Bug: clone_attachments assignes an attachment to a wrong object #10

Description

@Viki-H02

Are you willing to create (at a later stage) a PR for that?

No

iTop version

3.2.2-1

Module/extension version

1.4.6

PHP version

8.3.6

Reproduction procedure

Bug: clone_attachments assignes an attachment to a wrong object

Summary

We are using the Object Copier to convert a UserRequest into an Incident.

There is a bug when the source UserRequest contains both:

  • related_request_list
  • attachments

In this case, the attachments are not attached to the newly created Incident. Instead, they are incorrectly attached to the first of the related requests.

If the same conversion is performed with a UserRequest that has attachments but no related requests, the attachments are copied correctly to the new Incident.


Steps to reproduce

  1. Add object-copier rule to config
'incident_from_userrequest' => 
		  array (
		    'source_scope' => 'SELECT UserRequest WHERE status NOT IN (\'closed\',\'resolved\')',
		    'allowed_profiles' => 'Administrator',
		    'menu_label' => 'Transfrom UserRequest into Incident...',
		    'menu_tooltip' => 'This UserRequest will be closed and a new Incident created.',
		    'form_label' => 'Create an incident from UserRequest: %1$s',
		    'report_label' => 'Incident created from UserRequest: %1$s',
		    'dest_class' => 'Incident',
		    'preset' => 
		    array (
		      1 => 'clone(org_id,caller_id,origin,description,impact,urgency)',
		      2 => 'set(private_log,Incident was transformed from "$this->hyperlink()$")',
		      3 => 'copy(related_request_list, related_request_list)',
		      4 => 'clone_attachments()',
		    ),
		    'retrofit' => 
		    array (
		    ),
		  ),
  1. Create a new UserRequest. Add at least one related request and at least one attachment to the same UserRequest.
Image Image Image
  1. Start the conversion from the menu using the Object Copier action.
Image
  1. Fill in the required fields and create the new Incident.
Image
  1. Check the related Request tab of the new incident.

Result: The related requests are shown correctly.

Image
  1. Check the Attachments tab of the new Incident.

Result: The Attachments tab is empty.

Image
  1. Open the related request.

Result: The attachment was incorrectly attached to the related request.

Image
  1. Check the database entry for the attachment.

Result: The attachment is linked to the related request instead of the new Incident.

Image

Additional information (if needed)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions