private function _load_datamanager() { $schemadb_person = midcom_helper_datamanager2_schema::load_database($this->_config->get('schemadb_person')); $this->_datamanager = new midcom_helper_datamanager2_datamanager($schemadb_person); $this->_datamanager->set_schema($this->_master->get_person_schema($this->_contact)); $this->_datamanager->set_storage($this->_contact); }
/** * Internal helper, loads the datamanager for the current type. Any error triggers a 500. */ public function _load_datamanager($schemadb) { if (empty($this->_schema)) { throw new midcom_error('Export schema ($this->_schema) must be defined, hint: do it in "_load_schemadb"'); } $this->_datamanager = new midcom_helper_datamanager2_datamanager($schemadb); if (!$this->_datamanager || !$this->_datamanager->set_schema($this->_schema)) { throw new midcom_error("Failed to create a DM2 instance for schemadb schema '{$this->_schema}'."); } }
/** * Sets the current datamanager instance to the storage object given, which may either * be a MidCOM DBA object (which is encapsulated by a midgard datamanager storage instance). * * You must load a schema database before actually * * @param object &$storage A reference to either an initialized datamanager, an initialized * storage backend or to a DBA compatible class instance. * @param string $schema This is an optional schema name that should be used to edit the * storage object. If it is null, the controller will try to autodetect the schema * to use by using the datamanager's autoset_storage interface. */ function set_storage(&$storage, $schema = null) { if (count($this->schemadb) == 0) { throw new midcom_error('You cannot set a storage object for a DM2 controller object without loading a schema database previously.'); } if ($storage instanceof midcom_helper_datamanager2_datamanager) { $this->datamanager = $storage; } else { if ($storage instanceof midcom_helper_datamanager2_storage || midcom::get('dbclassloader')->is_midcom_db_object($storage)) { $this->datamanager = new midcom_helper_datamanager2_datamanager($this->schemadb); if ($schema === null) { if (!$this->datamanager->autoset_storage($storage)) { debug_print_r('We got this storage object:', $storage); throw new midcom_error('Failed to automatically create a datamanager instance for a storage object or a MidCOM type. See the debug level log for more information.'); } } else { if (!$this->datamanager->set_schema($schema)) { debug_add("Tried to set the schema {$schema}"); debug_print_r('We got this storage object:', $storage); throw new midcom_error('Failed to set the autocreated datamanager\'s schema. See the debug level log for more information.'); } if (!$this->datamanager->set_storage($storage)) { debug_add("Tried to set the schema {$schema}"); debug_print_r('We got this storage object:', $storage); throw new midcom_error('Failed to set the autocreated datamanager\'s storage object. See the debug level log for more information.'); } } } else { debug_print_r('Storage object passed was:', $storage); throw new midcom_error('You must pass either a datamanager subclass, an initialized storage encapsulation or a MidCOM DBA object'); } } }
/** * Object display * * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. * @return boolean Indicating success. */ public function _handler_delete($handler_id, array $args, array &$data) { $this->_load_object($args[0]); $this->_object->require_do('midgard:delete'); midcom::get('auth')->require_user_do('midgard.admin.asgard:manage_objects', null, 'midgard_admin_asgard_plugin'); $type = $this->_object->__mgdschema_class_name__; $relocate_url = $type; $cancel_url = "__mfa/asgard/object/{$this->_request_data['default_mode']}/{$this->_object->guid}/"; $class_extends = $this->_config->get('class_extends'); if (is_array($class_extends) && array_key_exists($type, $class_extends)) { $relocate_url = $class_extends[$type]; } // Redirect person deletion to user management if (is_a($this->_object, 'midcom_db_person')) { $relocate_url = "../asgard_midcom.admin.user/"; $cancel_url = "__mfa/asgard_midcom.admin.user/edit/{$args[0]}/"; } $this->_prepare_request_data(); $this->_load_schemadb(); $this->_datamanager = new midcom_helper_datamanager2_datamanager($this->_schemadb); $this->_datamanager->set_schema('object'); if (!$this->_datamanager->set_storage($this->_object)) { throw new midcom_error("Failed to create a DM2 instance for object {$this->_object->guid}."); } if (array_key_exists('midgard_admin_asgard_deleteok', $_REQUEST)) { // Deletion confirmed. $parent = $this->_object->get_parent(); if (array_key_exists('midgard_admin_asgard_disablercs', $_REQUEST)) { $this->_object->_use_rcs = false; } if (!$this->_object->delete_tree()) { throw new midcom_error("Failed to delete object {$args[0]}, last Midgard error was: " . midcom_connection::get_error_string()); } if (is_a($this->_object, 'midcom_db_style') || is_a($this->_object, 'midcom_db_element')) { mgd_cache_invalidate(); } // Update the index $indexer = midcom::get('indexer'); $indexer->delete($this->_object->guid); if ($parent) { return new midcom_response_relocate(midcom_connection::get_url('self') . "__mfa/asgard/object/{$data['default_mode']}/{$parent->guid}/"); } return new midcom_response_relocate(midcom_connection::get_url('self') . "__mfa/asgard/" . $relocate_url); } if (array_key_exists('midgard_admin_asgard_deletecancel', $_REQUEST)) { // Redirect to default object mode page. return new midcom_response_relocate($cancel_url); } midgard_admin_asgard_plugin::bind_to_object($this->_object, $handler_id, $data); // Add Thickbox midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . '/midgard.admin.asgard/object_browser.js'); midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . '/jQuery/thickbox/jquery-thickbox-3.1.pack.js'); $this->add_stylesheet(MIDCOM_STATIC_URL . '/jQuery/thickbox/thickbox.css', 'screen'); midcom::get('head')->add_jscript('var tb_pathToImage = "' . MIDCOM_STATIC_URL . '/jQuery/thickbox/loadingAnimation.gif"'); // Add jQuery file for the checkbox operations midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . '/midgard.admin.asgard/jquery-copytree.js'); midcom::get('head')->add_jscript('jQuery(document).ready(function(){jQuery("#midgard_admin_asgard_copytree").tree_checker();})'); }
/** * Loads the DM2 view of an object. * * @param midcom_baseclasses_components_handler &$handler The handler from which we were called * @param midcom_core_dbaobject &$object The object to display * @return array The get_content_html output for the requested object */ public static function get_view_controller(midcom_helper_datamanager2_interfaces_view &$handler, &$object) { $schemadb = $handler->load_schemadb(); $datamanager = new midcom_helper_datamanager2_datamanager($schemadb); $datamanager->set_schema($handler->get_schema_name()); if (!$datamanager->set_storage($object)) { throw new midcom_error("Failed to create a DM2 instance for object {$object->guid}."); } return $datamanager; }
public function test_set_storage() { $filename = 'file:/../test/midcom/helper/datamanager2/__files/schemadb_invoice.inc'; $schemadb = midcom_helper_datamanager2_schema::load_database($filename); $dm = new midcom_helper_datamanager2_datamanager($schemadb); $dm->set_schema(); $invoice = $this->create_object('org_openpsa_invoices_invoice_dba'); $this->assertTrue($dm->set_storage($invoice)); $this->assertTrue(is_a($dm->storage, 'midcom_helper_datamanager2_storage_midgard')); $this->assertTrue($dm->set_storage($dm->storage)); }