Skip to content

Commit

Permalink
Allow copying root-only entities recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Jan 7, 2025
1 parent 14e22d9 commit 84b8493
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
18 changes: 5 additions & 13 deletions lib/midcom/helper/reflector/copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,10 @@ class midcom_helper_reflector_copy
/**
* Get the parent property for overriding it
*/
public static function get_parent_property(midcom_core_dbaobject $object) : string
public static function get_parent_property(midcom_core_dbaobject $object) : ?string
{
$parent = midgard_object_class::get_property_parent($object->__mgdschema_class_name__);
if (!$parent) {
$parent = midgard_object_class::get_property_up($object->__mgdschema_class_name__);

if (!$parent) {
throw new midcom_error('Failed to get the parent property for copying');
}
}

return $parent;
return midgard_object_class::get_property_parent($object->__mgdschema_class_name__)
?? midgard_object_class::get_property_up($object->__mgdschema_class_name__);
}

/**
Expand Down Expand Up @@ -146,8 +138,8 @@ public function copy_object(midcom_core_dbaobject $source, ?midcom_core_dbaobjec
$target->$name = $value;
}

if ($this->recursive) {
$parent_property = self::get_parent_property($source);
if ( $this->recursive
&& $parent_property = self::get_parent_property($source)) {

// Copy the link to parent
if (!empty($parent->guid)) {
Expand Down
6 changes: 4 additions & 2 deletions lib/midgard/admin/asgard/handler/object/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,10 @@ public function _handler_copy(Request $request, string $handler_id, string $guid
if ($handler_id === 'object_copy_tree') {
$parent = midcom_helper_reflector_copy::get_parent_property($this->_object);
$this->_load_schemadb($this->_object, [$parent], true);
// Change the name for the parent field
$this->schemadb->get_first()->get_field($parent)['title'] = $this->_l10n->get('choose the target');
if ($parent) {
// Change the name for the parent field
$this->schemadb->get_first()->get_field($parent)['title'] = $this->_l10n->get('choose the target');
}
} else {
$parent = null;
$this->_load_schemadb($this->_object, [false], true);
Expand Down

0 comments on commit 84b8493

Please sign in to comment.