/** * Registers a job to the AT service. * * @param int $start Timestamp after which the job is run * @param string $component The name of the component which should run the job * @param string $method The method in interface class to call to run the job * @param array $args Arguments array for the method * @return boolean Indicating success/failure in registering the job */ public static function register($start, $component, $method, $args) { $entry = new midcom_services_at_entry_dba(); $entry->start = $start; $entry->component = $component; $entry->method = $method; $entry->arguments = $args; return $entry->create(); }
/** * 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(); }
private function _create_at_entry($cycle_number, $start) { $args = array('deliverable' => $this->_deliverable->guid, 'cycle' => $cycle_number); $at_entry = new midcom_services_at_entry_dba(); $at_entry->start = $start; $at_entry->component = 'org.openpsa.sales'; $at_entry->method = 'new_subscription_cycle'; $at_entry->arguments = $args; if ($at_entry->create()) { debug_add('AT entry for cycle ' . $cycle_number . ' created'); org_openpsa_relatedto_plugin::create($at_entry, 'midcom.services.at', $this->_deliverable, 'org.openpsa.sales'); return true; } else { debug_add('AT registration failed, last midgard error was: ' . midcom_connection::get_error_string(), MIDCOM_LOG_WARN); return false; } }