MDL-10956, convert blogs to use the same tags (and convert old tags)

This commit is contained in:
toyomoyo 2007-08-27 08:46:00 +00:00
parent d526725b8d
commit bd1f4559f7
9 changed files with 133 additions and 106 deletions

View File

@ -2,7 +2,7 @@
define('BLOGDEFAULTTIMEWITHIN', 90); define('BLOGDEFAULTTIMEWITHIN', 90);
define('BLOGDEFAULTNUMBEROFTAGS', 20); define('BLOGDEFAULTNUMBEROFTAGS', 20);
define('BLOGDEFAULTSORT', 'text'); define('BLOGDEFAULTSORT', 'name');
require_once($CFG->dirroot .'/blog/lib.php'); require_once($CFG->dirroot .'/blog/lib.php');
@ -38,7 +38,6 @@ class block_blog_tags extends block_base {
} }
} }
function get_content() { function get_content() {
global $CFG, $SITE, $COURSE, $USER; global $CFG, $SITE, $COURSE, $USER;
@ -71,19 +70,18 @@ class block_blog_tags extends block_base {
$this->content->text = ''; $this->content->text = '';
$this->content->footer = ''; $this->content->footer = '';
/// Get a list of tags /// Get a list of tags
$timewithin = $this->config->timewithin * 24 * 60 * 60; /// convert to seconds $timewithin = $this->config->timewithin * 24 * 60 * 60; /// convert to seconds
$sql = 'SELECT t.id, t.type, t.text, COUNT(DISTINCT bt.id) as ct '; $sql = 'SELECT t.id, t.tagtype, t.name, COUNT(DISTINCT ti.id) as ct ';
$sql .= "FROM {$CFG->prefix}tags t, {$CFG->prefix}blog_tag_instance bt, {$CFG->prefix}post p "; $sql .= "FROM {$CFG->prefix}tag t, {$CFG->prefix}tag_instance ti, {$CFG->prefix}post p ";
$sql .= 'WHERE t.id = bt.tagid '; $sql .= 'WHERE t.id = ti.tagid ';
$sql .= 'AND p.id = bt.entryid '; $sql .= 'AND p.id = ti.itemid ';
$sql .= 'AND (p.publishstate = \'site\' or p.publishstate=\'public\') '; $sql .= 'AND (p.publishstate = \'site\' or p.publishstate=\'public\') ';
$sql .= "AND bt.timemodified > {$timewithin} "; $sql .= "AND ti.timemodified > {$timewithin} ";
$sql .= 'GROUP BY t.id, t.type, t.text '; $sql .= 'GROUP BY t.id, t.tagtype, t.name ';
$sql .= 'ORDER BY ct DESC, t.text ASC'; $sql .= 'ORDER BY ct DESC, t.name ASC';
if ($tags = get_records_sql($sql, 0, $this->config->numberoftags)) { if ($tags = get_records_sql($sql, 0, $this->config->numberoftags)) {
@ -111,7 +109,7 @@ class block_blog_tags extends block_base {
$size = 20 - ( (int)((($currenttag - 1) / $totaltags) * 20) ); $size = 20 - ( (int)((($currenttag - 1) / $totaltags) * 20) );
} }
$tag->class = "$tag->type s$size"; $tag->class = "$tag->tagtype s$size";
$etags[] = $tag; $etags[] = $tag;
} }
@ -159,7 +157,7 @@ class block_blog_tags extends block_base {
$this->content->text .= '<li><a href="'.$link.'" '. $this->content->text .= '<li><a href="'.$link.'" '.
'class="'.$tag->class.'" '. 'class="'.$tag->class.'" '.
'title="'.get_string('numberofentries','blog',$tag->ct).'">'. 'title="'.get_string('numberofentries','blog',$tag->ct).'">'.
$tag->text.'</a></li> '; $tag->name.'</a></li> ';
} }
$this->content->text .= "\n</ul>\n"; $this->content->text .= "\n</ul>\n";
@ -186,7 +184,7 @@ class block_blog_tags extends block_base {
/// set up sort select field /// set up sort select field
$sort = array(); $sort = array();
$sort['text'] = get_string('tagtext', 'blog'); $sort['name'] = get_string('tagtext', 'blog');
$sort['id'] = get_string('tagdatelastused', 'blog'); $sort['id'] = get_string('tagdatelastused', 'blog');
@ -197,9 +195,7 @@ class block_blog_tags extends block_base {
} else { } else {
notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me())); notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me()));
} }
} }
} }
function blog_tags_sort($a, $b) { function blog_tags_sort($a, $b) {

View File

@ -2,6 +2,7 @@
require_once('../config.php'); require_once('../config.php');
include_once('lib.php'); include_once('lib.php');
include_once($CFG->dirroot.'/tag/lib.php');
$action = required_param('action', PARAM_ALPHA); $action = required_param('action', PARAM_ALPHA);
$id = optional_param('id', 0, PARAM_INT); $id = optional_param('id', 0, PARAM_INT);
@ -118,12 +119,12 @@ switch ($action) {
$post->action = $action; $post->action = $action;
$strformheading = get_string('updateentrywithid', 'blog'); $strformheading = get_string('updateentrywithid', 'blog');
if ($ptags = get_records_sql_menu("SELECT t.id, t.text FROM if ($ptags = get_records_sql_menu("SELECT t.id, t.name FROM
{$CFG->prefix}tags t, {$CFG->prefix}tag t,
{$CFG->prefix}blog_tag_instance bti {$CFG->prefix}tag_instance ti
WHERE t.id = bti.tagid WHERE t.id = ti.tagid
AND t.type = 'personal' AND t.tagtype = 'default'
AND bti.entryid = {$post->id}")) { AND ti.itemid = {$post->id}")) {
$post->ptags = implode(', ', $ptags); $post->ptags = implode(', ', $ptags);
} else { } else {
@ -131,12 +132,12 @@ switch ($action) {
//was used but seems redundant. //was used but seems redundant.
$post->ptags = ''; $post->ptags = '';
} }
if ($otags = get_records_sql_menu("SELECT t.id, t.text FROM if ($otags = get_records_sql_menu("SELECT t.id, t.name FROM
{$CFG->prefix}tags t, {$CFG->prefix}tag t,
{$CFG->prefix}blog_tag_instance bti {$CFG->prefix}tag_instance ti
WHERE t.id = bti.tagid WHERE t.id = ti.tagid
AND t.type = 'official' AND t.tagtype = 'official'
AND bti.entryid = {$post->id}")){ AND ti.itemid = {$post->id}")){
$post->otags = array_keys($otags); $post->otags = array_keys($otags);
} }
break; break;
@ -185,56 +186,47 @@ function no_submit_button_actions(&$blogeditform, $sitecontext){
function delete_otags($tagids, $sitecontext){ function delete_otags($tagids, $sitecontext){
foreach ($tagids as $tagid) { foreach ($tagids as $tagid) {
if (!$tag = get_record('tags', 'id', $tagid)) { if (!$tag = tag_by_id($tagid)) {
error('Can not delete tag, tag doesn\'t exist'); error('Can not delete tag, tag doesn\'t exist');
} }
if ($tag->tagtype != 'official') {
if ($tag->type == 'official' and !has_capability('moodle/blog:manageofficialtags', $sitecontext)) { continue;
}
if ($tag->tagtype == 'official' and !has_capability('moodle/blog:manageofficialtags', $sitecontext)) {
//can not delete //can not delete
error('Can not delete tag, you don\'t have permission to delete an official tag'); error('Can not delete tag, you don\'t have permission to delete an official tag');
} }
if ($tag->type == 'personal' and !has_capability('moodle/blog:managepersonaltags', $sitecontext)) {
//can not delete
error('Can not delete tag, you don\'t have permission to delete a personal tag');
}
// Delete the tag itself // Delete the tag itself
if (!delete_records('tags', 'id', $tagid)) { if (!tag_delete($tagid)) {
error('Can not delete tag'); error('Can not delete tag');
} }
// Deleteing all references to this tag
if (!delete_records('blog_tag_instance', 'tagid', $tagid)) {
error('Can not delete blog tag instances');
}
} }
} }
function add_otag($otag){ function add_otag($otag){
global $USER; global $USER;
$error = ''; $error = '';
if ($tag = get_record('tags', 'text', $otag)) {
if ($tag->type == 'official') { // When adding ofical tag, we see if there's already a personal tag
// With the same Name, if there is, we just change the type
if ($tag = tag_by_name ($otag)) {
if ($tag->tagtype == 'official') {
// official tag already exist // official tag already exist
$error = get_string('tagalready'); $error = get_string('tagalready');
break;
} else { } else {
$tag->type = 'official'; // might not want to do this anymore?
update_record('tags', $tag); $tag->tagtype = 'official';
update_record('tag', $tag);
$tagid = $tag->id; $tagid = $tag->id;
} }
} else { // Brand new offical tag } else { // Brand new offical tag
$tagid = tag_create($otag, 'official');
$tag = new object(); if (empty($tagid)) {
$tag->userid = $USER->id;
$tag->text = $otag;
$tag->type = 'official';
if (!$tagid = insert_record('tags', $tag)) {
error('Can not create tag!'); error('Can not create tag!');
} }
} }
return $error; return $error;
} }
@ -246,8 +238,9 @@ function do_delete($post) {
global $returnurl; global $returnurl;
$status = delete_records('post', 'id', $post->id); $status = delete_records('post', 'id', $post->id);
$status = delete_records('blog_tag_instance', 'entryid', $post->id) and $status; //$status = delete_records('blog_tag_instance', 'entryid', $post->id) and $status;
untag_an_item('blog', $post->id);
blog_delete_old_attachments($post); blog_delete_old_attachments($post);
add_to_log(SITEID, 'blog', 'delete', 'index.php?userid='. $post->userid, 'deleted blog entry with entry id# '. $post->id); add_to_log(SITEID, 'blog', 'delete', 'index.php?userid='. $post->userid, 'deleted blog entry with entry id# '. $post->id);
@ -305,11 +298,13 @@ function do_edit($post, $blogeditform) {
// update record // update record
if (update_record('post', $post)) { if (update_record('post', $post)) {
// delete all tags associated with this entry // delete all tags associated with this entry
delete_records('blog_tag_instance', 'entryid', $post->id);
//delete_records('blog_tag_instance', 'entryid', $post->id);
//delete_records('tag_instance', 'itemid', $post->id, 'itemtype', 'blog');
untag_an_item('blog', $post->id);
// add them back // add them back
add_tags_info($post->id); add_tags_info($post->id);
add_to_log(SITEID, 'blog', 'update', 'index.php?userid='.$post->userid.'&postid='.$post->id, $post->subject); add_to_log(SITEID, 'blog', 'update', 'index.php?userid='.$post->userid.'&postid='.$post->id, $post->subject);
} else { } else {
@ -327,16 +322,12 @@ function add_tags_info($postid) {
$post = get_record('post', 'id', $postid); $post = get_record('post', 'id', $postid);
$tag = new object();
$tag->entryid = $post->id;
$tag->userid = $post->userid;
$tag->timemodified = time();
/// Attach official tags /// Attach official tags
if ($otags = optional_param('otags', '', PARAM_INT)) { if ($otags = optional_param('otags', '', PARAM_INT)) {
foreach ($otags as $otag) { foreach ($otags as $otag) {
$tag->tagid = $otag; $tag->tagid = $otag;
insert_record('blog_tag_instance', $tag); //insert_record('blog_tag_instance', $tag);
tag_an_item('blog', $postid, $otag, 'official');
} }
} }
@ -348,17 +339,13 @@ function add_tags_info($postid) {
// check for existance // check for existance
// it does not matter whether it is an offical tag or personal tag // it does not matter whether it is an offical tag or personal tag
// we do not want to have 1 copy of offical tag and 1 copy of personal tag (for the same tag) // we do not want to have 1 copy of offical tag and 1 copy of personal tag (for the same tag)
if ($ctag = get_record('tags', 'text', $ptag)) { if ($ctag = tag_by_id($ptag)) {
$tag->tagid = $ctag->id; tag_an_item('blog', $postid, $ctag);
insert_record('blog_tag_instance', $tag);
} else { // create a personal tag } else { // create a personal tag
$ctag = new object; if ($tagid = tag_create($ptag)) {
$ctag->userid = $USER->id; if ($tagid = array_shift($tagid)) {
$ctag->text = $ptag; tag_an_item('blog', $postid, $tagid);
$ctag->type = 'personal'; }
if ($tagid = insert_record('tags', $ctag)) {
$tag->tagid = $tagid;
insert_record('blog_tag_instance', $tag);
} }
} }
} }

View File

@ -92,12 +92,14 @@ class blog_edit_form extends moodleform {
function otags_select_setup(){ function otags_select_setup(){
global $CFG; global $CFG;
$mform =& $this->_form; $mform =& $this->_form;
$otagsselect =& $mform->getElement('otags'); if ($otagsselect =& $mform->getElement('otags')) {
$otagsselect->removeOptions(); $otagsselect->removeOptions();
if ($otags = get_records_sql_menu('SELECT id, text from '.$CFG->prefix.'tags WHERE type=\'official\' ORDER by text ASC')){ }
if ($otags = get_records_sql_menu('SELECT id, name from '.$CFG->prefix.'tag WHERE tagtype=\'official\' ORDER by name ASC')){
$otagsselect->loadArray($otags); $otagsselect->loadArray($otags);
} else { } else {
$mform->removeElement('otags'); // removing this causes errors
//$mform->removeElement('otags');
} }
} }

View File

@ -87,13 +87,11 @@ if ($editing) {
} }
if (!empty($tagid)) { if (!empty($tagid)) {
$taginstance = get_record('tags', 'id', $tagid); $taginstance = get_record('tag', 'id', $tagid);
} else { } else {
$tagid = ''; $tagid = '';
if (!empty($tag)) { if (!empty($tag)) {
$tagrec = get_record('tags', 'text', $tag); $taginstance = tag_id($tag);
$tagid = $tagrec->id;
$taginstance = get_record('tags', 'id', $tagid);
} }
} }
@ -119,7 +117,7 @@ $navlinks = array();
case 'site': case 'site':
if ($tagid || !empty($tag)) { if ($tagid || !empty($tag)) {
$navlinks[] = array('name' => $blogstring, 'link' => "index.php?filtertype=site", 'type' => 'misc'); $navlinks[] = array('name' => $blogstring, 'link' => "index.php?filtertype=site", 'type' => 'misc');
$navlinks[] = array('name' => "$tagstring: $taginstance->text", 'link' => null, 'type' => 'misc'); $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks); $navigation = build_navigation($navlinks);
print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string()); print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
} else { } else {
@ -134,7 +132,7 @@ $navlinks = array();
$navlinks[] = array('name' => $blogstring, $navlinks[] = array('name' => $blogstring,
'link' => "index.php?filtertype=course&amp;filterselect=$filterselect", 'link' => "index.php?filtertype=course&amp;filterselect=$filterselect",
'type' => 'misc'); 'type' => 'misc');
$navlinks[] = array('name' => "$tagstring: $taginstance->text", 'link' => null, 'type' => 'misc'); $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks); $navigation = build_navigation($navlinks);
print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string()); print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
} else { } else {
@ -154,7 +152,7 @@ $navlinks = array();
$navlinks[] = array('name' => $blogstring, $navlinks[] = array('name' => $blogstring,
'link' => "index.php?filtertype=group&amp;filterselect=$filterselect", 'link' => "index.php?filtertype=group&amp;filterselect=$filterselect",
'type' => 'misc'); 'type' => 'misc');
$navlinks[] = array('name' => "$tagstring: $taginstance->text", 'link' => null, 'type' => 'misc'); $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks); $navigation = build_navigation($navlinks);
print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string()); print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
} else { } else {
@ -191,7 +189,7 @@ $navlinks = array();
$navlinks[] = array('name' => $blogstring, $navlinks[] = array('name' => $blogstring,
'link' => "index.php?courseid=$course->id&amp;filtertype=user&amp;filterselect=$filterselect", 'link' => "index.php?courseid=$course->id&amp;filtertype=user&amp;filterselect=$filterselect",
'type' => 'misc'); 'type' => 'misc');
$navlinks[] = array('name' => "$tagstring: $taginstance->text", 'link' => null, 'type' => 'misc'); $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks); $navigation = build_navigation($navlinks);
print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string()); print_header("$course->shortname: $blogstring", $course->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());
@ -226,7 +224,7 @@ $navlinks = array();
$navlinks[] = array('name' => $blogstring, $navlinks[] = array('name' => $blogstring,
'link' => "index.php?filtertype=user&amp;filterselect=$filterselect", 'link' => "index.php?filtertype=user&amp;filterselect=$filterselect",
'type' => 'misc'); 'type' => 'misc');
$navlinks[] = array('name' => "$tagstring: $taginstance->text", 'link' => null, 'type' => 'misc'); $navlinks[] = array('name' => "$tagstring: $taginstance->name", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks); $navigation = build_navigation($navlinks);
print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string()); print_header("$SITE->shortname: $blogstring", $SITE->fullname, $navigation,'','',true,$PAGE->get_extra_header_string());

