more sqlite fixes
This commit is contained in:
parent
4e4f0be4e5
commit
35cc1aad48
3 changed files with 21 additions and 9 deletions
|
@ -255,13 +255,25 @@ class Image {
|
|||
|
||||
// insert each new tags
|
||||
foreach($tags as $tag) {
|
||||
$this->database->execute(
|
||||
"INSERT IGNORE INTO tags(tag) VALUES (?)",
|
||||
$id = $this->database->db->GetOne(
|
||||
"SELECT id FROM tags WHERE tag = ?",
|
||||
array($tag));
|
||||
$this->database->execute(
|
||||
"INSERT INTO image_tags(image_id, tag_id) ".
|
||||
"VALUES(?, (SELECT id FROM tags WHERE tag = ?))",
|
||||
array($this->id, $tag));
|
||||
if(empty($id)) {
|
||||
// a new tag
|
||||
$this->database->execute(
|
||||
"INSERT INTO tags(tag) VALUES (?)",
|
||||
array($tag));
|
||||
$this->database->execute(
|
||||
"INSERT INTO image_tags(image_id, tag_id)
|
||||
VALUES(?, (SELECT id FROM tags WHERE tag = ?))",
|
||||
array($this->id, $tag));
|
||||
}
|
||||
else {
|
||||
// user of an existing tag
|
||||
$this->database->execute(
|
||||
"INSERT INTO image_tags(image_id, tag_id) VALUES(?, ?)",
|
||||
array($this->id, $id));
|
||||
}
|
||||
$this->database->execute(
|
||||
"UPDATE tags SET count = count + 1 WHERE tag = ?",
|
||||
array($tag));
|
||||
|
|
|
@ -210,7 +210,7 @@ class TagList implements Extension {
|
|||
global $config;
|
||||
|
||||
$query = "
|
||||
SELECT COUNT(it3.image_id) as count, t3.tag AS tag
|
||||
SELECT COUNT(it3.image_id) as calc_count, t3.tag AS tag
|
||||
FROM
|
||||
image_tags AS it1,
|
||||
image_tags AS it2,
|
||||
|
@ -226,7 +226,7 @@ class TagList implements Extension {
|
|||
AND t1.id = it1.tag_id
|
||||
AND t3.id = it3.tag_id
|
||||
GROUP BY it3.tag_id
|
||||
ORDER BY count DESC
|
||||
ORDER BY calc_count DESC
|
||||
LIMIT ?
|
||||
";
|
||||
$args = array($image->id, $config->get_int('tag_list_length'));
|
||||
|
|
|
@ -40,7 +40,7 @@ class TagListTheme extends Themelet {
|
|||
$tag = $row['tag'];
|
||||
$h_tag = html_escape($tag);
|
||||
$h_tag_no_underscores = str_replace("_", " ", $h_tag);
|
||||
$count = $row['count'];
|
||||
$count = $row['calc_count'];
|
||||
if($n++) $html .= "\n<br/>";
|
||||
if(!is_null($config->get_string('info_link'))) {
|
||||
$link = str_replace('$tag', $tag, $config->get_string('info_link'));
|
||||
|
|
Reference in a new issue