/** * Trash view * * @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_trash($handler_id, array $args, array &$data) { midcom::get('auth')->require_admin_user(); midcom::get('cache')->content->no_cache(); $data['view_title'] = $this->_l10n->get('trash'); midcom::get('head')->set_pagetitle($data['view_title']); $data['types'] = array(); foreach (midcom_connection::get_schema_types() as $type) { if (substr($type, 0, 2) == '__') { continue; } if (class_exists('midgard_reflector_object')) { // In Midgard2 we can have objects that don't // have metadata. These should not be shown // in trash. $ref = new midgard_reflector_object($type); if (!$ref->has_metadata_class($type)) { debug_add("{$type} has no metadata, skipping", MIDCOM_LOG_DEBUG); continue; } } $qb = new midgard_query_builder($type); $qb->include_deleted(); $qb->add_constraint('metadata.deleted', '=', true); $data['types'][$type] = $qb->count(); } // Set the breadcrumb data $this->add_breadcrumb('__mfa/asgard/', $this->_l10n->get('midgard.admin.asgard')); $this->add_breadcrumb('__mfa/asgard/trash/', $this->_l10n->get('trash')); }
public function _on_execute() { debug_add('called!'); $cut_off = mktime(23, 59, 59, date('n'), date('j') - $GLOBALS['midcom_config']['cron_purge_deleted_after'], date('Y')); foreach (midcom_connection::get_schema_types() as $mgdschema) { if (substr($mgdschema, 0, 2) == '__') { continue; } debug_add("Processing class {$mgdschema}"); $qb = new midgard_query_builder($mgdschema); $qb->add_constraint('metadata.deleted', '<>', 0); $qb->add_constraint('metadata.revised', '<', gmdate('Y-m-d H:i:s', $cut_off)); $qb->include_deleted(); $qb->set_limit(500); $objects = $qb->execute(); unset($qb); if (!is_array($objects)) { debug_add("QB failed fatally on class {$mgdschema}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); continue; } $found = count($objects); $purged = 0; foreach ($objects as $obj) { if (!$obj->purge()) { debug_add("Failed to purge {$mgdschema} {$obj->guid}, deleted: {$obj->metadata->deleted}, revised: {$obj->metadata->revised}. errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); debug_print_r('Failed object', $obj); continue; } $purged++; } if ($found > 0) { debug_add("Found {$found} {$mgdschema} objects deleted before " . date('Y-m-d H:i:s', $cut_off) . ", purged {$purged}", MIDCOM_LOG_INFO); } else { debug_add("No {$mgdschema} objects deleted before " . date('Y-m-d H:i:s', $cut_off) . " found"); } } }
<?php function obj_cleanup(&$object) { if ($object->delete()) { $object->purge(); return true; } echo "Deletion failed for {$object->guid}, errstr: " . midcom_connection::get_error_string() . "<br>\n"; } echo "<h1>Starting tests</h1>\n"; while (@ob_end_flush()) { } foreach (midcom_connection::get_schema_types() as $mgdschema) { if (empty($mgdschema)) { continue; } flush(); $dummy = new $mgdschema(); $midcom_class = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($dummy); if (empty($midcom_class)) { continue; } if (!midcom::get('dbclassloader')->load_mgdschema_class_handler($midcom_class) || !class_exists($midcom_class)) { echo "<h2>ERROR: Could not load handler for {$midcom_class}</h2>\n"; continue; } echo "<h2>Testing {$midcom_class}</h2>\n"; if (isset($empty)) { unset($empty); }
/** * Object editing view * * @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_welcome($handler_id, array $args, array &$data) { $data['schema_types'] = array_diff(midcom_connection::get_schema_types(), $this->_config->get('skip_in_filter')); $data['view_title'] = $this->_l10n->get('asgard'); midcom::get('head')->set_pagetitle($data['view_title']); if (isset($_POST['execute_mass_action'])) { if (!empty($_POST['selections']) && isset($_POST['mass_action'])) { $method_name = "_mass_{$_POST['mass_action']}"; $this->{$method_name}($_POST['selections']); } } $data['revised'] = array(); if (isset($_REQUEST['revised_after'])) { $data['revised_after'] = $_REQUEST['revised_after']; if ($data['revised_after'] != 'any') { $data['revised_after'] = date('Y-m-d H:i:s\\Z', $_REQUEST['revised_after']); } $data['review_by'] = null; if ($this->_config->get('enable_review_dates') && isset($_REQUEST['review_by']) && $_REQUEST['review_by'] != 'any') { $data['review_by'] = (int) $_REQUEST['review_by']; } $data['type_filter'] = null; if (isset($_REQUEST['type_filter']) && $_REQUEST['type_filter'] != 'any') { $data['type_filter'] = $_REQUEST['type_filter']; } $data['only_mine'] = false; if (isset($_REQUEST['only_mine']) && $_REQUEST['only_mine'] == 1) { $data['only_mine'] = $_REQUEST['only_mine']; } $data['revised'] = $this->_list_revised($data['revised_after'], $data['review_by'], $data['type_filter'], $data['only_mine']); } // else // { // $data['revised_after'] = date('Y-m-d H:i:s\Z', mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'))); // } midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . '/jQuery/jquery.tablesorter.pack.js'); midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . '/midgard.admin.asgard/jquery.batch_process.js'); $this->add_stylesheet(MIDCOM_STATIC_URL . '/midgard.admin.asgard/tablewidget.css'); $this->_populate_toolbar(); }
/** * Resolves the "root level" classes, used by get_root_classes() * * @return array of classnames (or false on critical failure) */ private static function _resolve_root_classes() { $root_exceptions_notroot = midcom_baseclasses_components_configuration::get('midcom.helper.reflector', 'config')->get('root_class_exceptions_notroot'); // Safety against misconfiguration if (!is_array($root_exceptions_notroot)) { debug_add("config->get('root_class_exceptions_notroot') did not return array, invalid configuration ??", MIDCOM_LOG_ERROR); $root_exceptions_notroot = array(); } $root_classes = array(); foreach (midcom_connection::get_schema_types() as $schema_type) { if (substr($schema_type, 0, 2) == '__') { continue; } if (in_array($schema_type, $root_exceptions_notroot)) { // Explicitly specified to not be root class, skip all heuristics continue; } // Class extensions mapping $schema_type = midcom_helper_reflector::class_rewrite($schema_type); // Make sure we only add classes once if (in_array($schema_type, $root_classes)) { // Already listed continue; } $parent = midgard_object_class::get_property_parent($schema_type); if (!empty($parent)) { // type has parent set, thus cannot be root type continue; } $dba_class = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($schema_type); if (!$dba_class) { // Not a MidCOM DBA object, skip continue; } $root_classes[] = $schema_type; } unset($root_exceptions_notroot); $root_exceptions_forceroot = midcom_baseclasses_components_configuration::get('midcom.helper.reflector', 'config')->get('root_class_exceptions_forceroot'); // Safety against misconfiguration if (!is_array($root_exceptions_forceroot)) { debug_add("config->get('root_class_exceptions_forceroot') did not return array, invalid configuration ??", MIDCOM_LOG_ERROR); $root_exceptions_forceroot = array(); } if (!empty($root_exceptions_forceroot)) { foreach ($root_exceptions_forceroot as $schema_type) { if (!class_exists($schema_type)) { // Not a valid class debug_add("Type {$schema_type} has been listed to always be root class, but the class does not exist", MIDCOM_LOG_WARN); continue; } if (in_array($schema_type, $root_classes)) { // Already listed continue; } $root_classes[] = $schema_type; } } usort($root_classes, 'strnatcmp'); return $root_classes; }
private function _initialize_from_reflector() { $matching_type = false; $matched_types = array(); foreach (midcom_connection::get_schema_types() as $schema_type) { $pos = strpos($schema_type, $this->clever_class); if ($pos !== false) { $matched_types[] = $schema_type; } } if (count($matched_types) == 1) { $matching_type = $matched_types[0]; } else { if ($this->clever_class == 'event') { $this->creation_default_key = 'title'; } else { if ($this->clever_class == 'person') { $matching_type = 'midgard_person'; } else { if (count($matched_types) > 0) { $matching_type = $matched_types[0]; } } } } if (!$matching_type) { debug_add("no matches found for {$this->clever_class}!"); return false; } $midcom_reflector = new midcom_helper_reflector($matching_type); $labels = array(); $dummy_object = new $matching_type(); $type_fields = array_keys(get_object_vars($dummy_object)); unset($type_fields['metadata']); foreach ($type_fields as $key) { if (in_array($key, array('title', 'firstname', 'lastname', 'name', 'email', 'start', 'end', 'location'))) { if (!in_array($key, $labels)) { $labels[] = $key; } } } if (empty($labels)) { $label_properties = $midcom_reflector->get_label_property(); if (is_array($label_properties)) { foreach ($label_properties as $key) { if (!in_array($key, array('id', 'guid'))) { if (!in_array($key, $labels)) { $labels[] = $key; } } } } } $this->class = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($matching_type); $this->component = midcom::get('dbclassloader')->get_component_for_class($matching_type); if (empty($this->constraints)) { $this->constraints = array(); } if (empty($this->searchfields)) { $this->searchfields = $midcom_reflector->get_search_properties(); if (empty($this->searchfields)) { //TODO: Special rules for objects that need them } } if (empty($this->orders)) { $this->orders = array(); } $reflection_l10n = $midcom_reflector->get_component_l10n(); if (empty($this->result_headers)) { $this->result_headers = array(); foreach ($labels as $label) { $header = array(); $header['title'] = $reflection_l10n->get($label); $header['name'] = $label; $this->result_headers[] = $header; } if (empty($this->result_headers)) { //Special rules for objects that need them } } if ($this->creation_mode_enabled && empty($this->creation_default_key)) { $this->creation_default_key = $this->result_headers[0]['name']; } }
/** * Simple helper to check whether we are dealing with a MgdSchema or MidCOM DBA * object or a subclass thereof. * * @param object $object The object to check * @return boolean true if this is a MgdSchema object, false otherwise. */ function is_mgdschema_object($object) { // Sometimes we might get class string instead of an object if (is_string($object)) { $classname = $object; $object = new $classname(); } if ($this->is_midcom_db_object($object)) { return true; } // First, try the quick way if (in_array(get_class($object), midcom_connection::get_schema_types())) { return true; } // Then, do a thorough scan foreach (midcom_connection::get_schema_types() as $mgdschema_class) { if (is_a($object, $mgdschema_class)) { return true; } } return false; }