/** * Loads the temporary object identified by the argument from the DB, verifies * ownership (using the midgard:owner privilege) and returns the instance. * * The object timestamp is updated implicitly by the temporary object class. * * Objects which have exceeded their lifetime will no longer be returned for * security reasons. * * @param int $id The temporary object ID to load. * @return midcom_core_temporary_object The associated object or null in case that it * is unavailable. */ function request_object($id) { if (!$id) { debug_add("Invalid argument, may not evaluate to false", MIDCOM_LOG_INFO); debug_print_r('Got this argument:', $id); return null; } $tmp = new midcom_core_temporary_object((int) $id); if (!$tmp->can_do('midgard:owner')) { debug_add("The current user does not have owner privileges on the temporary object {$id}, denying access.", MIDCOM_LOG_INFO); debug_print_r('Got this object:', $tmp); return null; } // Check if the object has timeouted already. $timeout = time() - $GLOBALS['midcom_config']['midcom_temporary_resource_timeout']; if ($tmp->timestamp < $timeout) { debug_add("The temporary object {$id} has exceeded its maximum lifetime, rejecting access and dropping it", MIDCOM_LOG_INFO); debug_print_r("Object was:", $tmp); $tmp->delete(); return null; } // Update the object timestamp $tmp->update(); return $tmp; }
public function _on_execute() { midcom::get('dbclassloader')->load_classes('midcom', 'core_classes.inc', null, true); $qb = midcom_core_temporary_object::new_query_builder(); $qb->add_constraint('timestamp', '<', time() - $GLOBALS['midcom_config']['midcom_temporary_resource_timeout']); $qb->set_limit(500); $result = $qb->execute(); foreach ($result as $tmp) { if (!$tmp->delete()) { // Print and log error $msg = "Failed to delete temporary object {$tmp->id}, last Midgard error was: " . midcom_connection::get_error_string(); $this->print_error($msg); debug_add($msg, MIDCOM_LOG_ERROR); debug_print_r('Tried to delete this object:', $tmp); } else { debug_add("Deleted temporary object {$tmp->id}."); } } }