Skip to content

Commit

Permalink
[#431] Fix calling sizeof on non-countable.
Browse files Browse the repository at this point in the history
This warning has become an error in PHP 8. We also remove some
unused code.
  • Loading branch information
jaragunde committed Mar 8, 2023
1 parent 426b6e6 commit 4d307f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
19 changes: 9 additions & 10 deletions model/dao/BelongsDAO/PostgreSQLBelongsDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,22 @@ public function getByUserGroupName($userGroupName) {
* @throws {@link SQLQueryErrorException}
*/
public function create($userId, $userGroupId) {
$affectedRows = 0;
$affectedRows = 0;

// Check for a belongs entry ID.
// Check for a belongs entry ID.
$currBelongs = $this->getByIds($userId, $userGroupId);

// If it doesn't exist, then create.
if(sizeof($currBelongs) == 0) {
$sql = "INSERT INTO belongs (usrid, user_groupid) VALUES (" . $userId . ", " . $userGroupId . ")";
if(!isset($currBelongs) || sizeof($currBelongs) == 0) {
$sql = "INSERT INTO belongs (usrid, user_groupid) VALUES (" . $userId . ", " . $userGroupId . ")";

$res = pg_query($this->connect, $sql);
if ($res == NULL) throw new SQLQueryErrorException(pg_last_error());

$affectedRows = pg_affected_rows($res);
}
if ($res == NULL) throw new SQLQueryErrorException(pg_last_error());

return $affectedRows;
$affectedRows = pg_affected_rows($res);
}

return $affectedRows;
}

/** Belongs relationship entry deleter by User id and User Group id for PostgreSQL.
Expand All @@ -234,7 +233,7 @@ public function delete($userId, $userGroupId) {
$currBelongs = $this->getByIds($userId, $userGroupId);

// If it exists, then delete.
if(sizeof($currBelongs) > 0) {
if(isset($currBelongs) && sizeof($currBelongs) > 0) {
$sql = "DELETE FROM belongs WHERE usrid=" . $userId . " AND user_groupid=" . $userGroupId;

$res = pg_query($this->connect, $sql);
Expand Down
6 changes: 2 additions & 4 deletions model/dao/UserDAO/PostgreSQLUserDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public function update(UserVO $userVO) {
}

// If the query returned a row then update
if(sizeof($currUserVO) > 0) {
if(isset($currUserVO)) {

$sql = "UPDATE usr SET login=" . DBPostgres::checkStringNull($userVO->getLogin());

Expand Down Expand Up @@ -486,7 +486,7 @@ public function delete(UserVO $userVO) {
}

// Otherwise delete a user.
if(sizeof($currUserVO) > 0) {
if(isset($currUserVO)) {
$sql = "DELETE FROM usr WHERE id=".$userVO->getId();

$res = pg_query($this->connect, $sql);
Expand All @@ -497,8 +497,6 @@ public function delete(UserVO $userVO) {
}

return $affectedRows;
if (!is_numeric($userId))
throw new SQLIncorrectTypeException($userId);
}
}

Expand Down

0 comments on commit 4d307f2

Please sign in to comment.