Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve split functions #44

Closed
wants to merge 12 commits into from
Closed

Improve split functions #44

wants to merge 12 commits into from

Conversation

rafaucau
Copy link

@rafaucau rafaucau commented Jun 28, 2021

Changes proposed in this pull request:

This PR adds the ability to split posts to an existing discussion instead of creating a new one.

Additionally, this PR adds:

  • update flarum-webpack-config to 1.0.0
  • extract Prettier config to .prettierrc

Screenshot

image

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes.

@rafaucau
Copy link
Author

rafaucau commented Jul 3, 2021

Thanks to @simon1222 for helping with this. He wrote a function for moving posts that works even with discussions that have a large number of posts (even 120k)

@rafaucau rafaucau marked this pull request as ready for review July 3, 2021 21:25
@rafaucau rafaucau changed the title [WIP] Improve split functions Improve split functions Jul 3, 2021
@Hari-Bonda
Copy link

Hari-Bonda commented Jul 6, 2021

one quick question, if a discussion has only one post and we move it into a different discussion will the old discussion will be soft-deleted or the old post stays no posts?

Copy link
Contributor

@luceos luceos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the feature, left some remarks.

src/Validators/SplitToDiscussionValidator.php Outdated Show resolved Hide resolved
src/Api/Commands/SplitToDiscussionHandler.php Outdated Show resolved Hide resolved
Copy link
Member

@imorland imorland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a thought a while back to drop fof/split and fof/merge-discussions, and create a new fof/split-and-merge extension in their place. Seeing this PR has reignited that thought process.

Anyhow, the biggest issue with this PR is the raw sql use - this has to be changed

js/package.json Outdated Show resolved Hide resolved
src/Api/Commands/SplitToDiscussionHandler.php Outdated Show resolved Hide resolved
src/Api/Controllers/SplitToController.php Outdated Show resolved Hide resolved
js/package.json Outdated Show resolved Hide resolved
resources/locale/en.yml Outdated Show resolved Hide resolved
@rafaucau
Copy link
Author

rafaucau commented Jul 6, 2021

I had a thought a while back to drop fof/split and fof/merge-discussions, and create a new fof/split-and-merge extension in their place. Seeing this PR has reignited that thought process.

Yes, there is some duplication of code on the frontend and it would be worth merging them.

Tonight or tomorrow I'll try to find time to fix the SQL Injection problem.

rafaucau and others added 4 commits July 7, 2021 09:40
Co-authored-by: Ian Morland <ian@morland.me>
Co-authored-by: Ian Morland <ian@morland.me>
Co-Authored-By: simon1222 <67348152+simon1222@users.noreply.github.com>
@rafaucau rafaucau requested review from luceos and imorland July 8, 2021 19:26
Copy link
Member

@dsevillamartin dsevillamartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not tested locally. Some comments.

// Persist the new statistics.
$discussion->save();

return Discussion::find($discussion->id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to find the discussion again?? The methods called earlier modify the original $discussion object, so theoretically both will equal the same thing.

If it is to update a relation, you can unset it by using $model->unsetRelation(<name>).

];
}

disabled = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both disabled and select should be methods, not class properties.

Comment on lines +171 to +174
$db->statement('SET @maxNumber = (SELECT MAX(number) FROM posts WHERE discussion_id = ?);', [$discussion->id]);
$db->statement('SET @rank = @maxNumber;');
$db->statement('UPDATE posts SET number=@rank:=@rank+1 WHERE discussion_id = ? ORDER BY created_at;', [$discussion->id]);
$db->statement('UPDATE posts SET number=number-@maxNumber WHERE discussion_id = ?;', [$discussion->id]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raw SQL will not work with table prefixes. I'm also not good at SQL so I'm not going to comment on the statements themselves, performance, etc.

@rafaucau
Copy link
Author

Due to lack of time I unfortunately cannot continue to develop this PR further. I already maintain my own version of this extension on my forum anyway. If anyone has the time and willingness then please help to complete this PR.

@rafaucau rafaucau marked this pull request as draft August 11, 2021 18:05
@rafaucau rafaucau marked this pull request as draft August 11, 2021 18:05
@rafaucau
Copy link
Author

rafaucau commented Aug 31, 2021

The Move Posts extension was released, so there is no point in continuing this PR
https://discuss.flarum.org/d/28824-move-posts

@rafaucau rafaucau closed this Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve split functions Move comment feature
6 participants