du532861657 2016-12-04 19:53
浏览 43

阻止多人编辑同一表单

I hope you can help me. :)

i have a laravel app that is being used by multiple users at once, they all have the possibility to edit some projects in our system.

What i dont want is to have 2 people at the same time editing the same form.

If that happens i would like to tell other users that the current form is locked and is being edited by username.

if user then leaves or submits the form, then the form is opened for other users to work with.

I have checked out both optimistic and pessimistic locking, i dont think this is correct for me

What i was thinking of doing, was to create a unique identifier in the table, that is being edited, and if the user on the page has the identifier, i whould lock all other out, but how would i know if the user closes the browser window? then all other usere still cant access the page/form?

How would you guys suggest i go about this?

Kind Regards Dannie

  • 写回答

1条回答 默认 最新

  • duangou2028 2016-12-04 20:11
    关注

    Add a nullable locked_to column to your projects database. Then in the Project model add this field to $dates array so it can be converted to Carbon instances automatically.

    When someone opens the project for edit just set locked_to field to future date, i think +5 seconds may be a good choice. Edit form should send ajax request every 5 seconds to keep project locked for next 5 seconds.

    When user saves project changes, locking will be stopped cause no ajax requests will be send. In that case you also have field which may tell you when the project was opened for the last time.

    User won't be able to edit project if locked_to field is equal or greater than new Carbon instance.

    UPDATE - more info

    There is no need to clear this field. If user didn't finish editing - he just reloaded page, navigated to other page, closed window or browser, died etc... ajax for locking won't be executed anymore, so in the next 5 second currently edited project will be unlocked - locked_to field will contain earlier date than current.

    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