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(); }
/** * @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); }
/** * 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; }
/** * Handle the AJAX request * * @todo This function is unused */ public function _handle_ajax() { $update_succeeded = false; $errstr = null; $user = new midcom_db_person($this->_request_data['user']->id); if (array_key_exists('org_openpsa_calendar_filters_add', $_POST)) { try { $target = new midcom_db_person($_POST['org_openpsa_calendar_filters_add']); $update_succeeded = $user->parameter('org_openpsa_calendar_show', $_POST['org_openpsa_calendar_filters_add'], 1); } catch (midcom_error $e) { $e->log(); } } else { if (array_key_exists('org_openpsa_calendar_filters_remove', $_POST)) { try { $target = new midcom_db_person($_POST['org_openpsa_calendar_filters_remove']); $update_succeeded = $user->parameter('org_openpsa_calendar_show', $_POST['org_openpsa_calendar_filters_remove'], ''); } catch (midcom_error $e) { $e->log(); } } } $errstr = midcom_connection::get_error_string(); $response = new midcom_response_xml(); $response->result = $update_succeeded; $response->status = $errstr; $response->send(); //This will exit. }
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(); }
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(); }
/** * 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; }
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.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(); }
/** * 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 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; }
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"; }
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()); }
/** * 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; }
/** * 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; }
/** * 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. */ 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; }
/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_link = new net_nehmer_static_link_dba(); $this->_link->topic = $this->_topic->id; if (!$this->_link->create()) { debug_print_r('We operated on this object:', $this->_link); throw new midcom_error('Failed to create a new article. Last Midgard error was: ' . midcom_connection::get_error_string()); } return $this->_link; }
/** * 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, 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; }
/** * 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, 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; }
private function _import_group($groupdata) { // Convert fields from latin-1 to MidCOM charset (usually utf-8) foreach ($groupdata as $key => $value) { $groupdata[$key] = iconv('ISO-8859-1', midcom::get('i18n')->get_current_charset(), $value); } $group = null; $new = false; if (isset($groupdata['code'])) { $qb = org_openpsa_products_product_group_dba::new_query_builder(); $qb->add_constraint('code', '=', (string) $groupdata['code']); $groups = $qb->execute(); if (count($groups) > 0) { // Match found, use it $group = $groups[0]; $this->_request_data['import_status']['already_created']++; } } if (!$group) { // We didn't have group matching the code in DB. Create a new one. $group = new org_openpsa_products_product_group_dba(); if (!$group->create()) { debug_add("Failed to create group, reason " . midcom_connection::get_error_string()); $this->_request_data['import_status']['failed_create']++; return false; // This will skip to next } $new = true; $this->_request_data['import_status']['created_new']++; } if (isset($groupdata['org_openpsa_products_import_parent_group'])) { // Validate and set parent group $qb = org_openpsa_products_product_group_dba::new_query_builder(); $qb->add_constraint('code', '=', (string) $groupdata['org_openpsa_products_import_parent_group']); $parents = $qb->execute(); if (count($parents) == 0) { // Invalid parent, delete $group->delete(); $this->_request_data['import_status']['failed_create']++; return false; } $group->up = $parents[0]->id; $groupdata['up'] = $parents[0]->id; $group->update(); } if (!$this->_datamanager_process($groupdata, $group)) { if ($new) { $group->delete(); $this->_request_data['import_status']['failed_create']++; } return false; } $this->_groups_processed[$group->code] = $group; return $group; }
/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_product = new org_openpsa_products_product_dba(); $this->_request_data['up'] = $controller->formmanager->get_value('productGroup'); $this->_product->productGroup = $this->_request_data['up']; if (!$this->_product->create()) { debug_print_r('We operated on this object:', $this->_product); throw new midcom_error("Failed to create a new product under product group #{$this->_request_data['up']}. Error: " . midcom_connection::get_error_string()); } return $this->_product; }
/** * This is what Datamanager calls to actually create a query */ function &dm2_create_callback(&$controller) { $query = new org_openpsa_reports_query_dba(); $query->component = $this->_component; if (!$query->create()) { debug_print_r('We operated on this object:', $query); throw new midcom_error("Failed to create a new project. Error: " . midcom_connection::get_error_string()); } $this->_request_data['query'] = $query; return $query; }
/** * This class creates a new temporary object for use with the application. * The id member of the object is used in the future to reference it in * request and release operations. The GUID of the object should not be used * for further references. * * In case the temporary object cannot be created, midcom_error is thrown. * * All existing privileges (created by the DBA core) will be dropped, so that * privileges can be created at will by the application (f.x. using DM(2) * privilege types). Since EVERYONE owns all temporary objects using magic * default privileges, full access is ensured. * * @return midcom_core_temporary_object The newly created object. */ function create_object() { midcom::get('auth')->require_user_do('midgard:create', null, 'midcom_core_temporary_object'); $tmp = new midcom_core_temporary_object(); if (!$tmp->create()) { debug_print_r('Tried to create this object:', $tmp); throw new midcom_error('Failed to create a new temporary object, last Midgard error was: ' . midcom_connection::get_error_string()); } $tmp->unset_all_privileges(); return $tmp; }
/** * This is what Datamanager calls to actually create a document */ public function &dm2_create_callback(&$datamanager) { $document = new org_openpsa_documents_document_dba(); $document->topic = $this->_request_data['directory']->id; $document->orgOpenpsaAccesstype = org_openpsa_core_acl::ACCESS_WGPRIVATE; if (!$document->create()) { debug_print_r('We operated on this object:', $document); throw new midcom_error("Failed to create a new document. Error: " . midcom_connection::get_error_string()); } $this->_document = $document; return $document; }
/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_message = new org_openpsa_directmarketing_campaign_message_dba(); // duh ? (copy-paste artefact ??) $this->_message->campaign = $this->_request_data['campaign']->id; $this->_message->orgOpenpsaObtype = $this->_schemadb[$this->_schema]->customdata['org_openpsa_directmarketing_messagetype']; if (!$this->_message->create()) { debug_print_r('We operated on this object:', $this->_message); throw new midcom_error('Failed to create a new message. Last Midgard error was: ' . midcom_connection::get_error_string()); } return $this->_message; }
/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_deliverable = new org_openpsa_sales_salesproject_deliverable_dba(); $this->_deliverable->salesproject = $this->_salesproject->id; $this->_deliverable->state = org_openpsa_sales_salesproject_deliverable_dba::STATUS_NEW; $this->_deliverable->orgOpenpsaObtype = $this->_product->delivery; if (!$this->_deliverable->create()) { debug_print_r('We operated on this object:', $this->_deliverable); throw new midcom_error('Failed to create a new deliverable. Last Midgard error was: ' . midcom_connection::get_error_string()); } return $this->_deliverable; }
public function remove_member($guid) { $qb = midcom_db_member::new_query_builder(); $qb->add_constraint('gid', '=', $this->id); $qb->add_constraint('uid.guid', '=', $guid); $results = $qb->execute(); foreach ($results as $result) { if (!$result->delete()) { throw new midcom_error('Failed to remove member: ' . midcom_connection::get_error_string()); } } }