/** * Function to process the notify date in the passed formdata of the datamanger * creates/edits/deletes the corresponding at_entry if needed * * @param array $formdata The Formdata of the datamanager containing the notify_date * @param org_openpsa_sales_salesproject_deliverable_dba $deliverable The current deliverable */ public function process_notify_date($formdata, org_openpsa_sales_salesproject_deliverable_dba $deliverable) { //check if there is already an at_entry $mc_entry = org_openpsa_relatedto_dba::new_collector('toGuid', $deliverable->guid); $mc_entry->add_constraint('fromClass', '=', 'midcom_services_at_entry_dba'); $mc_entry->add_constraint('toClass', '=', 'org_openpsa_sales_salesproject_deliverable_dba'); $mc_entry->add_constraint('toExtra', '=', 'notify_at_entry'); $entry_keys = $mc_entry->get_values('fromGuid'); //check date if (!$formdata['notify']->is_empty()) { $notification_entry = null; if (count($entry_keys) == 0) { $notification_entry = new midcom_services_at_entry_dba(); $notification_entry->create(); //relatedto from notifcation to deliverable org_openpsa_relatedto_plugin::create($notification_entry, 'midcom.services.at', $deliverable, 'org.openpsa.sales', false, array('toExtra' => 'notify_at_entry')); } else { //get guid of at_entry foreach ($entry_keys as $key => $entry) { //check if related at_entry exists try { $notification_entry = new midcom_services_at_entry_dba($entry); } catch (midcom_error $e) { //relatedto links to a non-existing at_entry - so create a new one an link to it $notification_entry = new midcom_services_at_entry_dba(); $notification_entry->create(); $relatedto = new org_openpsa_relatedto_dba($key); $relatedto->fromGuid = $notification_entry->guid; $relatedto->update(); } break; } } $notification_entry->start = $formdata['notify']->value->format('U'); $notification_entry->method = 'new_notification_message'; $notification_entry->component = 'org.openpsa.sales'; $notification_entry->arguments = array('deliverable' => $deliverable->guid); $notification_entry->update(); } else { //void date - so delete existing at_entrys for this notify_date foreach ($entry_keys as $key => $empty) { try { $notification_entry = new midcom_services_at_entry_dba($mc_entry->get_subkey($key, 'fromGuid')); //check if related at_entry exists & delete it $notification_entry->delete(); } catch (midcom_error $e) { $e->log(); } } } }
public function testCRUD() { $args = array('arg1' => 'test', 'arg2' => 12); midcom::get('auth')->request_sudo('midcom.services.at'); $entry = new midcom_services_at_entry_dba(); $entry->arguments = $args; $stat = $entry->create(); $this->assertTrue($stat); //@todo For some reason, this throws a "Critical internal error". Needs to be investigated //$this->register_object($entry); $this->assertEquals($args, $entry->arguments); $this->assertEquals(midcom_services_at_entry_dba::SCHEDULED, $entry->status); $args['arg2'] = 11; $entry->arguments = $args; $stat = $entry->update(); $this->assertTrue($stat); $this->assertEquals($args, $entry->arguments); $stat = $entry->delete(); $this->assertTrue($stat); midcom::get('auth')->drop_sudo(); }
/** * Displays a deliverable edit view. * * Note, that the deliverable for non-index mode operation is automatically determined in the can_handle * phase. * * If create privileges apply, we relocate to the index creation deliverable * * @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_edit($handler_id, array $args, array &$data) { $this->_deliverable = new org_openpsa_sales_salesproject_deliverable_dba($args[0]); $this->_deliverable->require_do('midgard:update'); $this->_load_controller(); switch ($this->_controller->process_form()) { case 'save': $formdata = $this->_controller->datamanager->types; if (!empty($formdata['at_entry']->value)) { $entry = new midcom_services_at_entry_dba((int) $formdata['at_entry']->value); $next_cycle = 0; if (isset($formdata['next_cycle']) && !$formdata['next_cycle']->is_empty()) { $next_cycle = (int) $formdata['next_cycle']->value->format('U'); } //@todo If next_cycle is changed to be in the past, should we check if this would lead //to multiple runs immediately? i.e. if you set a monthly subscriptions next cycle to //one year in the past, this would trigger twelve consecutive runs and maybe //the user needs to be warned about that... if ($next_cycle != $entry->start) { $entry->start = $next_cycle; $entry->update(); } } $this->_master->process_notify_date($formdata, $this->_deliverable); // Reindex the deliverable //$indexer = midcom::get('indexer'); //org_openpsa_sales_viewer::index($this->_controller->datamanager, $indexer, $this->_content_topic); // *** FALL-THROUGH *** // Reindex the deliverable //$indexer = midcom::get('indexer'); //org_openpsa_sales_viewer::index($this->_controller->datamanager, $indexer, $this->_content_topic); // *** FALL-THROUGH *** case 'cancel': return new midcom_response_relocate("deliverable/{$this->_deliverable->guid}/"); } // Add toolbar items org_openpsa_helpers::dm2_savecancel($this); $this->_prepare_request_data($handler_id); $this->bind_view_to_object($this->_deliverable, $this->_request_data['controller']->datamanager->schema->name); $this->_update_breadcrumb_line($handler_id); midcom::get('head')->set_pagetitle(sprintf($this->_l10n_midcom->get('edit %s'), $this->_deliverable->title)); }