Skip to content

Commit

Permalink
Split a topic with a poll, it isn't keeped to the original topic #3385 (
Browse files Browse the repository at this point in the history
  • Loading branch information
xillibit authored and 810 committed May 26, 2018
1 parent 532c91c commit 8b1b6a0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/components/com_kunena/controllers/topic.php
Expand Up @@ -1881,6 +1881,7 @@ public function move()
$subject = Factory::getApplication()->input->getString('subject', '');
$shadow = Factory::getApplication()->input->getBool('shadow', false);
$topic_emoticon = Factory::getApplication()->input->getInt('topic_emoticon', null);
$keep_poll = Factory::getApplication()->input->getInt('keep_poll', false);

if ($object instanceof KunenaForumMessage)
{
Expand All @@ -1902,7 +1903,7 @@ public function move()
$ids = false;
}

$targetobject = $topic->move($target, $ids, $shadow, $subject, $changesubject, $topic_emoticon);
$targetobject = $topic->move($target, $ids, $shadow, $subject, $changesubject, $topic_emoticon, $keep_poll);

if (!$targetobject)
{
Expand Down
Expand Up @@ -175,6 +175,7 @@ COM_KUNENA_MODERATION_MOVE_SELECTED = "Move only selected message"
COM_KUNENA_MODERATION_TITLE_DEST_SUBJECT = "New Subject"
COM_KUNENA_MODERATION_TITLE_SELECTED = "Selected Message"
COM_KUNENA_MODERATION_TOPIC_SHADOW = "Leave shadow topic pointing to new location"
COM_KUNENA_MODERATION_TOPIC_KEEP_POLL = "Keep poll when split the topic"
COM_KUNENA_MORE = "More"
COM_KUNENA_MYPROFILE_ABOUTME = "About Me"
COM_KUNENA_MYPROFILE_BANINFO = "Ban reason"
Expand Down
Expand Up @@ -197,6 +197,15 @@ class="fa fa-<?php echo $icon->fa; ?> glyphicon-topic fa-2x"></i>
<?php echo JText::_('COM_KUNENA_MODERATION_CHANGE_SUBJECT_ON_REPLIES'); ?> </label>
</div>
</div>
<?php if (isset($this->message) && $this->topic->poll_id && $this->topic->first_post_id!=$this->message->id) : ?>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="keep_poll" value="1" />
<?php echo JText::_('COM_KUNENA_MODERATION_TOPIC_KEEP_POLL'); ?> </label>
</div>
</div>
<?php endif; ?>
<?php if (!isset($this->message)) : ?>
<div class="control-group">
<div class="controls">
Expand Down
50 changes: 29 additions & 21 deletions src/libraries/kunena/forum/topic/topic.php
Expand Up @@ -1482,13 +1482,14 @@ public function load($id = null)
* @param string $subject New subject
* @param bool $subjectall Change subject from every message
* @param int $topic_iconid Define a new topic icon
* @param int $keep_poll Define if you want keep the poll to the original topic or to the splitted topic
*
* @return boolean|KunenaForumCategory|KunenaForumTopic Target KunenaForumCategory or KunenaForumTopic or
* false on failure
* @throws Exception
* @since Kunena
*/
public function move($target, $ids = false, $shadow = false, $subject = '', $subjectall = false, $topic_iconid = null)
public function move($target, $ids = false, $shadow = false, $subject = '', $subjectall = false, $topic_iconid = null, $keep_poll = 0)
{
// Warning: logic in this function is very complicated and even with full understanding its easy to miss some details!

Expand Down Expand Up @@ -1731,33 +1732,40 @@ public function move($target, $ids = false, $shadow = false, $subject = '', $sub
throw new RuntimeException($e->getMessage(), $e->getCode());
}

// If all messages were moved into another topic, we need to move poll as well
if ($this->poll_id && !$ids && $target != $this)
if ($keep_poll)
{
// Note: We may already have saved cloned target (having poll_id already in there)
$target->poll_id = $this->poll_id;
$target->poll_id = 0;
}
else
{
// If all messages were moved into another topic, we need to move poll as well
if ($this->poll_id && !$ids && $target != $this)
{
// Note: We may already have saved cloned target (having poll_id already in there)
$target->poll_id = $this->poll_id;

// Note: Do not remove poll from shadow: information could still be used to show icon etc
// Note: Do not remove poll from shadow: information could still be used to show icon etc

$query = "UPDATE #__kunena_polls SET `threadid`={$this->_db->Quote($target->id)} WHERE `threadid`={$this->_db->Quote($this->id)}";
$this->_db->setQuery($query);
$query = "UPDATE #__kunena_polls SET `threadid`={$this->_db->Quote($target->id)} WHERE `threadid`={$this->_db->Quote($this->id)}";
$this->_db->setQuery($query);

try
{
$this->_db->execute();
}
catch (JDatabaseExceptionExecuting $e)
{
throw new RuntimeException($e->getMessage(), $e->getCode());
try
{
$this->_db->execute();
}
catch (JDatabaseExceptionExecuting $e)
{
throw new RuntimeException($e->getMessage(), $e->getCode());
}
}
}

// When moving only first message keep poll only on target topic
if ($this->poll_id && $target != $this && $ids)
{
if ($ids && $this->first_post_id)
// When moving only first message keep poll only on target topic
if ($this->poll_id && $target != $this && $ids)
{
$this->poll_id = 0;
if ($ids && $this->first_post_id)
{
$this->poll_id = 0;
}
}
}

Expand Down

0 comments on commit 8b1b6a0

Please sign in to comment.