Skip to content

Commit

Permalink
Merge pull request #5 from zhenxxin/dev
Browse files Browse the repository at this point in the history
action 改写为 yii2 的方式
  • Loading branch information
XuanXin Zhen authored Jan 28, 2017
2 parents 2c59914 + b26d035 commit 0bbfe25
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions AutoLockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ public function setLockMode($value)
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
if (!$this->checkLockRequired($action)) {
if (!$this->checkLockRequired($action->id)) {
return true;
}

return $this->lock($action);
return $this->lock($action->id);
}

return parent::beforeAction($action);
Expand All @@ -129,8 +129,8 @@ public function beforeAction($action)
*/
public function afterAction($action, $result)
{
if ($this->checkLockRequired($action)) {
return $this->unlock($action);
if ($this->checkLockRequired($action->id)) {
return $this->unlock($action->id);
}

return parent::afterAction($action, $result);
Expand All @@ -148,7 +148,7 @@ private function lock($action)
mkdir($dir);
}

$filename = sprintf('%s/%s-%s.lock', $dir, $this->name, $action);
$filename = sprintf('%s/%s-%s.lock', $dir, $this->id, $action);
$file = fopen($filename, 'c'); // 'c' 相对于 'w' 方式更适合于需要 咨询锁(advisory lock) 的情况
if (!flock($file, $this->lockMode)) {
return false;
Expand Down

0 comments on commit 0bbfe25

Please sign in to comment.