View File

@ -7,7 +7,7 @@
require_once($CFG->libdir .'/pagelib.php'); require_once($CFG->libdir .'/pagelib.php');
require_once($CFG->dirroot .'/blog/rsslib.php'); require_once($CFG->dirroot .'/blog/rsslib.php');
require_once($CFG->dirroot .'/blog/blogpage.php'); require_once($CFG->dirroot .'/blog/blogpage.php');
include_once($CFG->dirroot.'/tag/lib.php');
/** /**
* Definition of blogcourse page type (blog page with course id present). * Definition of blogcourse page type (blog page with course id present).
@ -222,15 +222,18 @@
echo $attachedimages; echo $attachedimages;
/// Links to tags /// Links to tags
/*
if ($blogtags = get_records_sql('SELECT t.* FROM '.$CFG->prefix.'tags t, '.$CFG->prefix.'blog_tag_instance ti if ($blogtags = get_records_sql('SELECT t.* FROM '.$CFG->prefix.'tags t, '.$CFG->prefix.'blog_tag_instance ti
WHERE t.id = ti.tagid WHERE t.id = ti.tagid
AND ti.entryid = '.$blogEntry->id)) { AND ti.entryid = '.$blogEntry->id)) {
*/
if ($blogtags = get_item_tags('blog', $blogEntry->id)) {
echo '<div class="tags">'; echo '<div class="tags">';
if ($blogtags) { if ($blogtags) {
print_string('tags'); print_string('tags');
echo ': '; echo ': ';
foreach ($blogtags as $key => $blogtag) { foreach ($blogtags as $key => $blogtag) {
$taglist[] = '<a href="index.php?filtertype='.$filtertype.'&amp;filterselect='.$filterselect.'&amp;tagid='.$blogtag->id.'">'.$blogtag->text.'</a>'; $taglist[] = '<a href="index.php?filtertype='.$filtertype.'&amp;filterselect='.$filterselect.'&amp;tagid='.$blogtag->id.'">'.$blogtag->name.'</a>';
} }
echo implode(', ', $taglist); echo implode(', ', $taglist);
} }
@ -488,7 +491,7 @@
if ($tagid) { if ($tagid) {
$tag = $tagid; $tag = $tagid;
} else if ($tag) { } else if ($tag) {
if ($tagrec = get_record_sql('SELECT * FROM '.$CFG->prefix.'tags WHERE text LIKE "'.$tag.'"')) { if ($tagrec = get_record_sql('SELECT * FROM '.$CFG->prefix.'tag WHERE name LIKE "'.$tag.'"')) {
$tag = $tagrec->id; $tag = $tagrec->id;
} else { } else {
$tag = -1; //no records found $tag = -1; //no records found
@ -521,8 +524,8 @@
} }
if ($tag) { if ($tag) {
$tagtablesql = $CFG->prefix.'blog_tag_instance bt, '; $tagtablesql = $CFG->prefix.'tag_instance ti, ';
$tagquerysql = ' AND bt.entryid = p.id AND bt.tagid = '.$tag.' '; $tagquerysql = ' AND ti.itemid = p.id AND ti.tagid = '.$tag.' ';
} else { } else {
$tagtablesql = ''; $tagtablesql = '';
$tagquerysql = ''; $tagquerysql = '';

View File

@ -33,25 +33,19 @@ switch ($action) {
$otag = trim(required_param('otag', PARAM_NOTAGS)); $otag = trim(required_param('otag', PARAM_NOTAGS));
// When adding ofical tag, we see if there's already a personal tag // When adding ofical tag, we see if there's already a personal tag
// With the same Name, if there is, we just change the type // With the same Name, if there is, we just change the type
if ($tag = get_record('tags', 'text', $otag)) { if ($tag = tag_by_name ($otag)) {
if ($tag->type == 'official') { if ($tag->type == 'official') {
// official tag already exist // official tag already exist
$error = get_string('tagalready'); $error = get_string('tagalready');
break; break;
} else { } else {
$tag->type = 'official'; $tag->type = 'official';
update_record('tags', $tag); update_record('tag', $tag);
$tagid = $tag->id; $tagid = $tag->id;
} }
} else { // Brand new offical tag } else { // Brand new offical tag
if (!$tagid = tag_create($otag, 'official')) {
$tag = new object();
$tag->userid = $USER->id;
$tag->text = $otag;
$tag->type = 'official';
if (!$tagid = insert_record('tags', $tag)) {
error('Can not create tag!'); error('Can not create tag!');
} }
} }

View File

@ -1789,7 +1789,50 @@ function xmldb_main_upgrade($oldversion=0) {
/// Launch add field timemodified /// Launch add field timemodified
$result = $result && add_field($table, $field); $result = $result && add_field($table, $field);
} }
/// migrate all tags table to tag
if ($result && $oldversion < 2007082701) {
require_once($CFG->dirroot.'/tag/lib.php');
$tagrefs = array(); // $tagrefs[$oldtagid] = $newtagid
if ($tags = get_records('tags')) {
foreach ($tags as $oldtag) {
// if this tag does not exist in tag table yet
if (!$newtag = get_record('tag', 'name', tag_normalize($oldtag->text))) {
$itag->name = tag_normalize($oldtag->text);
$itag->rawname = tag_normalize($oldtag->text, false);
if ($oldtag->type == 'official') {
$itag->tagtype = $oldtag->type;
} else {
$itag->tagtype = 'default';
}
$itag->userid = $oldtag->userid;
$itag->timemodified = time();
if ($idx = insert_record('tag', $itag)) {
$tagrefs[$oldtag->id] = $idx;
}
// if this tag is already used by tag table
} else {
$tagrefs[$oldtag->id] = $newtag->id;
}
}
}
// fetch all the tag instances and migrate them as well
if ($blogtags = get_records('blog_tag_instance')) {
foreach ($blogtags as $blogtag) {
if (!empty($tagrefs[$blogtag->tagid])) {
tag_an_item('blog', $blogtag->entryid, $tagrefs[$blogtag->tagid]);
}
}
}
$table = new XMLDBTable('tags');
drop_table($table);
$table = new XMLDBTable('blog_tag_instance');
drop_table($table);
}
return $result; return $result;
} }

View File

@ -74,11 +74,14 @@ function tag_delete($tag_names_or_ids_csv) {
//covert all ids to names //covert all ids to names
$tag_names_csv = tag_name_from_string($tag_names_or_ids_csv); $tag_names_csv = tag_name_from_string($tag_names_or_ids_csv);
$tag_ids_csv = tag_id_from_string($tag_names_csv);
//put apostrophes in names //put apostrophes in names
$tag_names_csv_with_apos = "'" . str_replace(',', "','", $tag_names_csv) . "'"; $tag_names_csv_with_apos = "'" . str_replace(',', "','", $tag_names_csv) . "'";
$tag_ids_csv_with_apos = "'" . str_replace(',', "','", $tag_ids_csv) . "'";
delete_records_select('tag',"name IN ($tag_names_csv_with_apos)"); // tag instances needs to be deleted as well
delete_records_select('tag_instance',"tagid IN ($tag_ids_csv_with_apos)");
return delete_records_select('tag',"name IN ($tag_names_csv_with_apos)");
} }
@ -396,13 +399,14 @@ function tag_an_item($item_type, $item_id, $tag_names_or_ids_csv, $tag_type="def
$tag_instance->tagid = $tag_id; $tag_instance->tagid = $tag_id;
$tag_instance->ordering = $ordering[$tag_normalized_name]; $tag_instance->ordering = $ordering[$tag_normalized_name];
$tag_instance->timemodified = time();
$tag_instance_exists = get_record('tag_instance', 'tagid', $tag_id, 'itemtype', $item_type, 'itemid', $item_id); $tag_instance_exists = get_record('tag_instance', 'tagid', $tag_id, 'itemtype', $item_type, 'itemid', $item_id);
if (!$tag_instance_exists) { if (!$tag_instance_exists) {
insert_record('tag_instance',$tag_instance); insert_record('tag_instance',$tag_instance);
} }
else { else {
$tag_instance_exists->timemodified = time();
$tag_instance_exists->ordering = $ordering[$tag_normalized_name]; $tag_instance_exists->ordering = $ordering[$tag_normalized_name];
update_record('tag_instance',$tag_instance_exists); update_record('tag_instance',$tag_instance_exists);
} }

View File

@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine // This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php) // whether upgrades should be performed (see lib/db/*.php)
$version = 2007082700; // YYYYMMDD = date $version = 2007082701; // YYYYMMDD = date
// XY = increments within a single day // XY = increments within a single day
$release = '1.9 Beta +'; // Human-friendly version name $release = '1.9 Beta +'; // Human-friendly version name