/** * 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(); }
/** * Query all specific component for objects related to given object * * See org_openpsa_relatedto_suspect::find_links_object() for details */ public static function find_links_object_component($object, $component, $defaults = false) { $ret = array(); //Make sure we can load and access the component if (midcom::get('componentloader')->load_graceful($component)) { //We could not load the component/interface debug_add("could not load component {$component}", MIDCOM_LOG_ERROR); return $ret; } $interface = midcom::get('componentloader')->get_interface_class($component); if (!method_exists($interface, 'org_openpsa_relatedto_find_suspects')) { //Component does not wish to tell us anything debug_add("component {$component} does not support querying for suspects", MIDCOM_LOG_INFO); return $ret; } //Get components suspected links $interface->org_openpsa_relatedto_find_suspects($object, $defaults, $ret); //Filter out existing links foreach ($ret as $k => $linkdata) { if ($guid = $linkdata['link']->check_db(false)) { //Essentially same link already exists in db, remove from returned values debug_print_r("found matching link with {$guid} (skipping), our data:", $linkdata['link']); unset($ret[$k]); } } reset($ret); return $ret; }
/** * DM2 creation callback, binds to the current content topic. */ private function _create_product($title, $productgroup) { $product = new org_openpsa_products_product_dba(); $product->productGroup = $productgroup; $product->title = $title; if (!$product->create()) { debug_print_r('We operated on this object:', $product); return null; } // Generate URL name if ($product->code == '') { $product->code = midcom_helper_misc::generate_urlname_from_string($product->title); $tries = 0; $maxtries = 999; while (!$product->update() && $tries < $maxtries) { $product->code = midcom_helper_misc::generate_urlname_from_string($product->title); if ($tries > 0) { // Append an integer if products with same name exist $product->code .= sprintf("-%03d", $tries); } $tries++; } } $product->parameter('midcom.helper.datamanager2', 'schema_name', $this->_config->get('api_products_schema')); return $product; }
/** * DM2 creation callback, binds to the current content topic. */ private function _create_article($title) { $author = midcom::get('auth')->user->get_storage(); $article = new midcom_db_article(); $article->topic = $this->_content_topic->id; $article->title = $title; //Figure out author $article->author = $author->id; if (!$article->create()) { debug_print_r('We operated on this object:', $article); return null; } // Generate URL name if ($article->name == '') { $article->name = midcom_helper_misc::generate_urlname_from_string($article->title); $tries = 0; $maxtries = 999; while (!$article->update() && $tries < $maxtries) { $article->name = midcom_helper_misc::generate_urlname_from_string($article->title); if ($tries > 0) { // Append an integer if articles with same name exist $article->name .= sprintf("-%03d", $tries); } $tries++; } } $article->parameter('midcom.helper.datamanager2', 'schema_name', $this->_config->get('api_metaweblog_schema')); return $article; }
/** * Handle the moving of a group phase * * @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_move($handler_id, array $args, array &$data) { $data['group'] = new midcom_db_group($args[0]); // Get the prefix $data['prefix'] = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX); if (isset($_POST['f_cancel'])) { return new midcom_response_relocate("__mfa/asgard_midcom.admin.user/group/edit/{$data['group']->guid}/"); } if (isset($_POST['f_submit'])) { echo "<pre>\n"; print_r($_POST); echo "</pre>\n"; $data['group']->owner = (int) $_POST['midcom_admin_user_move_group']; if ($data['group']->update()) { midcom::get('uimessages')->add($this->_l10n->get('midcom.admin.user'), midcom::get('i18n')->get_string('updated', 'midcom')); return new midcom_response_relocate("__mfa/asgard_midcom.admin.user/group/edit/{$data['group']->guid}/"); } else { debug_add('Failed to update the group, last midcom_connection::get_error_string was ' . midgard_connection::get_error_string(), MIDCOM_LOG_ERROR); debug_print_r('We operated on this object', $data['group'], MIDCOM_LOG_ERROR); throw new midcom_error('Failed to update the group, see error level log for details'); } } $data['view_title'] = sprintf($this->_l10n->get('move %s'), $data['group']->official); midcom::get('head')->set_pagetitle($data['view_title']); $this->_update_breadcrumb($handler_id); }
/** * Start up the storage manager and bind it to a given MidgardObject. * The passed object must be a MidCOM DBA object, otherwise the system bails with * midcom_error. In this case, no automatic conversion is done, as this would * destroy the reference. * * @param midcom_helper_datamanager2_schema $schema The data schema to use for processing. * @param MidCOMDBAObject $object A reference to the DBA object to user for Data I/O. */ public function __construct($schema, $object) { parent::__construct($schema); if (!midcom::get('dbclassloader')->is_mgdschema_object($object)) { debug_print_r('Object passed:', $object); throw new midcom_error('The midgard storage backend requires a MidCOM DBA object.'); } $this->object = $object; }
/** * 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; }
/** * 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; }
/** * 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, 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, 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; }
/** * 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; }
/** * 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; }
/** * 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; }
function validate($value, $options = null) { debug_add('called'); debug_print_r('got value', $value); debug_print_r('got options', $options); if (!is_array($value) || empty($value)) { debug_add('value is not array or is empty'); return false; } debug_add('value is non-empty array'); return true; }
/** * 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; }
/** * 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->_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 _handler_create($handler_id, array $args, array &$data) { midcom::get('auth')->require_valid_user(); try { $this->_linked_object = midcom::get('dbfactory')->get_object_by_guid($args[0]); } catch (midcom_error $e) { debug_print_r('Passed guid does not exist. GUID :', $args[0]); } $this->_controller = $this->get_controller('create'); $this->_process_billing_form(); $this->_prepare_output('create'); }
function &dm2_create_callback(&$controller) { $this->_event = new fi_kilonkipinat_events_event_dba(); $this->_event->topic = $this->_request_data['content_topic']->id; if (!$this->_event->create()) { debug_push_class(__CLASS__, __FUNCTION__); debug_print_r('We operated on this object:', $this->_event); debug_pop(); $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to create a new event, cannot continue. Last Midgard error was: ' . midcom_application::get_error_string()); // This will exit. } return $this->_event; }
/** * This is what Datamanager calls to actually create a directory */ public function &dm2_create_callback(&$datamanager) { $topic = new org_openpsa_documents_directory(); $topic->up = $this->_request_data['directory']->id; $topic->component = 'org.openpsa.documents'; // Set the name by default $topic->name = midcom_helper_misc::generate_urlname_from_string($_POST['extra']); if (!$topic->create()) { debug_print_r('We operated on this object:', $topic); throw new midcom_error("Failed to create a new topic, cannot continue. Error: " . midcom_connection::get_error_string()); } $this->_request_data['directory'] = new org_openpsa_documents_directory($topic->id); return $topic; }
function &dm2_create_callback(&$controller) { $this->_jobgroup = new fi_kilonkipinat_account_jobhistory_jobgroup_dba(); $this->_jobgroup->_use_activitystream = false; $this->_use_activitystream = false; if (!$this->_jobgroup->create()) { debug_push_class(__CLASS__, __FUNCTION__); debug_print_r('We operated on this object:', $this->_jobgroup); debug_pop(); $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to create a new jobgroup, cannot continue. Last Midgard error was: ' . midcom_application::get_error_string()); // This will exit. } return $this->_jobgroup; }
/** * Returns the Parent of the Element. This is the style the element is assigned to. * * @return MidgardObject Parent object or null if there is none. */ function get_parent_guid_uncached() { if ($this->style == 0) { debug_print_r('Current element is:', $this); debug_add("The Style Element {$this->id} has its style member set to 0, this is a critical database inconsistency.", MIDCOM_LOG_INFO); return null; } try { $parent = new midcom_db_style($this->style); } catch (midcom_error $e) { debug_add("Could not load Style ID {$this->up} from the database, aborting.", MIDCOM_LOG_INFO); return null; } return $parent->guid; }
/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_page = new net_nemein_wiki_wikipage(); $this->_page->topic = $this->_topic->id; $this->_page->title = $this->_wikiword; $this->_page->author = midcom_connection::get_user(); // We can clear the session now $this->_request_data['session']->remove('wikiword'); if (!$this->_page->create()) { debug_print_r('We operated on this object:', $this->_page); throw new midcom_error('Failed to create a new page. Last Midgard error was: ' . midcom_connection::get_error_string()); } $this->_page = new net_nemein_wiki_wikipage($this->_page->id); return $this->_page; }
/** * Set the content topic to use. This will check against the configuration setting 'symlink_topic'. */ private function _determine_content_topic() { $guid = $this->_config->get('symlink_topic'); if (is_null($guid)) { // No symlink topic // Workaround, we should talk to a DBA object automatically here in fact. $this->_content_topic = midcom_db_topic::get_cached($this->_topic->id); return; } $this->_content_topic = midcom_db_topic::get_cached($guid); // Validate topic. if ($this->_content_topic->component != 'net.nehmer.static') { debug_print_r('Retrieved topic was:', $this->_content_topic); throw new midcom_error('Symlink content topic is invalid, see the debug level log for details.'); } }
private function _load_document($guid) { $document = new org_openpsa_documents_document_dba($guid); // if the document doesn't belong to the current topic, we don't // show it, because otherwise folder-based permissions would be useless if ($document->topic != $this->_topic->id) { throw new midcom_error_notfound("The document '{$guid}' could not be found in this folder."); } // Load the document to datamanager if (!$this->_datamanager->autoset_storage($document)) { debug_print_r('DM instance was:', $this->_datamanager); debug_print_r('Object to be used was:', $document); throw new midcom_error('Failed to initialize the datamanager, see debug level log for more information.'); } return $document; }
/** * This is what Datamanager calls to actually create a group */ public function &dm2_create_callback(&$datamanager) { $this->_group = new org_openpsa_contacts_group_dba(); if ($this->_type == 'organization' && $this->_parent_group) { $this->_group->owner = (int) $this->_parent_group->id; } else { $root_group = org_openpsa_contacts_interface::find_root_group(); $this->_group->owner = (int) $root_group->id; } $this->_group->name = time(); if (!$this->_group->create()) { debug_print_r('We operated on this object:', $this->_group); throw new midcom_error("Failed to create a new group. Error: " . midcom_connection::get_error_string()); } return $this->_group; }
/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_productlink = new org_openpsa_products_product_link_dba(); if (isset($_POST['productGroup'])) { $this->_request_data['up'] = (int) $_POST['productGroup']; } $this->_productlink->productGroup = $this->_request_data['up']; if (isset($_POST['product'])) { $this->_request_data['product'] = (int) $_POST['product']; } $this->_productlink->product = $this->_request_data['product']; if (!$this->_productlink->create()) { debug_print_r('We operated on this object:', $this->_productlink); throw new midcom_error("Failed to create a new productlink under product group #{$this->_request_data['up']}. Error: " . midcom_connection::get_error_string()); } return $this->_productlink; }
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}."); } } }