public function generate_image($type, $filter_chain) { try { $original = new midcom_db_attachment($this->attachment); } catch (midcom_error $e) { $e->log(); return false; } $found_derived = false; try { $derived = new midcom_db_attachment($this->{$type}); $found_derived = true; } catch (midcom_error $e) { $derived = new midcom_db_attachment(); $derived->parentguid = $original->parentguid; $derived->title = $original->title; $derived->mimetype = $original->mimetype; $derived->name = $type . '_' . $original->name; } $imagefilter = new midcom_helper_imagefilter($original); if (!$imagefilter->process_chain($filter_chain)) { throw new midcom_error('Image processing failed'); } if (!$found_derived) { if (!$derived->create()) { throw new midcom_error('Failed to create derived image: ' . midcom_connection::get_error_string()); } $this->{$type} = $derived->id; $this->update(); } return $imagefilter->write($derived); }
public function testCRUD() { midcom::get('auth')->request_sudo('org.openpsa.projects'); $task = new org_openpsa_projects_task_dba(); if (extension_loaded('midgard2')) { $stat = $task->create(); $this->assertFalse($stat); } $project = $this->create_object('org_openpsa_projects_project'); $task->project = $project->id; $stat = $task->create(); $this->assertTrue($stat, midcom_connection::get_error_string()); $this->register_object($task); $this->assertEquals(ORG_OPENPSA_OBTYPE_TASK, $task->orgOpenpsaObtype); $task->refresh(); $this->assertEquals('Task #' . $task->id, $task->title); $this->assertEquals(org_openpsa_projects_task_status_dba::PROPOSED, $task->status); $task->title = 'Test Task'; $stat = $task->update(); $this->assertTrue($stat); $this->assertEquals('Test Task', $task->title); $stat = $task->delete(); $this->assertTrue($stat); midcom::get('auth')->drop_sudo(); }
/** * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. */ public function _handler_delete($handler_id, array $args, array &$data) { midcom::get('auth')->require_user_do('org.openpsa.user:manage', null, 'org_openpsa_user_interface'); $this->_group = new midcom_db_group($args[0]); if (array_key_exists('org_openpsa_user_deleteok', $_POST)) { $delete_succeeded = $this->_group->delete(); $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX); if ($delete_succeeded) { // Update the index $indexer = midcom::get('indexer'); $indexer->delete($this->_group->guid); return new midcom_response_relocate(''); } else { // Failure, give a message midcom::get('uimessages')->add($this->_l10n->get('org.openpsa.user'), $this->_l10n->get("failed to delete group, reason") . ' ' . midcom_connection::get_error_string(), 'error'); return new midcom_response_relocate($prefix . 'group/' . $this->_group->guid . '/'); } } $data['view'] = midcom_helper_datamanager2_handler::get_view_controller($this, $this->_group); $data['group'] = $this->_group; org_openpsa_widgets_tree::add_head_elements(); $this->add_breadcrumb('groups/', $this->_l10n->get('groups')); $this->add_breadcrumb('', sprintf($this->_l10n_midcom->get('delete %s'), $this->_group->get_label())); $this->bind_view_to_object($this->_group); }
public function testCRUD() { midcom::get('auth')->request_sudo('org.openpsa.invoices'); $data = new org_openpsa_invoices_billing_data_dba(); $data->linkGuid = self::$_contact->guid; $data->useContactAddress = true; $stat = $data->create(); $this->assertTrue($stat, midcom_connection::get_error_string()); $this->register_object($data); $parent = $data->get_parent(); $this->assertEquals($parent->guid, self::$_contact->guid); self::$_contact->refresh(); $this->assertEquals(self::$_contact->street, $data->street); $data->vat = 12; $data->due = 12; $stat = $data->update(); $this->assertTrue($stat); self::$_contact->refresh(); $invoice = new org_openpsa_invoices_invoice_dba(); $invoice->customerContact = self::$_contact->id; $invoice_data = $invoice->get_billing_data(); $this->assertEquals($data->guid, $invoice_data->guid); $this->assertEquals($data->vat, $invoice->get_default('vat')); $this->assertEquals($data->due, $invoice->get_default('due')); $stat = $data->delete(); $this->assertTrue($stat); midcom::get('auth')->drop_sudo(); }
/** * Don't save aerodrome if another aerodrome is in same place or exists with same ICAO */ public function _on_creating() { if ($this->longitude && $this->latitude) { $qb = org_routamc_positioning_aerodrome_dba::new_query_builder(); $qb->add_constraint('longitude', '=', $this->longitude); $qb->add_constraint('latitude', '=', $this->latitude); $qb->set_limit(1); $matches = $qb->execute_unchecked(); if (count($matches) > 0) { // We don't need to save duplicate entries return false; } } if (!empty($this->icao)) { $qb = org_routamc_positioning_aerodrome_dba::new_query_builder(); $qb->add_constraint('icao', '=', $this->icao); $qb->set_limit(1); $matches = $qb->execute_unchecked(); if (count($matches) > 0) { // We don't need to save duplicate entries midcom_connection::set_error(MGD_ERR_DUPLICATE); return false; } } return true; }
public function _handler_csv($handler_id, array $args, array &$data) { midcom::get('auth')->require_valid_user(); midcom::get()->disable_limits(); $this->_load_datamanager($this->_load_schemadb($handler_id, $args, $data)); $this->_objects = $this->_load_data($handler_id, $args, $data); if (!isset($args[0]) || empty($args[0])) { //We do not have filename in URL, generate one and redirect $fname = preg_replace('/[^a-z0-9-]/i', '_', strtolower($this->_topic->extra)) . '_' . date('Y-m-d') . '.csv'; if (strpos(midcom_connection::get_url('uri'), '/', strlen(midcom_connection::get_url('uri')) - 2)) { return new midcom_response_relocate(midcom_connection::get_url('uri') . $fname); } else { return new midcom_response_relocate(midcom_connection::get_url('uri') . "/{$fname}"); } } if (!isset($data['filename']) || $data['filename'] == '') { $data['filename'] = str_replace('.csv', '', $args[0]); } $this->_init_csv_variables(); midcom::get()->skip_page_style = true; // FIXME: Use global configuration //midcom::get('cache')->content->content_type($this->_config->get('csv_export_content_type')); midcom::get('cache')->content->content_type('application/csv'); _midcom_header('Content-Disposition: filename=' . $data['filename']); }
/** * Find hanging duplicate marks (that no longer point anywhere) and clear them */ public function _on_execute() { debug_add('_on_execute called'); if (!$this->_config->get('enable_duplicate_search')) { debug_add('Duplicate operations disabled, aborting', MIDCOM_LOG_INFO); return; } // Untill the FIXME below is handled we abort debug_add('Duplicate cleanup disabled since it needs code cleanup for 1.8 Midgfard, aborting', MIDCOM_LOG_ERROR); return; ignore_user_abort(); $qb = new midgard_query_builder('midgard_parameter'); $qb->add_constraint('domain', '=', 'org.openpsa.contacts.duplicates:possible_duplicate'); $qb->add_order('name', 'ASC'); $results = @$qb->execute(); foreach ($results as $param) { try { $obj = midcom::get('dbfactory')->get_object_by_guid($param->name); } catch (midcom_error $e) { debug_add("GUID {$param->name} points to nonexistent person, removing possible duplicate mark", MIDCOM_LOG_INFO); if (!$param->delete()) { debug_add("Failed to delete parameter {$param->guid}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); } } } debug_add('Done'); return; }
/** * Find all old send tokens and clear them. */ public function _on_execute() { //Disable limits, TODO: think if this could be done in smaller chunks to save memory. midcom::get()->disable_limits(); debug_add('_on_execute called'); $days = $this->_config->get('send_token_max_age'); if ($days == 0) { debug_add('send_token_max_age evaluates to zero, aborting'); return; } $th = time() - $days * 3600 * 24; $qb = org_openpsa_directmarketing_campaign_messagereceipt_dba::new_query_builder(); $qb->add_constraint('token', '<>', ''); $qb->add_constraint('timestamp', '<', $th); $qb->add_constraint('orgOpenpsaObtype', '=', org_openpsa_directmarketing_campaign_messagereceipt_dba::SENT); $ret = $qb->execute_unchecked(); if ($ret === false || !is_array($ret)) { //TODO: display some error ? return false; } if (empty($ret)) { debug_add('No results, returning early.'); return; } foreach ($ret as $receipt) { debug_add("clearing token '{$receipt->token}' from receipt #{$receipt->id}"); $receipt->token = ''; $stat = $receipt->update(); if (!$stat) { debug_add("FAILED to update receipt #{$receipt->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_WARN); } } debug_add('Done'); return; }
/** * 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')); }
/** * Find all old temporary reports and clear them. */ public function _on_execute() { //Disable limits, TODO: think if this could be done in smaller chunks to save memory. midcom::get()->disable_limits(); debug_add('_on_execute called'); $days = $this->_config->get('temporary_report_max_age'); if ($days == 0) { debug_add('temporary_report_max_age evaluates to zero, aborting'); return; } $th = time() - $days * 3600 * 24; $qb = org_openpsa_reports_query_dba::new_query_builder(); $qb->add_constraint('metadata.created', '<', $th); $qb->add_constraint('orgOpenpsaObtype', '=', ORG_OPENPSA_OBTYPE_REPORT_TEMPORARY); $ret = $qb->execute_unchecked(); if ($ret === false || !is_array($ret)) { //TODO: display some error ? return false; } if (empty($ret)) { debug_add('No results, returning early.'); return; } foreach ($ret as $query) { debug_add("removing temporary query #{$query->id}"); $stat = $query->delete(); if (!$stat) { debug_add("FAILED to delete query #{$query->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_WARN); } } debug_add('Done'); return; }
/** * Find all old temporary reports and clear them. */ public function _on_execute() { debug_add('_on_execute called'); midcom::get('auth')->request_sudo('net.nemein.tag'); $qb_tags = net_nemein_tag_tag_dba::new_query_builder(); $tags = $qb_tags->execute_unchecked(); if (!is_array($tags)) { // QB error midcom::get('auth')->drop_sudo(); return; } foreach ($tags as $tag) { debug_add("Processing tag #{$tag->id} ('{$tag->tag}')"); $qb_links = net_nemein_tag_link_dba::new_query_builder(); $qb_links->add_constraint('tag', '=', $tag->id); $count = $qb_links->count_unchecked(); if ($count === false) { // QB error, skip debug_add("There was QB level error, skip rest of the checks"); continue; } if ($count > 0) { // Tag has links, skip debug_add("Tag has links to it, do not clean"); continue; } debug_add("Cleaning dangling tag #{$tag->id} ('{$tag->tag}')", MIDCOM_LOG_INFO); if (!$tag->delete()) { debug_add("Could not delete dangling tag #{$tag->id} ('{$tag->tag}'), errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); } } debug_add('done'); midcom::get('auth')->drop_sudo(); return; }
/** * Handle the request for editing contact list * * @param String $handler_id Name of the request handler * @param array $args Variable arguments * @param array &$data Public request data, passed by reference */ public function _handler_edit($handler_id, array $args, array &$data) { midcom::get('auth')->require_valid_user(); // Get the current user $this->_person = new midcom_db_person(midcom_connection::get_user()); $this->_person->require_do('midgard:update'); // Load the controller $data['controller'] = $this->get_controller('simple', $this->_person); // Process the form switch ($data['controller']->process_form()) { case 'save': case 'cancel': if (isset($_GET['org_openpsa_calendar_returnurl'])) { $url = $_GET['org_openpsa_calendar_returnurl']; } else { $url = ''; } return new midcom_response_relocate($url); } // Add the breadcrumb pieces if (isset($_GET['org_openpsa_calendar_returnurl'])) { $this->add_breadcrumb($_GET['org_openpsa_calendar_returnurl'], $this->_l10n->get('calendar')); } $this->add_breadcrumb('filters/', $this->_l10n->get('choose calendars')); }
public function run($object) { if (!$object->delete()) { throw new \midcom_error("failed to delete " . get_class($object) . " #" . $object->id . ': ' . \midcom_connection::get_error_string()); } return array(); }
public function testCRUD() { midcom::get('auth')->request_sudo('org.openpsa.sales'); $deliverable = new org_openpsa_sales_salesproject_deliverable_dba(); $deliverable->salesproject = $this->_salesproject->id; $deliverable->plannedUnits = 2.5; $deliverable->pricePerUnit = 100; $stat = $deliverable->create(); $this->assertTrue($stat, midcom_connection::get_error_string()); $this->register_object($deliverable); $this->assertEquals($deliverable->price, 250); $parent = $deliverable->get_parent(); $this->assertEquals($parent->guid, $this->_salesproject->guid); $this->_salesproject->refresh(); $this->assertEquals($this->_salesproject->value, 250); $this->assertEquals($this->_salesproject->profit, 250); $deliverable->plannedUnits = 2; $stat = $deliverable->update(); $this->assertTrue($stat); $this->_salesproject->refresh(); $this->assertEquals($this->_salesproject->value, 200); $this->assertEquals($this->_salesproject->profit, 200); $stat = $deliverable->delete(); $this->assertTrue($stat); $this->_salesproject->calculate_price(); $this->assertEquals($this->_salesproject->value, 0); $this->assertEquals($this->_salesproject->profit, 0); midcom::get('auth')->drop_sudo(); }
/** * Loads all entries that need to be processed and processes them. */ public function _on_execute() { $qb = midcom_services_at_entry_dba::new_query_builder(); // (to be) start(ed) AND last touched over two days ago $qb->add_constraint('start', '<=', time() - 3600 * 24 * 2); $qb->begin_group('OR'); $qb->add_constraint('host', '=', midcom_connection::get('host')); $qb->add_constraint('host', '=', 0); $qb->end_group(); $qb->add_constraint('metadata.revised', '<=', date('Y-m-d H:i:s', time() - 3600 * 24 * 2)); $qb->add_constraint('status', '>=', midcom_services_at_entry_dba::RUNNING); midcom::get('auth')->request_sudo('midcom.services.at'); $qbret = $qb->execute(); if (empty($qbret)) { debug_add('Got empty resultset, exiting'); midcom::get('auth')->drop_sudo(); return; } foreach ($qbret as $entry) { debug_add("Deleting dangling entry #{$entry->id}\n", MIDCOM_LOG_INFO); debug_print_r("Entry #{$entry->id} dump: ", $entry); $entry->delete(); } midcom::get('auth')->drop_sudo(); }
public function _on_updating() { if ($this->_check_duplicates($this->code)) { midcom_connection::set_error(MGD_ERR_OBJECT_NAME_EXISTS); return false; } return true; }
public function _on_updating() { if (!$this->verify_can_reserve()) { midcom_connection::set_error(MGD_ERR_ACCESS_DENIED); return false; } return true; }
public function test_copy_from_file() { $attachment = $this->create_object('midcom_db_attachment', array('parentguid' => self::$_topic->guid)); $stat = $attachment->copy_from_file(self::$_filepath . 'attach.png'); $this->assertTrue($stat, midcom_connection::get_error_string()); $blob = new midgard_blob($attachment->__object); $this->assertFileEquals(self::$_filepath . 'attach.png', $blob->get_path()); }
public function _on_updating() { if (!$this->validate_code($this->code)) { midcom_connection::set_error(MGD_ERR_OBJECT_NAME_EXISTS); return false; } return true; }
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"; }
/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_tinyurl = new net_nemein_redirector_tinyurl_dba(); $this->_tinyurl->node = $this->_topic->guid; if (!$this->_tinyurl->create()) { throw new midcom_error('Failed to create a new TinyURL object. Last Midgard error was: ' . midcom_connection::get_error_string()); } return $this->_tinyurl; }
public function _on_creating() { $mc = self::new_collector('linkGuid', $this->linkGuid); if ($mc->count() > 0) { midcom_connection::set_error(MGD_ERR_DUPLICATE); return false; } return true; }
/** * Check if all the fields contain required information upon update * * @return boolean Indicating success */ public function _on_updating() { if (!$this->topic || !$this->article) { debug_add('Failed to update the link, either topic or article was undefined', MIDCOM_LOG_WARN); midcom_connection::set_error(MGD_ERR_ERROR); return false; } return true; }
/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_group = new org_openpsa_products_product_group_dba(); $this->_group->up = $this->_request_data['up']; if (!$this->_group->create()) { debug_print_r('We operated on this object:', $this->_group); throw new midcom_error('Failed to create a new product group. Last Midgard error was: ' . midcom_connection::get_error_string()); } return $this->_group; }
/** * This is what Datamanager calls to actually create a person */ public function &dm2_create_callback(&$datamanager) { $person = new org_openpsa_contacts_person_dba(); if (!$person->create()) { debug_print_r('We operated on this object:', $person); throw new midcom_error("Failed to create a new person, cannot continue. Error: " . midcom_connection::get_error_string()); } $this->_person =& $person; return $person; }
/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_campaign = new org_openpsa_directmarketing_campaign_dba(); $this->_campaign->node = $this->_topic->id; if (!$this->_campaign->create()) { debug_print_r('We operated on this object:', $this->_campaign); throw new midcom_error('Failed to create a new campaign. Last Midgard error was: ' . midcom_connection::get_error_string()); } return $this->_campaign; }
/** * DM2 creation callback, creates a new person and binds it to the selected group. * * Assumes Admin Privileges. */ public function &dm2_create_callback(&$controller) { // Create a new person $this->_person = new midcom_db_person(); if (!$this->_person->create()) { debug_print_r('We operated on this object:', $this->_person); throw new midcom_error('Failed to create a new person. Last Midgard error was: ' . midcom_connection::get_error_string()); } return $this->_person; }
/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_event = new org_openpsa_calendar_event_dba(); $this->_event->up = $this->_root_event->id; if (!$this->_event->create()) { debug_print_r('We operated on this object:', $this->_event); throw new midcom_error('Failed to create a new event. Last Midgard error was: ' . midcom_connection::get_error_string()); } return $this->_event; }
/** * Datamanager callback */ public function &dm2_create_callback(&$datamanager) { $billing_data = new org_openpsa_invoices_billing_data_dba(); $billing_data->linkGuid = $this->_linked_object->guid; if (!$billing_data->create()) { debug_print_r('We operated on this object:', $billing_data); throw new midcom_error("Failed to create a new billing_data. Error: " . midcom_connection::get_error_string()); } return $billing_data; }
/** * DM2 creation callback. */ function &dm2_create_callback(&$controller) { // Create a new group $this->_group = new midcom_db_group(); if (!$this->_group->create()) { debug_print_r('We operated on this object:', $this->_group); throw new midcom_error('Failed to create a new group. Last Midgard error was: ' . midcom_connection::get_error_string()); } return $this->_group; }