Ejemplo n.º 1
0
 /**
  * Handle the message copying interface
  *
  * @return boolean Indicating success
  */
 public function _handler_copy($handler_id, array $args, array &$data)
 {
     $this->_topic->require_do('midgard:create');
     $this->_message = new org_openpsa_directmarketing_campaign_message_dba($args[0]);
     $guid = $args[0];
     $this->_schemadb = midcom_helper_datamanager2_schema::load_database($this->_config->get('schemadb_message_copy'));
     $this->_controller = midcom_helper_datamanager2_controller::create('nullstorage');
     $this->_controller->schemadb =& $this->_schemadb;
     $this->_controller->initialize();
     $data['targets'] = array();
     switch ($this->_controller->process_form()) {
         case 'save':
             $copy = new midcom_helper_reflector_copy();
             $campaigns = $this->_controller->datamanager->types['campaign']->convert_to_storage();
             $copy_objects = array();
             foreach ($campaigns as $campaign_id) {
                 try {
                     $campaign = new org_openpsa_directmarketing_campaign_dba($campaign_id);
                 } catch (midcom_error $e) {
                     continue;
                 }
                 $new_object = $copy->copy_object($this->_message->guid, $campaign);
                 $guid = $new_object->guid;
                 // Store for later use
                 $copy_objects[] = $new_object;
             }
             if (count($copy_objects) > 1) {
                 $data['targets'] =& $copy_objects;
                 break;
             }
             // Fall through
         // Fall through
         case 'cancel':
             return new midcom_response_relocate("message/{$guid}/");
     }
     midcom::get('head')->set_pagetitle($this->_message->title);
     $this->bind_view_to_object($this->_message);
     $this->_update_breadcrumb_line($handler_id);
 }
Ejemplo n.º 2
0
 /**
  * Copy an object tree. Both source and parent may be liberally filled. Source can be either
  * MgdSchema or MidCOM db object or GUID of the object and parent can be
  *
  * - MgdSchema object
  * - MidCOM db object
  * - predefined target array (@see get_target_properties())
  * - ID or GUID of the object
  * - left empty to copy as a parentless object
  *
  * This method is self-aware and will refuse to perform any infinite loops (e.g. to copy
  * itself to its descendant, copying itself again and again and again).
  *
  * Eventually this method will return the first root object that was created, i.e. the root
  * of the new tree.
  *
  * @param mixed $source        GUID or MgdSchema object that will be copied
  * @param mixed $parent        MgdSchema or MidCOM db object, predefined array or ID of the parent object
  * @param array $exclude       IDs that will be excluded from the copying
  * @param boolean $parameters  Switch to determine if the parameters should be copied
  * @param boolean $metadata    Switch to determine if the metadata should be copied (excluding created and published)
  * @param boolean $attachments Switch to determine if the attachments should be copied (creates only a new link, doesn't duplicate the content)
  * @return mixed               False on failure, newly created MgdSchema root object on success
  */
 public static function copy_object_tree($source, $parent, $exclude = array(), $parameters = true, $metadata = true, $attachments = true)
 {
     $copy = new midcom_helper_reflector_copy();
     $copy->source =& $source;
     $copy->target =& $parent;
     $copy->parameters = $parameters;
     $copy->metadata = $metadata;
     $copy->attachments = $attachments;
     if (!$copy->execute()) {
         return false;
     }
     return $copy->get_object();
 }
Ejemplo n.º 3
0
 private function _process_copy($target)
 {
     // Get the target information of the form
     $target['id'] = $this->_controller->datamanager->types[$target['parent']]->convert_to_storage();
     $this->_controller->datamanager->types['metadata']->convert_to_storage();
     $this->_controller->datamanager->types['attachments']->convert_to_storage();
     $this->_controller->datamanager->types['privileges']->convert_to_storage();
     $copy = new midcom_helper_reflector_copy();
     $copy->source = $this->_object;
     // Set the target - if available
     if (isset($target['id']) && $target['id']) {
         $link_properties = $target['reflector']->get_link_properties();
         $parent = $target['parent'];
         if (!$link_properties || !isset($link_properties[$parent])) {
             throw new midcom_error('Failed to construct the target class object');
         }
         $class_name = $link_properties[$parent]['class'];
         $target_object = new $class_name($target['id']);
         if ($target_object && $target_object->guid) {
             $copy->target = $target_object;
         } else {
             throw new midcom_error('Failed to get the target object');
         }
     }
     // Copying of parameters, metadata and such
     $copy->parameters = $this->_controller->datamanager->types['parameters']->convert_to_storage();
     $copy->metadata = $this->_controller->datamanager->types['metadata']->convert_to_storage();
     $copy->attachments = $this->_controller->datamanager->types['attachments']->convert_to_storage();
     $copy->privileges = $this->_controller->datamanager->types['privileges']->convert_to_storage();
     if ($this->_request_data['handler_id'] === '____mfa-asgard-object_copy_tree') {
         foreach ($_POST['all_objects'] as $guid) {
             if (!in_array($guid, $_POST['selected'])) {
                 $copy->exclude[] = $guid;
             }
         }
     } else {
         $copy->copy_tree = false;
     }
     if (!$copy->execute()) {
         debug_print_r('Copying failed with the following errors', $copy->errors, MIDCOM_LOG_ERROR);
         throw new midcom_error('Failed to successfully copy the object. Details in error level log');
     }
     $new_object = $copy->get_object();
     if (!$new_object || !$new_object->guid) {
         throw new midcom_error('Failed to copy the object');
     }
     if ($this->_request_data['handler_id'] === '____mfa-asgard-object_copy_tree') {
         midcom::get('uimessages')->add($this->_l10n->get('midgard.admin.asgard'), $this->_l10n->get('copy successful, you have been relocated to the root of the new object tree'));
     } else {
         midcom::get('uimessages')->add($this->_l10n->get('midgard.admin.asgard'), $this->_l10n->get('copy successful, you have been relocated to the new object'));
     }
     return $new_object;
 }