/** * 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; }
* 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(); }
/** * Lists all known tags * * @return array list of tags and urls, tag is key, url is value */ public static function get_tags() { $tags = array(); $qb = net_nemein_tag_tag_dba::new_query_builder(); $qb->add_constraint('metadata.navnoentry', '=', 0); $db_tags = $qb->execute(); if (!is_array($db_tags)) { return false; } foreach ($db_tags as $tag) { $tags[$tag->tag] = $tag->url; } return $tags; }