diff --git a/helpers/position.php b/helpers/position.php index 519f8c4..1305a5e 100644 --- a/helpers/position.php +++ b/helpers/position.php @@ -114,7 +114,7 @@ require_once(ROOT_DIR . "/helpers/upload.php"); $positionId = false; if (is_numeric($lat) && is_numeric($lon) && is_numeric($timestamp) && is_numeric($userId) && is_numeric($trackId)) { $track = new uTrack($trackId); - if ($track->isValid && $track->userId == $userId) { + if ($track->isValid && $track->userId === $userId) { try { $table = self::db()->table('positions'); $query = "INSERT INTO $table @@ -125,7 +125,7 @@ require_once(ROOT_DIR . "/helpers/upload.php"); $params = [ $userId, $trackId, $timestamp, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $image ]; $stmt->execute($params); - $positionId = self::db()->lastInsertId("${table}_id_seq"); + $positionId = (int) self::db()->lastInsertId("${table}_id_seq"); } catch (PDOException $e) { // TODO: handle error syslog(LOG_ERR, $e->getMessage()); @@ -299,7 +299,7 @@ require_once(ROOT_DIR . "/helpers/upload.php"); * @return bool True if success, false otherwise */ public static function removeImages($userId, $trackId = NULL) { - if (($positions = uPosition::getAllWithImage($userId, $trackId)) !== false) { + if (($positions = self::getAllWithImage($userId, $trackId)) !== false) { /** @var uUpload $position */ foreach ($positions as $position) { try { diff --git a/helpers/track.php b/helpers/track.php index e2aecf2..aa19ef1 100644 --- a/helpers/track.php +++ b/helpers/track.php @@ -84,7 +84,7 @@ $stmt = self::db()->prepare($query); $params = [ $userId, $name, $comment ]; $stmt->execute($params); - $trackId = self::db()->lastInsertId("${table}_id_seq"); + $trackId = (int) self::db()->lastInsertId("${table}_id_seq"); } catch (PDOException $e) { // TODO: handle exception syslog(LOG_ERR, $e->getMessage()); @@ -158,7 +158,7 @@ $ret = false; if (empty($name)) { $name = $this->name; } if (is_null($comment)) { $comment = $this->comment; } - if ($comment == "") { $comment = NULL; } + if ($comment === "") { $comment = NULL; } if ($this->isValid) { try { $query = "UPDATE " . self::db()->table('tracks') . " SET name = ?, comment = ? WHERE id = ?"; @@ -184,21 +184,17 @@ */ public static function deleteAll($userId) { $ret = false; - if (!empty($userId)) { - // remove all positions - if (uPosition::deleteAll($userId) === true) { - // remove all tracks - try { - $query = "DELETE FROM " . self::db()->table('tracks') . " WHERE user_id = ?"; - $stmt = self::db()->prepare($query); - $stmt->execute([ $userId ]); - $ret = true; - } catch (PDOException $e) { - // TODO: handle exception - syslog(LOG_ERR, $e->getMessage()); - } + if (!empty($userId) && uPosition::deleteAll($userId) === true) { + // remove all tracks + try { + $query = "DELETE FROM " . self::db()->table('tracks') . " WHERE user_id = ?"; + $stmt = self::db()->prepare($query); + $stmt->execute([ $userId ]); + $ret = true; + } catch (PDOException $e) { + // TODO: handle exception + syslog(LOG_ERR, $e->getMessage()); } - } return $ret; } diff --git a/helpers/user.php b/helpers/user.php index 5dcaf79..8df6d27 100644 --- a/helpers/user.php +++ b/helpers/user.php @@ -84,7 +84,7 @@ $query = "INSERT INTO $table (login, password) VALUES (?, ?)"; $stmt = self::db()->prepare($query); $stmt->execute([ $login, $hash ]); - $userid = self::db()->lastInsertId("${table}_id_seq"); + $userid = (int) self::db()->lastInsertId("${table}_id_seq"); } catch (PDOException $e) { // TODO: handle exception syslog(LOG_ERR, $e->getMessage());