/** * @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_edit($handler_id, array $args, array &$data) { $this->_component_name = $args[0]; if (!midcom::get('componentloader')->is_installed($this->_component_name)) { throw new midcom_error_notfound("Component {$this->_component_name} is not installed."); } $componentpath = midcom::get('componentloader')->path_to_snippetpath($this->_component_name); // Load and parse the global config $cfg = midcom_baseclasses_components_configuration::read_array_from_file("{$componentpath}/config/config.inc"); if (!$cfg) { // hmmm... that should never happen $cfg = array(); } $this->_libconfig = new midcom_helper_configuration($cfg); // Go for the sitewide default $cfg = midcom_baseclasses_components_configuration::read_array_from_file("/etc/midgard/midcom/{$this->_component_name}}/config.inc"); if ($cfg !== false) { $this->_libconfig->store($cfg, false); } // Finally, check the sitegroup config $cfg = midcom_baseclasses_components_configuration::read_array_from_snippet("{$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}/{$this->_component_name}/config"); if ($cfg !== false) { $this->_libconfig->store($cfg, false); } $this->_controller = $this->get_controller('nullstorage'); switch ($this->_controller->process_form()) { case 'save': if ($this->_save_configuration()) { mgd_cache_invalidate(); midcom::get('uimessages')->add($this->_l10n->get('host configuration'), $this->_l10n->get('settings saved successfully') . $this->_codeinit->id, 'ok'); } else { midcom::get('uimessages')->add($this->_l10n->get('host configuration'), sprintf($this->_l10n->get('failed to save settings, reason %s')), 'error'); } // *** FALL-THROUGH *** // *** FALL-THROUGH *** case 'cancel': return new midcom_response_relocate('__mfa/asgard_midcom.admin.libconfig/edit/' . $this->_component_name); } $data['controller'] =& $this->_controller; $this->_update_breadcrumb(); midcom::get('head')->set_pagetitle($data['view_title']); }
/** * Helper method for undeleting objects * * @param Array $guids * @param string $type * @return boolean Indicating success * @todo We should only undelete parameters & attachments deleted inside some small window of the main objects delete */ public static function undelete($guids, $type) { $undeleted_size = 0; if (!is_array($guids)) { $guids = array($guids); } $stats = array(); foreach ($guids as $guid) { $object = midcom_helper_reflector::get_object($guid, $type); if (is_null($object)) { // Purged, skip debug_add("Object identified with GUID {$guid} is purged, cannot undelete", MIDCOM_LOG_INFO); continue; } $undeleted = false; if ($object->undelete($guid)) { $undeleted = true; // refresh $object = midcom::get('dbfactory')->get_object_by_guid($guid); $undeleted_size += $object->metadata->size; } if (!$undeleted) { debug_add("Failed to undelete object with GUID {$guid} errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); } else { $parent = $object->get_parent(); if ($parent && $parent->guid) { // Invalidate parent from cache so content caches have chance to react midcom::get('cache')->invalidate($parent->guid); } // Invalidate Midgard pagecache if we touched style/page element if (function_exists('mgd_cache_invalidate') && (is_a($object, 'midcom_db_element') || is_a($object, 'midcom_db_pageelement'))) { mgd_cache_invalidate(); } } $stats[$guid] = $undeleted; // FIXME: We should only undelete parameters & attachments deleted inside some small window of the main objects delete $undeleted_size += self::undelete_parameters($guid); $undeleted_size += self::undelete_attachments($guid); //FIXME: are we sure we want to undelete all children here unconditionally, shouldn't it be left as UI decision ?? // List all deleted children $children_types = midcom_helper_reflector_tree::get_child_objects($object, true); if (empty($children_types)) { continue; } foreach ($children_types as $type => $children) { $child_guids = array(); foreach ($children as $child) { if ($child->metadata->deleted) { $child_guids[] = $child->guid; } } $undeleted_size += self::undelete($child_guids, $type); } } return $undeleted_size; }
/** * Invalidate all caches completely. * * Use this, if you have, f.x. changes in the layout. The URL function * midcom-cache-invalidate will trigger this function. */ function invalidate_all() { foreach ($this->_unload_queue as $name) { debug_add("Invalidating the cache module {$name} completely."); $this->_modules[$name]->invalidate_all(); } // Invalidate Midgard cache too mgd_cache_invalidate(); }
/** * 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();})'); }