Skip to content

Commit

Permalink
Fix duplicate nicks on AJAX thanks
Browse files Browse the repository at this point in the history
  • Loading branch information
Naguissa committed Jul 24, 2023
1 parent 614fd79 commit 9c78576
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
4 changes: 2 additions & 2 deletions naguissa/thanksforposts/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"type": "phpbb-extension",
"description": "Adds the ability to thank the author (thanks and cancel), and use the rating system posts/topics/forums based on the issued of thanks.",
"homepage": "https://www.foroelectro.net",
"version": "4.0.4",
"time": "2022-02-02",
"version": "4.0.5",
"time": "2023-07-24",
"license": "GPL-2.0",
"authors": [
{
Expand Down
28 changes: 9 additions & 19 deletions naguissa/thanksforposts/controller/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

use Symfony\Component\HttpFoundation\JsonResponse;

class ajax
{
class ajax {

/** @var \phpbb\config\config */
protected $config;
Expand Down Expand Up @@ -84,8 +83,7 @@ class ajax
* @param \naguissa\thanksforposts\core\partials $partials RenderPartial functionality
* @access public
*/
public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\auth\auth $auth, \phpbb\template\template $template, \phpbb\user $user, \phpbb\cache\driver\driver_interface $cache, \phpbb\pagination $pagination, \phpbb\profilefields\manager $profilefields_manager, \phpbb\request\request_interface $request, \phpbb\controller\helper $controller_helper, $thanks_table, $users_table, $phpbb_root_path, $php_ext, $helper, $partials)
{
public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\auth\auth $auth, \phpbb\template\template $template, \phpbb\user $user, \phpbb\cache\driver\driver_interface $cache, \phpbb\pagination $pagination, \phpbb\profilefields\manager $profilefields_manager, \phpbb\request\request_interface $request, \phpbb\controller\helper $controller_helper, $thanks_table, $users_table, $phpbb_root_path, $php_ext, $helper, $partials) {
$this->config = $config;
$this->db = $db;
$this->auth = $auth;
Expand All @@ -104,30 +102,24 @@ public function __construct(\phpbb\config\config $config, \phpbb\db\driver\drive
$this->partials = $partials;
}

protected function _thank()
{
protected function _thank() {
$post_id = $this->request->variable('pid', 0);
$forum_id = $this->request->variable('fid', 0);
$this->helper->array_all_thanks(array($post_id), $forum_id);
return $this->helper->insert_thanks($post_id, $this->user->data['user_id'], $forum_id, true);
}

protected function _rthank()
{
protected function _rthank() {
$post_id = $this->request->variable('pid', 0);
$forum_id = $this->request->variable('fid', 0);
return $this->helper->delete_thanks($post_id, $forum_id, true);
}

public function main()
{
public function main() {
$result = false;
$error = $this->user->lang('THANKS_AJAX_NOT_LOGGED');
if ($this->user->data['user_type'] != USER_IGNORE)
{
if ($this->user->data['user_type'] != USER_IGNORE) {
$action = $this->request->variable('action', "empty", true, \phpbb\request\request_interface::POST);
switch ($action)
{
switch ($action) {
case "thanks":
$result = $error = $this->_thank();
break;
Expand All @@ -139,8 +131,7 @@ public function main()
}
}

if ($result === true)
{
if ($result === true) {
$post_id = $this->request->variable('pid', 0);
$forum_id = $this->request->variable('fid', 0);
$this->helper->array_all_thanks(array($post_id), $forum_id);
Expand Down Expand Up @@ -168,8 +159,7 @@ public function main()
"app_thanks_button_" . $post_id => $this->partials->renderPartial('event/viewtopic_body_post_buttons_after.html', $template_vars)
)
));
} else
{
} else {
return new JsonResponse(array(
'result' => 0,
'error' => $error
Expand Down

0 comments on commit 9c78576

Please sign in to comment.