Skip to content

Commit

Permalink
Merge pull request #41 from yurenzhen/master
Browse files Browse the repository at this point in the history
修复当 user_id 为 string 类型(如uuid)时判断错误而导致的 updated_by 和 created_by 不更新问题.
  • Loading branch information
libern authored May 15, 2019
2 parents 38d3e97 + fa65f27 commit 38a820b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Someline/Base/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ protected function updateIps()
}
}

/**
* check the $user_id is valid.
*
* @param int|string $user_id
* @return bool
*/
protected function validUserId($user_id): bool
{
if ('int' === $this->keyType)
return $user_id > 0;

if ('string' === $this->keyType)
return strlen($user_id) > 0;
}

/**
* Update the creation and update by users.
*
Expand All @@ -143,7 +158,7 @@ protected function updateIps()
protected function updateUsers()
{
$user_id = $this->getAuthUserId();
if (!($user_id > 0)) {
if (!$this->validUserId($user_id)) {
return;
}

Expand All @@ -159,7 +174,7 @@ protected function updateUsers()
/**
* @return bool
*/
public function isAuthUserOwner()
public function isAuthUserOwner(): bool
{
return $this->getAuthUserId() == $this->getUserId();
}
Expand Down

0 comments on commit 38a820b

Please sign in to comment.