{"id":13684437,"url":"https://github.com/lorenzo/row-locker","last_synced_at":"2025-08-11T17:08:58.472Z","repository":{"id":62519075,"uuid":"46063649","full_name":"lorenzo/row-locker","owner":"lorenzo","description":"CakePHP ORM plugin for  creating exclusive row locks","archived":false,"fork":false,"pushed_at":"2020-10-21T10:05:31.000Z","size":24,"stargazers_count":19,"open_issues_count":1,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-31T17:49:21.693Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lorenzo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-12T15:55:53.000Z","updated_at":"2020-10-27T22:13:30.000Z","dependencies_parsed_at":"2022-11-02T10:31:14.933Z","dependency_job_id":null,"html_url":"https://github.com/lorenzo/row-locker","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/lorenzo/row-locker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenzo%2Frow-locker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenzo%2Frow-locker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenzo%2Frow-locker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenzo%2Frow-locker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lorenzo","download_url":"https://codeload.github.com/lorenzo/row-locker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenzo%2Frow-locker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269922906,"owners_count":24496999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T14:00:33.540Z","updated_at":"2025-08-11T17:08:58.441Z","avatar_url":"https://github.com/lorenzo.png","language":"PHP","funding_links":[],"categories":["ORM / Database / Datamapping"],"sub_categories":[],"readme":"# RowLocker plugin for the CakePHP ORM\n\nThis plugin offers a simple implementation of row locking by storing a timestamp\nin a field of the row and the name of the lock owner.\n\nRow locking can be useful in CMS-like systems where many people try to change\nthe same record at the same time. By locking the row you can prevent or alert\nthe users from possible data overwrite.\n\n## Installation\n\nYou can install this plugin into your CakePHP application using [composer](http://getcomposer.org).\n\n```\ncomposer require lorenzo/row-locker\n```\n\n**Note:** Above will install package compactible with CakePHP4. Please refer to [Versions section](https://github.com/lorenzo/row-locker#versions) to install package with CakePHP3.\n\nAnd then enable the plugin:\n\n```\nbin/cake plugin load RowLocker\n```\n\n## Configuration\n\nAny table to which you wish to apply RowLocker needs to have the following columns:\n\n* `locked_time`: `DATETIME`\n* `locked_by` (optional) Can be of any type that identify your users (INT, VARCHAR, UUID...)\n* `locked_session` (optional) `VARCHAR(100)` Used for debugging purposes\n\n## Usage\n\nTo use RowLocker you first need to add the `LockableInterface` and `LockableTrait` to your entity:\n\n```php\nuse RowLocker\\LockableInterface;\nuse RowLocker\\LockableTrait;\n...\n\nclass Article extends Entity implements LockableInterface\n{\n    use LockableTrait;\n\n    ...\n}\n```\n\nFinally, add the behavior to your Table class:\n\n```php\nclass ArticlesTable extends Table\n{\n    public function initialize()\n    {\n        ...\n        $this-\u003eaddBehavior('RowLocker.RowLocker');\n    }\n}\n```\n\n### Locking Rows\n\nTo lock any row first load it and the call `lock()` on it. The lock will last for 5 minutes:\n\n```php\n$article = $articlesTable-\u003eget($id);\n$article-\u003elock($userId, $sessionId); // both arguments are actaully optional\n$articlesTable-\u003esave($article);\n```\n\nRowLocker provides a shortcut for doing the above for one or many rows, by using the\n`autoLock` finder:\n\n```php\n$article = $articlesTable\n    -\u003efindById($id)\n    -\u003efind('autoLock', ['lockingUser' =\u003e $userId, 'lockingSession' =\u003e $sessionId])\n    -\u003efirstOrFail(); // This locks the row\n\n$article-\u003eisLocked(); // return true\n```\n\n### Unlocking a Row\n\nJust call `unlock()` in the entity:\n\n```php\n$article-\u003eunlock();\n$articlesTable-\u003esave($article);\n```\n\n### Finding Unlocked Rows\n\nIn order to find unlocked rows (or with locks owned by the same user), use the `unlocked` finder:\n\n\n```php\n$firstUnlocked = $articlesTable\n    -\u003efind('unlocked', ['lockingUser' =\u003e $userId])\n    -\u003efirstOrFail();\n```\n\n### Safely Locking Rows\n\nIn systems with high concurrency (many users trying to get a lock of the same row), it is highly\nrecommended to use the provided `lockingMonitor()` function:\n\n```php\n$safeLocker = $articlesTable-\u003elockingMonitor();\n// Safely lock the row\n$safeLocker(function () use ($id, $userId, $sessionId) {\n    $article = $articlesTable\n        -\u003efindById($id)\n        -\u003efind('autoLock', ['lockingUser' =\u003e $userId, 'lockingSession' =\u003e $sessionId])\n        -\u003efirstOrFail();\n});\n```\n\nWhat the locking monitor does is running the inner callable inside a `SERIALIZABLE` transaction.\n\n## Versions\n\nRowLocker has several releases, each compatible with different releases of\nCakePHP. Use the appropriate version by downloading a tag, or checking out the\ncorrect branch.\n\n* `1.x` tags are compatible with CakePHP 3.x and greater.\n* `2.x` tags is compatible with CakePHP 4.0.x and is stable to use.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florenzo%2Frow-locker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Florenzo%2Frow-locker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florenzo%2Frow-locker/lists"}