Skip to content

Commit

Permalink
Fixes Missing Likes if Article gets a new id
Browse files Browse the repository at this point in the history
  • Loading branch information
eSilverStrike committed Jan 29, 2020
1 parent 85b11de commit 210355a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 5 additions & 2 deletions system/classes/article.class.php
Expand Up @@ -784,6 +784,9 @@ public function saveToDatabase()
// Move trackbacks
$sql = "UPDATE {$_TABLES['trackback']} SET sid='{$newSid}' WHERE sid='{$checkSid}' AND type='article'";
DB_query($sql);

// Move any Likes
LIKES_moveActions('article', '', $checkSid, $newSid);
}
}

Expand Down Expand Up @@ -2358,7 +2361,7 @@ private function _applyTextFilter($text, $postMode)
public function sanitizeData()
{
global $_CONF, $LANG_structureddatatypes;

if (empty($this->_hits)) {
$this->_hits = 0;
}
Expand Down Expand Up @@ -2386,7 +2389,7 @@ public function sanitizeData()
} elseif ($this->_show_topic_icon != 1) {
$this->_show_topic_icon = 0;
}

// Only Core Structured Data Types supported
if (!empty($this->_structured_data_type) && !isset($LANG_structureddatatypes[$this->_structured_data_type])) {
if ($_CONF['structured_data_type_default'] != 'none') {
Expand Down
25 changes: 25 additions & 0 deletions system/lib-likes.php
Expand Up @@ -308,6 +308,31 @@ function LIKES_addAction($type, $sub_type = '', $item_id, $action, $prev_action,
return LIKES_getLikes($type, $sub_type, $item_id);
}

/**
* Move like actions from an old to a new item id
*
* @param string $type plugin name
* @param string $sub_type Sub type of plugin to allow plugins to have likes for more than one type of item (not required)
* @param string $old_item_id Original item id
* @param string $new_item_id New item id
* @return none
*
*/
function LIKES_moveActions($type, $sub_type = '', $old_item_id, $new_item_id)
{
global $_TABLES;

if (empty($sub_type)) {
DB_change($_TABLES['likes'], 'id', DB_escapeString($new_item_id),
array('id', 'type'),
array(DB_escapeString($old_item_id), $type));
} else {
DB_change($_TABLES['likes'], 'id', DB_escapeString($new_item_id),
array('id', 'type', 'sub_type'),
array(DB_escapeString($old_item_id), $type, $sub_type));
}
}

/**
* Return number of likes or dislikes for a type, sub type, and id(s)
*
Expand Down

0 comments on commit 210355a

Please sign in to comment.