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

Fix lesson order being changed when saving lesson #3951

Conversation

hansschuijff
Copy link
Contributor

Fixes #3921

Changes proposed in this Pull Request

  • Skip Sensei_Course_Structure::sort_structure sorting when $order is empty ( or [0] ).

In analysing the problem that on single lesson save, the entire lesson order can be changed, I found that the php usort function changes the lesson order when all lessons return a 0 value.

Note: The entry with value 0 is the result of the way $order is filled from the (empty) $order_string parameter in Sensei_Admin->save_lesson_order().

$order = array_map( 'absint', explode( ',', $order_string ) );

In those cases the lesson order will already be sorted correctly and the intention of the callback function used in this method is to leave the structure unaffected.

This PR just makes the usort-call conditional so it skips sorting when there is nothing to sort ( e.g. $order equals [0] ).

Testing instructions

  • I don't know exactly why and when usort fails, but in our case we had 47 lessons and no modules in the course. So all lessons where no module lessons.

New/Updated Hooks

Deprecated Code

Screenshot / Video

Copy link
Contributor

@yscik yscik left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Looks to be working well for all cases.

  • New lessons added to the end of a course
  • Ordering works everywhere as expected

@yscik yscik added this to the 3.8.0 milestone Feb 2, 2021
@yscik yscik merged commit 6d0fc9e into Automattic:master Feb 2, 2021
@donnapep donnapep changed the title Skip sort_structure method for single lesson save. Fix lesson order being changed when saving lesson Feb 2, 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.

Course Lesson order is changed whenever a single lesson is added or updated - Restore Lesson Order
2 participants