/** * Find all old temporary reports and clear them. */ public function _on_execute() { debug_add('_on_execute called'); midcom::get('auth')->request_sudo('net.nemein.tag'); $qb_tags = net_nemein_tag_tag_dba::new_query_builder(); $tags = $qb_tags->execute_unchecked(); if (!is_array($tags)) { // QB error midcom::get('auth')->drop_sudo(); return; } foreach ($tags as $tag) { debug_add("Processing tag #{$tag->id} ('{$tag->tag}')"); $qb_links = net_nemein_tag_link_dba::new_query_builder(); $qb_links->add_constraint('tag', '=', $tag->id); $count = $qb_links->count_unchecked(); if ($count === false) { // QB error, skip debug_add("There was QB level error, skip rest of the checks"); continue; } if ($count > 0) { // Tag has links, skip debug_add("Tag has links to it, do not clean"); continue; } debug_add("Cleaning dangling tag #{$tag->id} ('{$tag->tag}')", MIDCOM_LOG_INFO); if (!$tag->delete()) { debug_add("Could not delete dangling tag #{$tag->id} ('{$tag->tag}'), errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); } } debug_add('done'); midcom::get('auth')->drop_sudo(); return; }
function get_label() { $mc = net_nemein_tag_tag_dba::new_collector('id', $this->tag); $tag_guids = $mc->get_values('tag'); foreach ($tag_guids as $guid) { return net_nemein_tag_handler::tag_link2tagname($guid, $this->value, $this->context); } return $this->guid; }
* Handler for tag autocomplete widget * * @package net.nemein.tag * @author The Midgard Project, http://www.midgard-project.org * @copyright The Midgard Project, http://www.midgard-project.org * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License */ $response = new midcom_response_xml(); $response->status = 0; // Make sure we have search term if (!isset($_REQUEST['search'])) { $response->errstr = "Search term not defined"; $response->send(); } $search = str_replace('*', '%', $_REQUEST['search']); $qb = net_nemein_tag_tag_dba::new_query_builder(); $qb->add_constraint('tag', 'like', $search); $qb->add_order('tag', 'ASC'); $results = $qb->execute(); if ($results === false) { $response->errstr = "Error when executing QB"; $response->send(); } $response->status = 1; $response->errstr = ''; $items = array('tag'); echo " <results>\n"; foreach ($results as $object) { $items['tag'][] = $object->tag; } $response->results = $items;
private function _check_duplicates() { $qb = net_nemein_tag_tag_dba::new_query_builder(); if ($this->id) { $qb->add_constraint('id', '<>', $this->id); } $qb->add_constraint('tag', '=', $this->tag); return $qb->count_unchecked(); }
/** * Move all objects connected to a tag to another * * @param string $from Tag to move from * @param string $to Tag to move to * @param boolean $delete Whether to delete the from tag * @return boolean indicating success */ public static function merge_tags($from, $to, $delete = true) { $from_tag = net_nemein_tag_tag_dba::get_by_tag($from); if (!$from_tag || !$from_tag->guid) { return false; } $to_tag = net_nemein_tag_tag_dba::get_by_tag($to); if (!$to_tag || !$to_tag->guid) { // Create new one $to_tag = new net_nemein_tag_tag_dba(); $to_tag->tag = $to; if (!$to_tag->create()) { return false; } } $qb = net_nemein_tag_link_dba::new_query_builder(); $qb->add_constraint('tag', '=', $from_tag->id); $tag_links = $qb->execute(); foreach ($tag_links as $tag_link) { $tag_link->tag = $to_tag->id; $tag_link->update(); } if ($delete) { $from_tag->delete(); } return true; }