/** * 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 get_qb($field = null, $direction = 'ASC') { $qb = midcom_services_at_entry_dba::new_query_builder(); $qb->add_constraint('method', '=', 'new_subscription_cycle'); $qb->add_constraint('component', '=', 'org.openpsa.sales'); $qb->add_constraint('status', '=', midcom_services_at_entry_dba::SCHEDULED); if (!is_null($field)) { $qb->add_order($field, $direction); } return $qb; }
/** * Loads all entries that need to be processed and processes them. * * @todo FIXME: refactor to use more modern MidCOM interfaces and better sanity-checking */ public function _on_execute() { $qb = midcom_services_at_entry_dba::new_query_builder(); $qb->add_constraint('start', '<=', time()); $qb->begin_group('OR'); $qb->add_constraint('host', '=', midcom_connection::get('host')); $qb->add_constraint('host', '=', 0); $qb->end_group(); $qb->add_constraint('status', '=', midcom_services_at_entry_dba::SCHEDULED); $qb->set_limit((int) $this->_config->get('limit_per_run')); midcom::get('auth')->request_sudo('midcom.services.at'); $qbret = $qb->execute(); midcom::get('auth')->drop_sudo(); if (empty($qbret)) { debug_add('Got empty resultset, exiting'); return; } foreach ($qbret as $entry) { debug_add("Processing entry #{$entry->id}\n"); //Avoid double-execute in case of long runs $entry->status = midcom_services_at_entry_dba::RUNNING; midcom::get('auth')->request_sudo('midcom.services.at'); $entry->update(); midcom::get('auth')->drop_sudo(); midcom::get('componentloader')->load($entry->component); $args = $entry->arguments; $args['midcom_services_at_entry_object'] = $entry; $interface = midcom::get('componentloader')->get_interface_class($entry->component); $method = $entry->method; if (!is_callable(array($interface, $method))) { $error = "\$interface->{$method}() is not callable"; $this->print_error($error); debug_add($error, MIDCOM_LOG_ERROR); debug_add('$interface is ' . get_class($interface)); debug_print_r('$args', $args); //PONDER: Delete instead ? (There is currently nothing we do with failed entries) $entry->status = midcom_services_at_entry_dba::FAILED; midcom::get('auth')->request_sudo('midcom.services.at'); $entry->update(); midcom::get('auth')->drop_sudo(); continue; } $mret = $interface->{$method}($args, $this); if ($mret !== true) { $error = "\$interface->{$method}(\$args, \$this) returned '{$mret}', errstr: " . midcom_connection::get_error_string(); $this->print_error($error); debug_add($error, MIDCOM_LOG_ERROR); debug_add('$interface is ' . get_class($interface)); debug_print_r('$args', $args); //PONDER: Delete instead ? (There is currently nothing we do with failed entries) $entry->status = midcom_services_at_entry_dba::FAILED; midcom::get('auth')->request_sudo('midcom.services.at'); $entry->update(); midcom::get('auth')->drop_sudo(); } else { midcom::get('auth')->request_sudo('midcom.services.at'); $entry->delete(); midcom::get('auth')->drop_sudo(); } } }
/** * Function to disable account for time period given in config * * @return boolean - indicates success */ public function disable_account() { $this->_account = midcom_core_account::get($this->_person); $timeframe_minutes = $this->_config->get('password_block_timeframe_min'); if ($timeframe_minutes == 0) { return false; } $release_time = time() + $timeframe_minutes * 60; $args = array('guid' => $this->_person->guid, 'parameter_name' => 'org_openpsa_user_blocked_account', 'password' => 'account_password'); $qb = midcom_services_at_entry_dba::new_query_builder(); $qb->add_constraint('argumentsstore', '=', serialize($args)); $qb->add_constraint('status', '=', midcom_services_at_entry_dba::SCHEDULED); $results = $qb->execute(); if (sizeof($results) > 0) { //the account is already blocked, so we just extend the block's duration $entry = $results[0]; $entry->start = $release_time; return $entry->update(); } if (!midcom_services_at_interface::register($release_time, 'org.openpsa.user', 'reopen_account', $args)) { throw new midcom_error("Failed to register interface for re_open the user account, last Midgard error was: " . midcom_connection::get_error_string()); } $this->_person->set_parameter("org_openpsa_user_blocked_account", "account_password", $this->_account->get_password()); $this->_account->set_password('', false); return $this->_account->save(); }
private function _get_scheduled_invoices() { $invoices = array(); $at_qb = midcom_services_at_entry_dba::new_query_builder(); $at_qb->add_constraint('method', '=', 'new_subscription_cycle'); $at_qb->add_constraint('component', '=', 'org.openpsa.sales'); $at_entries = $at_qb->execute(); foreach ($at_entries as $at_entry) { try { $deliverable = org_openpsa_sales_salesproject_deliverable_dba::get_cached($at_entry->arguments['deliverable']); if ($deliverable->continuous || $deliverable->start < $this->_request_data['end'] && $deliverable->end > $this->_request_data['start']) { $invoices = array_merge($invoices, $this->_get_invoices_for_subscription($deliverable, $at_entry)); } } catch (midcom_error $e) { } } $invoices = array_filter($invoices, array($this, '_filter_by_date')); usort($invoices, array($this, '_sort_by_date')); return $invoices; }
/** * @depends testGenerate_safe_password */ public function testDisable_account() { $accounthelper = new org_openpsa_user_accounthelper(self::$_user); $account = midcom_core_account::get(self::$_user); $password = $account->get_password(); midcom::get('auth')->request_sudo('org.openpsa.user'); $this->assertTrue($accounthelper->disable_account()); $account = midcom_core_account::get(self::$_user); $this->assertEquals('', $account->get_password()); $this->assertEquals($password, self::$_user->get_parameter('org_openpsa_user_blocked_account', 'account_password')); $args = array('guid' => self::$_user->guid, 'parameter_name' => 'org_openpsa_user_blocked_account', 'password' => 'account_password'); $qb = midcom_services_at_entry_dba::new_query_builder(); $qb->add_constraint('argumentsstore', '=', serialize($args)); $result = $qb->execute(); $this->register_objects($result); $this->assertEquals(1, sizeof($result)); $account->set_password($accounthelper->generate_safe_password()); $account->save(); midcom::get('auth')->drop_sudo(); }