diff --git a/database/2023_07_21_121854_update_user_agent_storage.php b/database/2023_07_21_121854_update_user_agent_storage.php index de993a4..451ce8b 100644 --- a/database/2023_07_21_121854_update_user_agent_storage.php +++ b/database/2023_07_21_121854_update_user_agent_storage.php @@ -23,8 +23,8 @@ final class UpdateUserAgentStorage_20230721_121854 implements DbMigration { while($selectLoginAttempts->next()) { $updateLoginAttempts->reset(); $userAgent = $selectLoginAttempts->getString(0); - $updateLoginAttempts->addParameter(1, json_encode(ClientInfo::parse($userAgent))); - $updateLoginAttempts->addParameter(2, $userAgent); + $updateLoginAttempts->nextParameter(json_encode(ClientInfo::parse($userAgent))); + $updateLoginAttempts->nextParameter($userAgent); $updateLoginAttempts->execute(); } @@ -33,8 +33,8 @@ final class UpdateUserAgentStorage_20230721_121854 implements DbMigration { while($selectSessions->next()) { $updateSessions->reset(); $userAgent = $selectSessions->getString(0); - $updateSessions->addParameter(1, json_encode(ClientInfo::parse($userAgent))); - $updateSessions->addParameter(2, $userAgent); + $updateSessions->nextParameter(json_encode(ClientInfo::parse($userAgent))); + $updateSessions->nextParameter($userAgent); $updateSessions->execute(); } diff --git a/database/2023_08_30_213930_new_permissions_system.php b/database/2023_08_30_213930_new_permissions_system.php index 9d1b22b..9ed9209 100644 --- a/database/2023_08_30_213930_new_permissions_system.php +++ b/database/2023_08_30_213930_new_permissions_system.php @@ -77,12 +77,13 @@ final class NewPermissionsSystem_20230830_213930 implements DbMigration { $result = $conn->query('SELECT user_id, role_id, general_perms_allow, general_perms_deny, user_perms_allow, user_perms_deny, changelog_perms_allow, changelog_perms_deny, news_perms_allow, news_perms_deny, forum_perms_allow, forum_perms_deny, comments_perms_allow, comments_perms_deny FROM msz_permissions'); while($result->next()) { - $insert->addParameter(1, $result->isNull(0) ? null : $result->getString(0)); - $insert->addParameter(2, $result->isNull(1) ? null : $result->getString(1)); - $insert->addParameter(3, null); - $insert->addParameter(4, 'user'); - $insert->addParameter(5, $result->getInteger(4)); - $insert->addParameter(6, $result->getInteger(5)); + $insert->reset(); + $insert->nextParameter($result->isNull(0) ? null : $result->getString(0)); + $insert->nextParameter($result->isNull(1) ? null : $result->getString(1)); + $insert->nextParameter(null); + $insert->nextParameter('user'); + $insert->nextParameter($result->getInteger(4)); + $insert->nextParameter($result->getInteger(5)); $insert->execute(); $allow = $result->getInteger(2); @@ -105,12 +106,13 @@ final class NewPermissionsSystem_20230830_213930 implements DbMigration { $result = $conn->query('SELECT user_id, role_id, forum_id, forum_perms_allow, forum_perms_deny FROM msz_forum_permissions'); while($result->next()) { - $insert->addParameter(1, $result->isNull(0) ? null : $result->getString(0)); - $insert->addParameter(2, $result->isNull(1) ? null : $result->getString(1)); - $insert->addParameter(3, $result->getString(2)); - $insert->addParameter(4, 'forum'); - $insert->addParameter(5, $result->getInteger(3)); - $insert->addParameter(6, $result->getInteger(4)); + $insert->reset(); + $insert->nextParameter($result->isNull(0) ? null : $result->getString(0)); + $insert->nextParameter($result->isNull(1) ? null : $result->getString(1)); + $insert->nextParameter($result->getString(2)); + $insert->nextParameter('forum'); + $insert->nextParameter($result->getInteger(3)); + $insert->nextParameter($result->getInteger(4)); $insert->execute(); } diff --git a/public-legacy/settings/data.php b/public-legacy/settings/data.php index c6a5856..78e4cfa 100644 --- a/public-legacy/settings/data.php +++ b/public-legacy/settings/data.php @@ -54,7 +54,7 @@ function db_to_zip( try { $stmt = $dbConn->prepare(sprintf('SELECT %s FROM msz_%s WHERE %s = ?', implode(', ', $fields), $baseName, $userIdField)); - $stmt->addParameter(1, $userId); + $stmt->nextParameter($userId); $stmt->execute(); $result = $stmt->getResult(); diff --git a/src/AuditLog/AuditLog.php b/src/AuditLog/AuditLog.php index eb1149e..cbef494 100644 --- a/src/AuditLog/AuditLog.php +++ b/src/AuditLog/AuditLog.php @@ -36,11 +36,10 @@ class AuditLog { $stmt = $this->cache->get($query); - $args = 0; if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasRemoteAddr) - $stmt->addParameter(++$args, $remoteAddr); + $stmt->nextParameter($remoteAddr); $stmt->execute(); $result = $stmt->getResult(); @@ -81,14 +80,13 @@ class AuditLog { $stmt = $this->cache->get($query); - $args = 0; if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasRemoteAddr) - $stmt->addParameter(++$args, $remoteAddr); + $stmt->nextParameter($remoteAddr); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -126,11 +124,11 @@ class AuditLog { $params = json_encode($params); $stmt = $this->cache->get('INSERT INTO msz_audit_log (user_id, log_action, log_params, log_ip, log_country) VALUES (?, ?, ?, INET6_ATON(?), UPPER(?))'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $action); - $stmt->addParameter(3, $params); - $stmt->addParameter(4, $remoteAddr); - $stmt->addParameter(5, $countryCode); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($action); + $stmt->nextParameter($params); + $stmt->nextParameter($remoteAddr); + $stmt->nextParameter($countryCode); $stmt->execute(); } } diff --git a/src/Auth/LoginAttempts.php b/src/Auth/LoginAttempts.php index ba604c5..be73e25 100644 --- a/src/Auth/LoginAttempts.php +++ b/src/Auth/LoginAttempts.php @@ -43,14 +43,13 @@ class LoginAttempts { if($hasTimeRange) $query .= sprintf(' %s attempt_created > NOW() - INTERVAL ? SECOND', ++$args > 1 ? 'AND' : 'WHERE'); - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasRemoteAddr) - $stmt->addParameter(++$args, $remoteAddr); + $stmt->nextParameter($remoteAddr); if($hasTimeRange) - $stmt->addParameter(++$args, $timeRange); + $stmt->nextParameter($timeRange); $stmt->execute(); $result = $stmt->getResult(); @@ -103,17 +102,16 @@ class LoginAttempts { if($hasPagination) $query .= ' LIMIT ? OFFSET ?'; - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasRemoteAddr) - $stmt->addParameter(++$args, $remoteAddr); + $stmt->nextParameter($remoteAddr); if($hasTimeRange) - $stmt->addParameter(++$args, $timeRange); + $stmt->nextParameter($timeRange); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -135,12 +133,12 @@ class LoginAttempts { $clientInfo = json_encode($clientInfo ?? ClientInfo::parse($userAgentString)); $stmt = $this->cache->get('INSERT INTO msz_login_attempts (user_id, attempt_success, attempt_ip, attempt_country, attempt_user_agent, attempt_client_info) VALUES (?, ?, INET6_ATON(?), ?, ?, ?)'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $success ? 1 : 0); - $stmt->addParameter(3, $remoteAddr); - $stmt->addParameter(4, $countryCode); - $stmt->addParameter(5, $userAgentString); - $stmt->addParameter(6, $clientInfo); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($success ? 1 : 0); + $stmt->nextParameter($remoteAddr); + $stmt->nextParameter($countryCode); + $stmt->nextParameter($userAgentString); + $stmt->nextParameter($clientInfo); $stmt->execute(); } } diff --git a/src/Auth/RecoveryTokens.php b/src/Auth/RecoveryTokens.php index 70edde7..0792ec0 100644 --- a/src/Auth/RecoveryTokens.php +++ b/src/Auth/RecoveryTokens.php @@ -53,14 +53,13 @@ class RecoveryTokens { elseif($hasVerifyCode) $query .= sprintf(' %s verification_code = ?', ++$args > 1 ? 'AND' : 'WHERE'); - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasRemoteAddr) - $stmt->addParameter(++$args, $remoteAddr); + $stmt->nextParameter($remoteAddr); if($hasVerifyCode) - $stmt->addParameter(++$args, $verifyCode); + $stmt->nextParameter($verifyCode); $stmt->execute(); $result = $stmt->getResult(); @@ -80,9 +79,9 @@ class RecoveryTokens { $verifyCode = self::generateCode(); $stmt = $this->cache->get('INSERT INTO msz_users_password_resets (user_id, reset_ip, verification_code) VALUES (?, INET6_ATON(?), ?)'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $remoteAddr); - $stmt->addParameter(3, $verifyCode); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($remoteAddr); + $stmt->nextParameter($verifyCode); $stmt->execute(); return $this->getToken(verifyCode: $verifyCode); @@ -93,8 +92,8 @@ class RecoveryTokens { return; $stmt = $this->cache->get('UPDATE msz_users_password_resets SET verification_code = NULL WHERE verification_code = ? AND user_id = ?'); - $stmt->addParameter(1, $tokenInfo->code); - $stmt->addParameter(2, $tokenInfo->userId); + $stmt->nextParameter($tokenInfo->code); + $stmt->nextParameter($tokenInfo->userId); $stmt->execute(); } } diff --git a/src/Auth/Sessions.php b/src/Auth/Sessions.php index 7aa0eca..f79f884 100644 --- a/src/Auth/Sessions.php +++ b/src/Auth/Sessions.php @@ -37,10 +37,9 @@ class Sessions { $query .= ' WHERE user_id = ?'; } - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -73,13 +72,12 @@ class Sessions { if($hasPagination) $query .= ' LIMIT ? OFFSET ?'; - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -109,7 +107,7 @@ class Sessions { } $stmt = $this->cache->get($query); - $stmt->addParameter(1, $value); + $stmt->nextParameter($value); $stmt->execute(); $result = $stmt->getResult(); @@ -133,12 +131,12 @@ class Sessions { $clientInfo = json_encode($clientInfo ?? ClientInfo::parse($userAgentString)); $stmt = $this->cache->get('INSERT INTO msz_sessions (user_id, session_key, session_ip, session_user_agent, session_client_info, session_country, session_expires) VALUES (?, ?, INET6_ATON(?), ?, ?, ?, NOW() + INTERVAL 1 MONTH)'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $sessionToken); - $stmt->addParameter(3, $remoteAddr); - $stmt->addParameter(4, $userAgentString); - $stmt->addParameter(5, $clientInfo); - $stmt->addParameter(6, $countryCode); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($sessionToken); + $stmt->nextParameter($remoteAddr); + $stmt->nextParameter($userAgentString); + $stmt->nextParameter($clientInfo); + $stmt->nextParameter($countryCode); $stmt->execute(); return $this->getSession(sessionId: (string)$this->dbConn->getLastInsertId()); @@ -207,7 +205,6 @@ class Sessions { if(!$hasSessionInfos && !$hasSessionTokens && !$hasUserInfos) throw new InvalidArgumentException('At least one argument must be specified.'); - $args = 0; $stmt = $this->cache->get($query); if($hasSessionInfos) @@ -217,7 +214,7 @@ class Sessions { elseif(!is_string($sessionInfo)) throw new InvalidArgumentException('$sessionInfos must be strings or instances of SessionInfo.'); - $stmt->addParameter(++$args, $sessionInfo); + $stmt->nextParameter($sessionInfo); } if($hasSessionTokens) @@ -225,7 +222,7 @@ class Sessions { if(!is_string($sessionToken)) throw new InvalidArgumentException('$sessionTokens must be strings.'); - $stmt->addParameter(++$args, $sessionToken); + $stmt->nextParameter($sessionToken); } if($hasUserInfos) @@ -235,7 +232,7 @@ class Sessions { elseif(!is_string($userInfo)) throw new InvalidArgumentException('$userInfos must be strings or instances of UserInfo.'); - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); } $stmt->execute(); @@ -267,8 +264,8 @@ class Sessions { } else throw new RuntimeException('Failsafe to prevent all sessions from being updated at once somehow.'); $stmt = $this->cache->get($query); - $stmt->addParameter(1, $remoteAddr); - $stmt->addParameter(2, $value); + $stmt->nextParameter($remoteAddr); + $stmt->nextParameter($value); $stmt->execute(); } diff --git a/src/Auth/TwoFactorAuthSessions.php b/src/Auth/TwoFactorAuthSessions.php index 5ced130..d22f9e8 100644 --- a/src/Auth/TwoFactorAuthSessions.php +++ b/src/Auth/TwoFactorAuthSessions.php @@ -23,8 +23,8 @@ class TwoFactorAuthSessions { $token = self::generateToken(); $stmt = $this->cache->get('INSERT INTO msz_auth_tfa (user_id, tfa_token) VALUES (?, ?)'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $token); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($token); $stmt->execute(); return $token; @@ -32,7 +32,7 @@ class TwoFactorAuthSessions { public function getTokenUserId(string $token): string { $stmt = $this->cache->get('SELECT user_id FROM msz_auth_tfa WHERE tfa_token = ? AND tfa_created > NOW() - INTERVAL 15 MINUTE'); - $stmt->addParameter(1, $token); + $stmt->nextParameter($token); $stmt->execute(); $result = $stmt->getResult(); @@ -41,7 +41,7 @@ class TwoFactorAuthSessions { public function deleteToken(string $token): void { $stmt = $this->cache->get('DELETE FROM msz_auth_tfa WHERE tfa_token = ?'); - $stmt->addParameter(1, $token); + $stmt->nextParameter($token); $stmt->execute(); } } diff --git a/src/Changelog/Changelog.php b/src/Changelog/Changelog.php index 3ef1caf..a703e62 100644 --- a/src/Changelog/Changelog.php +++ b/src/Changelog/Changelog.php @@ -96,14 +96,13 @@ class Changelog { } $stmt = $this->cache->get($query); - $args = 0; if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasDateTime) - $stmt->addParameter(++$args, $dateTime); + $stmt->nextParameter($dateTime); if($hasTags) foreach($tags as $tag) - $stmt->addParameter(++$args, (string)$tag); + $stmt->nextParameter((string)$tag); $stmt->execute(); $result = $stmt->getResult(); @@ -157,17 +156,16 @@ class Changelog { $query .= ' LIMIT ? OFFSET ?'; $stmt = $this->cache->get($query); - $args = 0; if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasDateTime) - $stmt->addParameter(++$args, $dateTime); + $stmt->nextParameter($dateTime); if($hasTags) foreach($tags as $tag) - $stmt->addParameter(++$args, (string)$tag); + $stmt->nextParameter((string)$tag); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -177,7 +175,7 @@ class Changelog { public function getChange(string $changeId): ChangeInfo { $stmt = $this->cache->get('SELECT change_id, user_id, change_action, UNIX_TIMESTAMP(change_created), change_log, change_text FROM msz_changelog_changes WHERE change_id = ?'); - $stmt->addParameter(1, $changeId); + $stmt->nextParameter($changeId); $stmt->execute(); $result = $stmt->getResult(); @@ -210,11 +208,11 @@ class Changelog { $body = null; $stmt = $this->cache->get('INSERT INTO msz_changelog_changes (user_id, change_action, change_created, change_log, change_text) VALUES (?, ?, FROM_UNIXTIME(?), ?, ?)'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $action); - $stmt->addParameter(3, $createdAt); - $stmt->addParameter(4, $summary); - $stmt->addParameter(5, $body); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($action); + $stmt->nextParameter($createdAt); + $stmt->nextParameter($summary); + $stmt->nextParameter($body); $stmt->execute(); return $this->getChange((string)$this->dbConn->getLastInsertId()); @@ -225,7 +223,7 @@ class Changelog { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('DELETE FROM msz_changelog_changes WHERE change_id = ?'); - $stmt->addParameter(1, $infoOrId); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -262,14 +260,14 @@ class Changelog { } $stmt = $this->cache->get('UPDATE msz_changelog_changes SET change_action = COALESCE(?, change_action), change_log = COALESCE(?, change_log), change_text = IF(?, ?, change_text), user_id = IF(?, ?, user_id), change_created = COALESCE(FROM_UNIXTIME(?), change_created) WHERE change_id = ?'); - $stmt->addParameter(1, $action); - $stmt->addParameter(2, $summary); - $stmt->addParameter(3, $hasBody ? 1 : 0); - $stmt->addParameter(4, $body); - $stmt->addParameter(5, $updateUserInfo ? 1 : 0); - $stmt->addParameter(6, $userInfo); - $stmt->addParameter(7, $createdAt); - $stmt->addParameter(8, $infoOrId); + $stmt->nextParameter($action); + $stmt->nextParameter($summary); + $stmt->nextParameter($hasBody ? 1 : 0); + $stmt->nextParameter($body); + $stmt->nextParameter($updateUserInfo ? 1 : 0); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($createdAt); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -288,7 +286,7 @@ class Changelog { $stmt = $this->cache->get($query); if($hasChangeInfo) - $stmt->addParameter(1, $changeInfo); + $stmt->nextParameter($changeInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -307,7 +305,7 @@ class Changelog { public function getTag(string $tagId): ChangeTagInfo { $stmt = $this->cache->get('SELECT tag_id, tag_name, tag_description, UNIX_TIMESTAMP(tag_created), UNIX_TIMESTAMP(tag_archived), 0 AS `tag_changes` FROM msz_changelog_tags WHERE tag_id = ?'); - $stmt->addParameter(1, $tagId); + $stmt->nextParameter($tagId); $stmt->execute(); $result = $stmt->getResult(); @@ -331,9 +329,9 @@ class Changelog { $description = null; $stmt = $this->cache->get('INSERT INTO msz_changelog_tags (tag_name, tag_description, tag_archived) VALUES (?, ?, IF(?, NOW(), NULL))'); - $stmt->addParameter(1, $name); - $stmt->addParameter(2, $description); - $stmt->addParameter(3, $archived ? 1 : 0); + $stmt->nextParameter($name); + $stmt->nextParameter($description); + $stmt->nextParameter($archived ? 1 : 0); $stmt->execute(); return $this->getTag((string)$this->dbConn->getLastInsertId()); @@ -344,7 +342,7 @@ class Changelog { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('DELETE FROM msz_changelog_tags WHERE tag_id = ?'); - $stmt->addParameter(1, $infoOrId); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -373,12 +371,12 @@ class Changelog { $hasArchived = $archived !== null; $stmt = $this->cache->get('UPDATE msz_changelog_tags SET tag_name = COALESCE(?, tag_name), tag_description = IF(?, ?, tag_description), tag_archived = IF(?, IF(?, NOW(), NULL), tag_archived) WHERE tag_id = ?'); - $stmt->addParameter(1, $name); - $stmt->addParameter(2, $hasDescription ? 1 : 0); - $stmt->addParameter(3, $description); - $stmt->addParameter(4, $hasArchived ? 1 : 0); - $stmt->addParameter(5, $archived ? 1 : 0); - $stmt->addParameter(6, $infoOrId); + $stmt->nextParameter($name); + $stmt->nextParameter($hasDescription ? 1 : 0); + $stmt->nextParameter($description); + $stmt->nextParameter($hasArchived ? 1 : 0); + $stmt->nextParameter($archived ? 1 : 0); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -389,8 +387,8 @@ class Changelog { $tag = $tag->id; $stmt = $this->cache->get('INSERT INTO msz_changelog_change_tags (change_id, tag_id) VALUES (?, ?)'); - $stmt->addParameter(1, $change); - $stmt->addParameter(2, $tag); + $stmt->nextParameter($change); + $stmt->nextParameter($tag); $stmt->execute(); } @@ -401,8 +399,8 @@ class Changelog { $tag = $tag->id; $stmt = $this->cache->get('DELETE FROM msz_changelog_change_tags WHERE change_id = ? AND tag_id = ?'); - $stmt->addParameter(1, $change); - $stmt->addParameter(2, $tag); + $stmt->nextParameter($change); + $stmt->nextParameter($tag); $stmt->execute(); } } diff --git a/src/Comments/Comments.php b/src/Comments/Comments.php index 6f5fd5b..56c30d0 100644 --- a/src/Comments/Comments.php +++ b/src/Comments/Comments.php @@ -29,7 +29,7 @@ class Comments { $query .= ' WHERE owner_id = ?'; $stmt = $this->cache->get($query); - $stmt->addParameter(1, $owner); + $stmt->nextParameter($owner); $stmt->execute(); $count = 0; @@ -61,12 +61,11 @@ class Comments { $stmt = $this->cache->get($query); - $args = 0; if($hasOwner) - $stmt->addParameter(++$args, $owner); + $stmt->nextParameter($owner); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -110,7 +109,7 @@ class Comments { } $stmt = $this->cache->get($query); - $stmt->addParameter(1, $value); + $stmt->nextParameter($value); $stmt->execute(); $result = $stmt->getResult(); @@ -122,7 +121,7 @@ class Comments { public function checkCategoryNameExists(string $name): bool { $stmt = $this->cache->get('SELECT COUNT(*) FROM msz_comments_categories WHERE category_name = ?'); - $stmt->addParameter(1, $name); + $stmt->nextParameter($name); $stmt->execute(); $count = 0; @@ -149,8 +148,8 @@ class Comments { throw new InvalidArgumentException('$name may not be empty.'); $stmt = $this->cache->get('INSERT INTO msz_comments_categories (category_name, owner_id) VALUES (?, ?)'); - $stmt->addParameter(1, $name); - $stmt->addParameter(2, $owner); + $stmt->nextParameter($name); + $stmt->nextParameter($owner); $stmt->execute(); return $this->getCategory(categoryId: (string)$this->dbConn->getLastInsertId()); @@ -161,7 +160,7 @@ class Comments { $category = $category->id; $stmt = $this->cache->get('DELETE FROM msz_comments_categories WHERE category_id = ?'); - $stmt->addParameter(1, $category); + $stmt->nextParameter($category); $stmt->execute(); } @@ -183,10 +182,10 @@ class Comments { } $stmt = $this->cache->get('UPDATE msz_comments_categories SET category_name = COALESCE(?, category_name), owner_id = IF(?, ?, owner_id) WHERE category_id = ?'); - $stmt->addParameter(1, $name); - $stmt->addParameter(2, $updateOwner ? 1 : 0); - $stmt->addParameter(3, $owner ? 1 : 0); - $stmt->addParameter(4, $category); + $stmt->nextParameter($name); + $stmt->nextParameter($updateOwner ? 1 : 0); + $stmt->nextParameter($owner ? 1 : 0); + $stmt->nextParameter($category); $stmt->execute(); } @@ -195,7 +194,7 @@ class Comments { $category = $category->id; $stmt = $this->cache->get('UPDATE msz_comments_categories SET category_locked = COALESCE(category_locked, NOW()) WHERE category_id = ?'); - $stmt->addParameter(1, $category); + $stmt->nextParameter($category); $stmt->execute(); } @@ -204,7 +203,7 @@ class Comments { $category = $category->id; $stmt = $this->cache->get('UPDATE msz_comments_categories SET category_locked = NULL WHERE category_id = ?'); - $stmt->addParameter(1, $category); + $stmt->nextParameter($category); $stmt->execute(); } @@ -242,14 +241,13 @@ class Comments { if($hasUserInfo) $query .= sprintf(' %s user_id = ?', ++$args > 1 ? 'AND' : 'WHERE'); - $args = 0; $stmt = $this->cache->get($query); if($hasParentInfo) - $stmt->addParameter(++$args, $parentInfo); + $stmt->nextParameter($parentInfo); elseif($hasCategoryInfo) - $stmt->addParameter(++$args, $categoryInfo); + $stmt->nextParameter($categoryInfo); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo instanceof UserInfo ? $userInfo->id : $userInfo); + $stmt->nextParameter($userInfo instanceof UserInfo ? $userInfo->id : $userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -314,14 +312,13 @@ class Comments { else $query .= ' ORDER BY comment_created DESC'; - $args = 0; $stmt = $this->cache->get($query); if($hasParentInfo) - $stmt->addParameter(++$args, $parentInfo); + $stmt->nextParameter($parentInfo); elseif($hasCategoryInfo) - $stmt->addParameter(++$args, $categoryInfo); + $stmt->nextParameter($categoryInfo); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo instanceof UserInfo ? $userInfo->id : $userInfo); + $stmt->nextParameter($userInfo instanceof UserInfo ? $userInfo->id : $userInfo); $stmt->execute(); return $stmt->getResult()->getIterator(fn($result) => CommentsPostInfo::fromResult($result, $includeRepliesCount, $includeVotesCount)); @@ -343,7 +340,7 @@ class Comments { $query .= ' FROM msz_comments_posts AS cpp WHERE comment_id = ?'; $stmt = $this->cache->get($query); - $stmt->addParameter(1, $postId); + $stmt->nextParameter($postId); $stmt->execute(); $result = $stmt->getResult(); @@ -377,11 +374,11 @@ class Comments { throw new InvalidArgumentException('$body may not be empty.'); $stmt = $this->cache->get('INSERT INTO msz_comments_posts (category_id, user_id, comment_reply_to, comment_text, comment_pinned) VALUES (?, ?, ?, ?, IF(?, NOW(), NULL))'); - $stmt->addParameter(1, $category); - $stmt->addParameter(2, $user); - $stmt->addParameter(3, $parent); - $stmt->addParameter(4, $body); - $stmt->addParameter(5, $pin ? 1 : 0); + $stmt->nextParameter($category); + $stmt->nextParameter($user); + $stmt->nextParameter($parent); + $stmt->nextParameter($body); + $stmt->nextParameter($pin ? 1 : 0); $stmt->execute(); return $this->getPost((string)$this->dbConn->getLastInsertId()); @@ -392,7 +389,7 @@ class Comments { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('UPDATE msz_comments_posts SET comment_deleted = COALESCE(comment_deleted, NOW()) WHERE comment_id = ?'); - $stmt->addParameter(1, $infoOrId); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -401,7 +398,7 @@ class Comments { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('DELETE FROM msz_comments_posts WHERE comment_id = ?'); - $stmt->addParameter(1, $infoOrId); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -410,7 +407,7 @@ class Comments { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('UPDATE msz_comments_posts SET comment_deleted = NULL WHERE comment_id = ?'); - $stmt->addParameter(1, $infoOrId); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -422,8 +419,8 @@ class Comments { throw new InvalidArgumentException('$body may not be empty.'); $stmt = $this->cache->get('UPDATE msz_comments_posts SET comment_text = ?, comment_edited = NOW() WHERE comment_id = ?'); - $stmt->addParameter(1, $body); - $stmt->addParameter(2, $infoOrId); + $stmt->nextParameter($body); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -432,7 +429,7 @@ class Comments { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('UPDATE msz_comments_posts SET comment_pinned = COALESCE(comment_pinned, NOW()) WHERE comment_id = ?'); - $stmt->addParameter(1, $infoOrId); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -441,7 +438,7 @@ class Comments { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('UPDATE msz_comments_posts SET comment_pinned = NULL WHERE comment_id = ?'); - $stmt->addParameter(1, $infoOrId); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -456,8 +453,8 @@ class Comments { // SUM() here makes it so a result row is always returned, albeit with just NULLs $stmt = $this->cache->get('SELECT comment_id, user_id, SUM(comment_vote) FROM msz_comments_votes WHERE comment_id = ? AND user_id = ?'); - $stmt->addParameter(1, $post); - $stmt->addParameter(2, $user); + $stmt->nextParameter($post); + $stmt->nextParameter($user); $stmt->execute(); $result = $stmt->getResult(); @@ -480,9 +477,9 @@ class Comments { $user = $user->id; $stmt = $this->cache->get('REPLACE INTO msz_comments_votes (comment_id, user_id, comment_vote) VALUES (?, ?, ?)'); - $stmt->addParameter(1, $post); - $stmt->addParameter(2, $user); - $stmt->addParameter(3, $weight); + $stmt->nextParameter($post); + $stmt->nextParameter($user); + $stmt->nextParameter($weight); $stmt->execute(); } @@ -504,8 +501,8 @@ class Comments { $user = $user->id; $stmt = $this->cache->get('DELETE FROM msz_comments_votes WHERE comment_id = ? AND user_id = ?'); - $stmt->addParameter(1, $post); - $stmt->addParameter(2, $user); + $stmt->nextParameter($post); + $stmt->nextParameter($user); $stmt->execute(); } } diff --git a/src/Counters/Counters.php b/src/Counters/Counters.php index e7cb45f..68df5a6 100644 --- a/src/Counters/Counters.php +++ b/src/Counters/Counters.php @@ -38,11 +38,10 @@ class Counters { if($hasPagination) $query .= ' LIMIT ? OFFSET ?'; - $args = 0; $stmt = $this->cache->get($query); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -59,13 +58,12 @@ class Counters { $names = [$names]; } else $returnFirst = false; - $args = 0; $stmt = $this->cache->get(sprintf( 'SELECT counter_name, counter_value FROM msz_counters WHERE counter_name IN (%s)', DbTools::prepareListString($names) )); foreach($names as $name) - $stmt->addParameter(++$args, (string)$name); + $stmt->nextParameter((string)$name); $stmt->execute(); $values = []; @@ -89,15 +87,14 @@ class Counters { } else $values = $nameOrValues; - $args = 0; $stmt = $this->cache->get(sprintf( 'REPLACE INTO msz_counters (counter_name, counter_value) VALUES %s', DbTools::prepareListString($values, '(?, ?)') )); foreach($values as $name => $value) { - $stmt->addParameter(++$args, (string)$name); - $stmt->addParameter(++$args, (int)$value); + $stmt->nextParameter((string)$name); + $stmt->nextParameter((int)$value); } $stmt->execute(); @@ -110,29 +107,28 @@ class Counters { if(is_string($names)) $names = [$names]; - $args = 0; $stmt = $this->cache->get(sprintf( 'DELETE FROM msz_counters WHERE counter_name IN (%s)', DbTools::prepareListString($names) )); foreach($names as $name) - $stmt->addParameter(++$args, (string)$name); + $stmt->nextParameter((string)$name); $stmt->execute(); } public function increment(string $name, int $step = 1): void { $stmt = $this->cache->get('INSERT INTO msz_counters (counter_name, counter_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE counter_value = counter_value + ?'); - $stmt->addParameter(1, $name); - $stmt->addParameter(2, $step); - $stmt->addParameter(3, $step); + $stmt->nextParameter($name); + $stmt->nextParameter($step); + $stmt->nextParameter($step); $stmt->execute(); } public function decrement(string $name, int $step = 1): void { $stmt = $this->cache->get('INSERT INTO msz_counters (counter_name, counter_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE counter_value = counter_value - ?'); - $stmt->addParameter(1, $name); - $stmt->addParameter(2, -$step); - $stmt->addParameter(3, $step); + $stmt->nextParameter($name); + $stmt->nextParameter(-$step); + $stmt->nextParameter($step); $stmt->execute(); } } diff --git a/src/Emoticons/Emotes.php b/src/Emoticons/Emotes.php index ac7b3fc..775e5a0 100644 --- a/src/Emoticons/Emotes.php +++ b/src/Emoticons/Emotes.php @@ -22,7 +22,7 @@ class Emotes { public function getEmote(string $emoteId): EmoteInfo { $stmt = $this->cache->get('SELECT emote_id, emote_order, emote_hierarchy, emote_url FROM msz_emoticons WHERE emote_id = ?'); - $stmt->addParameter(1, $emoteId); + $stmt->nextParameter($emoteId); $stmt->execute(); $result = $stmt->getResult(); @@ -65,7 +65,7 @@ class Emotes { $stmt = $this->cache->get($query); if($hasMinRank) - $stmt->addParameter(1, $minRank); + $stmt->nextParameter($minRank); $stmt->execute(); return $stmt->getResult()->getIterator(EmoteInfo::fromResult(...)); @@ -86,7 +86,7 @@ class Emotes { return $check; $stmt = $this->cache->get('SELECT COUNT(*) FROM msz_emoticons WHERE emote_url = ?'); - $stmt->addParameter(1, $url); + $stmt->nextParameter($url); $stmt->execute(); $result = $stmt->getResult(); @@ -102,9 +102,9 @@ class Emotes { throw new InvalidArgumentException('$url is not correctly formatted: ' . $check); $stmt = $this->cache->get('INSERT INTO msz_emoticons (emote_url, emote_hierarchy, emote_order) SELECT ?, ?, COALESCE(?, (SELECT FLOOR(MAX(emote_order) / 10) * 10 + 10 FROM msz_emoticons), 10)'); - $stmt->addParameter(1, $url); - $stmt->addParameter(2, $minRank); - $stmt->addParameter(3, $order); + $stmt->nextParameter($url); + $stmt->nextParameter($minRank); + $stmt->nextParameter($order); $stmt->execute(); return $this->getEmote((string)$this->dbConn->getLastInsertId()); @@ -115,7 +115,7 @@ class Emotes { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('DELETE FROM msz_emoticons WHERE emote_id = ?'); - $stmt->addParameter(1, $infoOrId); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -135,10 +135,10 @@ class Emotes { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('UPDATE msz_emoticons SET emote_order = COALESCE(?, emote_order), emote_hierarchy = COALESCE(?, emote_hierarchy), emote_url = COALESCE(?, emote_url) WHERE emote_id = ?'); - $stmt->addParameter(1, $order); - $stmt->addParameter(2, $minRank); - $stmt->addParameter(3, $url); - $stmt->addParameter(4, $infoOrId); + $stmt->nextParameter($order); + $stmt->nextParameter($minRank); + $stmt->nextParameter($url); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -148,8 +148,8 @@ class Emotes { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('UPDATE msz_emoticons SET emote_order = emote_order + ? WHERE emote_id = ?'); - $stmt->addParameter(1, $offset); - $stmt->addParameter(2, $infoOrId); + $stmt->nextParameter($offset); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -159,7 +159,7 @@ class Emotes { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('SELECT emote_id, emote_string_order, emote_string FROM msz_emoticons_strings WHERE emote_id = ? ORDER BY emote_string_order'); - $stmt->addParameter(1, $infoOrId); + $stmt->nextParameter($infoOrId); $stmt->execute(); return $stmt->getResult()->getIterator(EmoteStringInfo::fromResult(...)); @@ -184,7 +184,7 @@ class Emotes { return $check; $stmt = $this->cache->get('SELECT COUNT(*) FROM msz_emoticons_strings WHERE emote_string = ?'); - $stmt->addParameter(1, $string); + $stmt->nextParameter($string); $stmt->execute(); $result = $stmt->getResult(); @@ -203,9 +203,9 @@ class Emotes { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('INSERT INTO msz_emoticons_strings (emote_id, emote_string, emote_string_order) SELECT ? AS target_emote_id, ?, COALESCE(?, (SELECT MAX(emote_string_order) + 1 FROM msz_emoticons_strings WHERE emote_id = target_emote_id), 1)'); - $stmt->addParameter(1, $infoOrId); - $stmt->addParameter(2, $string); - $stmt->addParameter(3, $order); + $stmt->nextParameter($infoOrId); + $stmt->nextParameter($string); + $stmt->nextParameter($order); $stmt->execute(); } @@ -214,7 +214,7 @@ class Emotes { $infoOrString = $infoOrString->string; $stmt = $this->cache->get('DELETE FROM msz_emoticons_strings WHERE emote_string = ?'); - $stmt->addParameter(1, $infoOrString); + $stmt->nextParameter($infoOrString); $stmt->execute(); } } diff --git a/src/Forum/ForumCategories.php b/src/Forum/ForumCategories.php index d8a4cdb..4daa7d5 100644 --- a/src/Forum/ForumCategories.php +++ b/src/Forum/ForumCategories.php @@ -88,12 +88,11 @@ class ForumCategories { if($hasHidden) $query .= sprintf(' %s forum_hidden %s 0', ++$args > 1 ? 'AND' : 'WHERE', $hidden ? '<>' : '='); - $args = 0; $stmt = $this->cache->get($query); if($hasParentInfo && !$isRootParent) - $stmt->addParameter(++$args, $parentInfo); + $stmt->nextParameter($parentInfo); if($hasType) - $stmt->addParameter(++$args, $type); + $stmt->nextParameter($type); $stmt->execute(); $result = $stmt->getResult(); @@ -143,19 +142,18 @@ class ForumCategories { if($hasPagination) $query .= ' LIMIT ? OFFSET ?'; - $args = 0; $stmt = $this->cache->get($query); if($hasParentInfo && !$isRootParent) { if($parentInfo instanceof ForumCategoryInfo) - $stmt->addParameter(++$args, $parentInfo->id); + $stmt->nextParameter($parentInfo->id); else - $stmt->addParameter(++$args, $parentInfo); + $stmt->nextParameter($parentInfo); } if($hasType) - $stmt->addParameter(++$args, $type); + $stmt->nextParameter($type); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -209,7 +207,7 @@ class ForumCategories { } $stmt = $this->cache->get($query); - $stmt->addParameter(1, $value); + $stmt->nextParameter($value); $stmt->execute(); $result = $stmt->getResult(); @@ -237,7 +235,7 @@ class ForumCategories { // previous implementation also WHERE'd for forum_type = link but i don't think there's any other way to get here anyhow $stmt = $this->cache->get('UPDATE msz_forum_categories SET forum_link_clicks = forum_link_clicks + 1 WHERE forum_id = ? AND forum_link_clicks IS NOT NULL'); - $stmt->addParameter(1, $categoryInfo); + $stmt->nextParameter($categoryInfo); $stmt->execute(); } @@ -246,7 +244,7 @@ class ForumCategories { $categoryInfo = $categoryInfo->id; $stmt = $this->cache->get('UPDATE msz_forum_categories SET forum_count_topics = forum_count_topics + 1 WHERE forum_id = ?'); - $stmt->addParameter(1, $categoryInfo); + $stmt->nextParameter($categoryInfo); $stmt->execute(); } @@ -255,7 +253,7 @@ class ForumCategories { $categoryInfo = $categoryInfo->id; $stmt = $this->cache->get('UPDATE msz_forum_categories SET forum_count_posts = forum_count_posts + 1 WHERE forum_id = ?'); - $stmt->addParameter(1, $categoryInfo); + $stmt->nextParameter($categoryInfo); $stmt->execute(); } @@ -275,7 +273,7 @@ class ForumCategories { . ') SELECT * FROM msz_cte_ancestry'; $stmt = $this->cache->get($query); - $stmt->addParameter(1, $categoryInfo); + $stmt->nextParameter($categoryInfo); $stmt->execute(); return $stmt->getResult()->getIterator(ForumCategoryInfo::fromResult(...)); @@ -335,17 +333,16 @@ class ForumCategories { if($userInfo instanceof UserInfo) $userInfo = $userInfo->id; - $args = 0; $stmt = $this->cache->get(sprintf( 'SELECT COUNT(*) FROM msz_forum_topics AS ft LEFT JOIN msz_forum_topics_track AS ftt ON ftt.topic_id = ft.topic_id AND ftt.user_id = ? WHERE ft.forum_id IN (%s) AND ft.topic_deleted IS NULL AND ft.topic_bumped >= NOW() - INTERVAL 1 MONTH AND (ftt.track_last_read IS NULL OR ftt.track_last_read < ft.topic_bumped)', DbTools::prepareListString($categoryInfos) )); - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); foreach($categoryInfos as $categoryInfo) { if($categoryInfo instanceof ForumCategoryInfo) - $stmt->addParameter(++$args, $categoryInfo->id); + $stmt->nextParameter($categoryInfo->id); elseif(is_string($categoryInfo) || is_int($categoryInfo)) - $stmt->addParameter(++$args, $categoryInfo); + $stmt->nextParameter($categoryInfo); else throw new InvalidArgumentException('Invalid item in $categoryInfos.'); } @@ -368,8 +365,8 @@ class ForumCategories { $categoryInfo = $categoryInfo->id; $stmt = $this->cache->get('REPLACE INTO msz_forum_topics_track (user_id, topic_id, forum_id, track_last_read) SELECT ?, topic_id, forum_id, NOW() FROM msz_forum_topics WHERE forum_id = ? AND topic_bumped >= NOW() - INTERVAL 1 MONTH'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $categoryInfo); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($categoryInfo); $stmt->execute(); } @@ -388,7 +385,7 @@ class ForumCategories { . ') SELECT forum_colour FROM msz_cte_colours WHERE forum_colour IS NOT NULL'; $stmt = $this->cache->get($query); - $stmt->addParameter(1, $categoryInfo); + $stmt->nextParameter($categoryInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -421,22 +418,21 @@ class ForumCategories { $query .= sprintf(' AND topic_id NOT IN (%s)', DbTools::prepareListString($exceptTopicInfos)); $query .= ' GROUP BY forum_id ORDER BY post_count DESC LIMIT 1'; - $args = 0; $stmt = $this->cache->get($query); - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); foreach($exceptCategoryInfos as $categoryInfo) { if($categoryInfo instanceof ForumCategoryInfo) - $stmt->addParameter(++$args, $categoryInfo->id); + $stmt->nextParameter($categoryInfo->id); elseif(is_string($categoryInfo) || is_int($categoryInfo)) - $stmt->addParameter(++$args, (string)$categoryInfo); + $stmt->nextParameter((string)$categoryInfo); else throw new InvalidArgumentException('$exceptCategoryInfos may only contain string ids or instances of ForumCategoryInfo.'); } foreach($exceptTopicInfos as $topicInfo) { if($topicInfo instanceof ForumTopicInfo) - $stmt->addParameter(++$args, $topicInfo->id); + $stmt->nextParameter($topicInfo->id); elseif(is_string($topicInfo) || is_int($topicInfo)) - $stmt->addParameter(++$args, (string)$topicInfo); + $stmt->nextParameter((string)$topicInfo); else throw new InvalidArgumentException('$exceptTopicInfos may only contain string ids or instances of ForumTopicInfo.'); } @@ -465,7 +461,7 @@ class ForumCategories { $counters = new stdClass; $stmt = $this->cache->get('SELECT ? AS target_category_id, (SELECT COUNT(*) FROM msz_forum_topics WHERE forum_id = target_category_id AND topic_deleted IS NULL) AS count_topics, (SELECT COUNT(*) FROM msz_forum_posts WHERE forum_id = target_category_id AND post_deleted IS NULL) AS count_posts'); - $stmt->addParameter(1, $categoryInfo); + $stmt->nextParameter($categoryInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -476,7 +472,7 @@ class ForumCategories { $counters->posts = $result->getInteger(2); $stmt = $this->cache->get('SELECT forum_id FROM msz_forum_categories WHERE forum_parent = ?'); - $stmt->addParameter(1, $categoryInfo); + $stmt->nextParameter($categoryInfo); $stmt->execute(); $children = []; @@ -492,9 +488,9 @@ class ForumCategories { if($updateCounters && $categoryInfo !== '0') { $stmt = $this->cache->get('UPDATE msz_forum_categories SET forum_count_topics = ?, forum_count_posts = ? WHERE forum_id = ?'); - $stmt->addParameter(1, $counters->topics); - $stmt->addParameter(2, $counters->posts); - $stmt->addParameter(3, $categoryInfo); + $stmt->nextParameter($counters->topics); + $stmt->nextParameter($counters->posts); + $stmt->nextParameter($categoryInfo); $stmt->execute(); } diff --git a/src/Forum/ForumPosts.php b/src/Forum/ForumPosts.php index de429b8..94dec2b 100644 --- a/src/Forum/ForumPosts.php +++ b/src/Forum/ForumPosts.php @@ -55,16 +55,15 @@ class ForumPosts { if($hasDeleted) $query .= sprintf(' %s post_deleted %s NULL', ++$args > 1 ? 'AND' : 'WHERE', $deleted ? 'IS NOT' : 'IS'); - $args = 0; $stmt = $this->cache->get($query); if($hasCategoryInfo) - $stmt->addParameter(++$args, $categoryInfo); + $stmt->nextParameter($categoryInfo); if($hasTopicInfo) - $stmt->addParameter(++$args, $topicInfo); + $stmt->nextParameter($topicInfo); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasUpToPostInfo) - $stmt->addParameter(++$args, $upToPostInfo); + $stmt->nextParameter($upToPostInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -164,30 +163,29 @@ class ForumPosts { $query .= ' LIMIT ? OFFSET ?'; } - $args = 0; $stmt = $this->cache->get($query); if($hasCategoryInfo) { if(is_array($categoryInfo)) { foreach($categoryInfo as $categoryInfoEntry) - $stmt->addParameter(++$args, $categoryInfoEntry instanceof ForumCategoryInfo ? $categoryInfoEntry->id : (string)$categoryInfoEntry); + $stmt->nextParameter($categoryInfoEntry instanceof ForumCategoryInfo ? $categoryInfoEntry->id : (string)$categoryInfoEntry); } else - $stmt->addParameter(++$args, $categoryInfo); + $stmt->nextParameter($categoryInfo); } if($hasTopicInfo) - $stmt->addParameter(++$args, $topicInfo); + $stmt->nextParameter($topicInfo); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasUpToPostInfo) - $stmt->addParameter(++$args, $upToPostInfo); + $stmt->nextParameter($upToPostInfo); if($hasAfterPostInfo) - $stmt->addParameter(++$args, $afterPostInfo); + $stmt->nextParameter($afterPostInfo); if($hasNewerThanDays) - $stmt->addParameter(++$args, $newerThanDays); + $stmt->nextParameter($newerThanDays); if($hasSearchQuery) - $stmt->addParameter(++$args, $searchQuery); + $stmt->nextParameter($searchQuery); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -254,10 +252,9 @@ class ForumPosts { } } - $args = 0; $stmt = $this->cache->get($query); foreach($values as $value) - $stmt->addParameter(++$args, $value); + $stmt->nextParameter($value); $stmt->execute(); $result = $stmt->getResult(); @@ -289,13 +286,13 @@ class ForumPosts { $userInfo = $userInfo->id; $stmt = $this->cache->get('INSERT INTO msz_forum_posts (topic_id, forum_id, user_id, post_ip, post_text, post_parse, post_display_signature) VALUES (?, ?, ?, INET6_ATON(?), ?, ?, ?)'); - $stmt->addParameter(1, $topicInfo); - $stmt->addParameter(2, $categoryInfo); - $stmt->addParameter(3, $userInfo); - $stmt->addParameter(4, $remoteAddr); - $stmt->addParameter(5, $body); - $stmt->addParameter(6, $bodyParser); - $stmt->addParameter(7, $displaySignature ? 1 : 0); + $stmt->nextParameter($topicInfo); + $stmt->nextParameter($categoryInfo); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($remoteAddr); + $stmt->nextParameter($body); + $stmt->nextParameter($bodyParser); + $stmt->nextParameter($displaySignature ? 1 : 0); $stmt->execute(); return $this->getPost(postId: (string)$this->dbConn->getLastInsertId()); @@ -341,11 +338,10 @@ class ForumPosts { if($bumpEdited) $fields[] = 'post_edited = NOW()'; - $args = 0; $stmt = $this->cache->get(sprintf('UPDATE msz_forum_posts SET %s WHERE post_id = ?', implode(', ', $fields))); foreach($values as $value) - $stmt->addParameter(++$args, $value); - $stmt->addParameter(++$args, $postInfo); + $stmt->nextParameter($value); + $stmt->nextParameter($postInfo); $stmt->execute(); } @@ -354,7 +350,7 @@ class ForumPosts { $postInfo = $postInfo->id; $stmt = $this->cache->get('UPDATE msz_forum_posts SET post_deleted = COALESCE(post_deleted, NOW()) WHERE post_id = ?'); - $stmt->addParameter(1, $postInfo); + $stmt->nextParameter($postInfo); $stmt->execute(); } @@ -363,7 +359,7 @@ class ForumPosts { $postInfo = $postInfo->id; $stmt = $this->cache->get('UPDATE msz_forum_posts SET post_deleted = NULL WHERE post_id = ?'); - $stmt->addParameter(1, $postInfo); + $stmt->nextParameter($postInfo); $stmt->execute(); } @@ -372,7 +368,7 @@ class ForumPosts { $postInfo = $postInfo->id; $stmt = $this->cache->get('DELETE FROM msz_forum_posts WHERE post_id = ?'); - $stmt->addParameter(1, $postInfo); + $stmt->nextParameter($postInfo); $stmt->execute(); } @@ -382,7 +378,7 @@ class ForumPosts { // intentionally including deleted posts $stmt = $this->cache->get('SELECT UNIX_TIMESTAMP(MAX(post_created)) FROM msz_forum_posts WHERE user_id = ?'); - $stmt->addParameter(1, $userInfo); + $stmt->nextParameter($userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -426,12 +422,11 @@ class ForumPosts { $query .= sprintf(' AND topic_id NOT IN (%s)', DbTools::prepareListString($exceptTopicInfos)); $query .= ' GROUP BY user_id HAVING posts_count > 0 ORDER BY posts_count DESC'; - $args = 0; $stmt = $this->cache->get($query); foreach($exceptCategoryInfos as $exceptCategoryInfo) - $stmt->addParameter(++$args, $exceptCategoryInfo instanceof ForumCategoryInfo ? $exceptCategoryInfo->id : $exceptCategoryInfo); + $stmt->nextParameter($exceptCategoryInfo instanceof ForumCategoryInfo ? $exceptCategoryInfo->id : $exceptCategoryInfo); foreach($exceptTopicInfos as $exceptTopicInfo) - $stmt->addParameter(++$args, $exceptTopicInfo instanceof ForumTopicInfo ? $exceptTopicInfo->id : $exceptTopicInfo); + $stmt->nextParameter($exceptTopicInfo instanceof ForumTopicInfo ? $exceptTopicInfo->id : $exceptTopicInfo); $stmt->execute(); $result = $stmt->getResult(); diff --git a/src/Forum/ForumTopicRedirects.php b/src/Forum/ForumTopicRedirects.php index c04f551..8a5415d 100644 --- a/src/Forum/ForumTopicRedirects.php +++ b/src/Forum/ForumTopicRedirects.php @@ -27,7 +27,7 @@ class ForumTopicRedirects { $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(1, $userInfo); + $stmt->nextParameter($userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -51,13 +51,12 @@ class ForumTopicRedirects { if($hasPagination) $query .= ' LIMIT ? OFFSET ?'; - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -69,7 +68,7 @@ class ForumTopicRedirects { $topicInfo = $topicInfo->id; $stmt = $this->cache->get('SELECT COUNT(*) FROM msz_forum_topics_redirects WHERE topic_id = ?'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -84,7 +83,7 @@ class ForumTopicRedirects { $topicInfo = $topicInfo->id; $stmt = $this->cache->get('SELECT topic_id, user_id, topic_redir_url, UNIX_TIMESTAMP(topic_redir_created) FROM msz_forum_topics_redirects WHERE topic_id = ?'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -105,9 +104,9 @@ class ForumTopicRedirects { $userInfo = $userInfo->id; $stmt = $this->cache->get('INSERT INTO msz_forum_topics_redirects (topic_id, user_id, topic_redir_url) VALUES (?, ?, ?)'); - $stmt->addParameter(1, $topicInfo); - $stmt->addParameter(2, $userInfo); - $stmt->addParameter(3, $linkTarget); + $stmt->nextParameter($topicInfo); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($linkTarget); $stmt->execute(); return $this->getTopicRedirect($topicInfo); @@ -120,7 +119,7 @@ class ForumTopicRedirects { $topicInfo = $topicInfo->id; $stmt = $this->cache->get('DELETE FROM msz_forum_topics_redirects WHERE topic_id = ?'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); } } diff --git a/src/Forum/ForumTopics.php b/src/Forum/ForumTopics.php index 1146eec..0a58205 100644 --- a/src/Forum/ForumTopics.php +++ b/src/Forum/ForumTopics.php @@ -66,17 +66,16 @@ class ForumTopics { if($hasDeleted) $query .= sprintf(' %s topic_deleted %s NULL', ++$args > 1 ? 'AND' : 'WHERE', $deleted ? 'IS NOT' : 'IS'); - $args = 0; $stmt = $this->cache->get($query); if($hasCategoryInfo) { if(is_array($categoryInfo)) { foreach($categoryInfo as $categoryInfoEntry) - $stmt->addParameter(++$args, $categoryInfoEntry instanceof ForumCategoryInfo ? $categoryInfoEntry->id : (string)$categoryInfoEntry); + $stmt->nextParameter($categoryInfoEntry instanceof ForumCategoryInfo ? $categoryInfoEntry->id : (string)$categoryInfoEntry); } else - $stmt->addParameter(++$args, $categoryInfo); + $stmt->nextParameter($categoryInfo); } if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -177,24 +176,23 @@ class ForumTopics { $query .= ' LIMIT ? OFFSET ?'; } - $args = 0; $stmt = $this->cache->get($query); if($hasCategoryInfo) { if(is_array($categoryInfo)) { foreach($categoryInfo as $categoryInfoEntry) - $stmt->addParameter(++$args, $categoryInfoEntry instanceof ForumCategoryInfo ? $categoryInfoEntry->id : (string)$categoryInfoEntry); + $stmt->nextParameter($categoryInfoEntry instanceof ForumCategoryInfo ? $categoryInfoEntry->id : (string)$categoryInfoEntry); } else - $stmt->addParameter(++$args, $categoryInfo); + $stmt->nextParameter($categoryInfo); } if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasAfterTopicId) - $stmt->addParameter(++$args, $afterTopicId); + $stmt->nextParameter($afterTopicId); if($hasSearchQuery) - $stmt->addParameter(++$args, $searchQuery); + $stmt->nextParameter($searchQuery); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -234,7 +232,7 @@ class ForumTopics { $query .= sprintf(' AND topic_deleted %s NULL', $deleted ? 'IS NOT' : 'IS'); $stmt = $this->cache->get($query); - $stmt->addParameter(1, $value); + $stmt->nextParameter($value); $stmt->execute(); $result = $stmt->getResult(); @@ -261,10 +259,10 @@ class ForumTopics { $userInfo = $userInfo->id; $stmt = $this->cache->get('INSERT INTO msz_forum_topics (forum_id, user_id, topic_type, topic_title) VALUES (?, ?, ?, ?)'); - $stmt->addParameter(1, $categoryInfo); - $stmt->addParameter(2, $userInfo); - $stmt->addParameter(3, $type); - $stmt->addParameter(4, $title); + $stmt->nextParameter($categoryInfo); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($type); + $stmt->nextParameter($title); $stmt->execute(); return $this->getTopic(topicId: (string)$this->dbConn->getLastInsertId()); @@ -301,11 +299,10 @@ class ForumTopics { if(empty($fields)) return; - $args = 0; $stmt = $this->cache->get(sprintf('UPDATE msz_forum_topics SET %s WHERE topic_id = ?', implode(', ', $fields))); foreach($values as $value) - $stmt->addParameter(++$args, $value); - $stmt->addParameter(++$args, $topicInfo); + $stmt->nextParameter($value); + $stmt->nextParameter($topicInfo); $stmt->execute(); } @@ -314,7 +311,7 @@ class ForumTopics { $topicInfo = $topicInfo->id; $stmt = $this->cache->get('UPDATE msz_forum_topics SET topic_count_views = topic_count_views + 1 WHERE topic_id = ?'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); } @@ -323,7 +320,7 @@ class ForumTopics { $topicInfo = $topicInfo->id; $stmt = $this->cache->get('UPDATE msz_forum_topics SET topic_bumped = NOW() WHERE topic_id = ?'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); } @@ -332,7 +329,7 @@ class ForumTopics { $topicInfo = $topicInfo->id; $stmt = $this->cache->get('UPDATE msz_forum_topics SET topic_locked = NOW() WHERE topic_id = ?'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); } @@ -341,7 +338,7 @@ class ForumTopics { $topicInfo = $topicInfo->id; $stmt = $this->cache->get('UPDATE msz_forum_topics SET topic_locked = NULL WHERE topic_id = ?'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); } @@ -350,11 +347,11 @@ class ForumTopics { $topicInfo = $topicInfo->id; $stmt = $this->cache->get('UPDATE msz_forum_topics SET topic_deleted = COALESCE(topic_deleted, NOW()) WHERE topic_id = ? AND topic_deleted IS NULL'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); $stmt = $this->cache->get('UPDATE msz_forum_posts AS fp SET post_deleted = (SELECT topic_deleted FROM msz_forum_topics WHERE topic_id = fp.topic_id) WHERE topic_id = ? AND post_deleted = NULL'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); } @@ -363,11 +360,11 @@ class ForumTopics { $topicInfo = $topicInfo->id; $stmt = $this->cache->get('UPDATE msz_forum_posts AS fp SET post_deleted = NULL WHERE topic_id = ? AND post_deleted = (SELECT topic_deleted FROM msz_forum_topics WHERE topic_id = fp.topic_id)'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); $stmt = $this->cache->get('UPDATE msz_forum_topics SET topic_deleted = NULL WHERE topic_id = ?'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); } @@ -376,7 +373,7 @@ class ForumTopics { $topicInfo = $topicInfo->id; $stmt = $this->cache->get('DELETE FROM msz_forum_topics WHERE topic_id = ?'); - $stmt->addParameter(1, $topicInfo); + $stmt->nextParameter($topicInfo); $stmt->execute(); } @@ -392,8 +389,8 @@ class ForumTopics { $userInfo = $userInfo->id; $stmt = $this->cache->get('SELECT COUNT(*) FROM msz_forum_posts WHERE topic_id = ? AND user_id = ?'); - $stmt->addParameter(1, $topicInfo); - $stmt->addParameter(2, $userInfo); + $stmt->nextParameter($topicInfo); + $stmt->nextParameter($userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -416,8 +413,8 @@ class ForumTopics { $query .= ' AND track_last_read = (SELECT topic_bumped FROM msz_forum_topics WHERE topic_id = ftt.topic_id AND topic_bumped >= NOW() - INTERVAL 1 MONTH)'; $stmt = $this->cache->get($query); - $stmt->addParameter(1, $userInfo instanceof UserInfo ? $userInfo->id : $userInfo); - $stmt->addParameter(2, $topicInfoIsInstance ? $topicInfo->id : $topicInfo); + $stmt->nextParameter($userInfo instanceof UserInfo ? $userInfo->id : $userInfo); + $stmt->nextParameter($topicInfoIsInstance ? $topicInfo->id : $topicInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -455,22 +452,21 @@ class ForumTopics { $query .= sprintf(' AND topic_id NOT IN (%s)', DbTools::prepareListString($exceptTopicInfos)); $query .= ' GROUP BY topic_id ORDER BY post_count DESC LIMIT 1'; - $args = 0; $stmt = $this->cache->get($query); - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); foreach($exceptCategoryInfos as $categoryInfo) { if($categoryInfo instanceof ForumCategoryInfo) - $stmt->addParameter(++$args, $categoryInfo->id); + $stmt->nextParameter($categoryInfo->id); elseif(is_string($categoryInfo) || is_int($categoryInfo)) - $stmt->addParameter(++$args, (string)$categoryInfo); + $stmt->nextParameter((string)$categoryInfo); else throw new InvalidArgumentException('$exceptCategoryInfos may only contain string ids or instances of ForumCategoryInfo.'); } foreach($exceptTopicInfos as $topicInfo) { if($topicInfo instanceof ForumTopicInfo) - $stmt->addParameter(++$args, $topicInfo->id); + $stmt->nextParameter($topicInfo->id); elseif(is_string($topicInfo) || is_int($topicInfo)) - $stmt->addParameter(++$args, (string)$topicInfo); + $stmt->nextParameter((string)$topicInfo); else throw new InvalidArgumentException('$exceptTopicInfos may only contain string ids or instances of ForumTopicInfo.'); } @@ -498,8 +494,8 @@ class ForumTopics { return true; $stmt = $this->cache->get('SELECT COUNT(*) FROM msz_forum_topics_track WHERE topic_id = ? AND user_id = ?'); - $stmt->addParameter(1, $topicInfo instanceof ForumTopicInfo ? $topicInfo->id : $topicInfo); - $stmt->addParameter(2, $userInfo instanceof UserInfo ? $userInfo->id : $userInfo); + $stmt->nextParameter($topicInfo instanceof ForumTopicInfo ? $topicInfo->id : $topicInfo); + $stmt->nextParameter($userInfo instanceof UserInfo ? $userInfo->id : $userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -528,9 +524,9 @@ class ForumTopics { } $stmt = $this->cache->get('REPLACE INTO msz_forum_topics_track (user_id, topic_id, forum_id, track_last_read) VALUES (?, ?, ?, NOW())'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $topicInfo); - $stmt->addParameter(3, $categoryInfo); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($topicInfo); + $stmt->nextParameter($categoryInfo); $stmt->execute(); } } diff --git a/src/Home/HomeRoutes.php b/src/Home/HomeRoutes.php index ffe124e..69312a7 100644 --- a/src/Home/HomeRoutes.php +++ b/src/Home/HomeRoutes.php @@ -121,7 +121,6 @@ class HomeRoutes implements RouteHandler, UrlSource { * }[] */ public function getPopularForumTopics(array $categoryIds): array { - $args = 0; $stmt = $this->dbConn->prepare( 'SELECT t.topic_id, c.forum_id, t.topic_title, c.forum_icon, t.topic_count_views' . ', (SELECT COUNT(*) FROM msz_forum_posts AS p WHERE p.topic_id = t.topic_id AND post_deleted IS NULL)' @@ -133,7 +132,7 @@ class HomeRoutes implements RouteHandler, UrlSource { ); foreach($categoryIds as $categoryId) - $stmt->addParameter(++$args, (string)$categoryId); + $stmt->nextParameter((string)$categoryId); $stmt->execute(); $topics = []; @@ -165,7 +164,6 @@ class HomeRoutes implements RouteHandler, UrlSource { * }[] */ public function getActiveForumTopics(array $categoryIds): array { - $args = 0; $stmt = $this->dbConn->prepare( 'SELECT t.topic_id, c.forum_id, t.topic_title, c.forum_icon, t.topic_count_views' . ', (SELECT COUNT(*) FROM msz_forum_posts AS p WHERE p.topic_id = t.topic_id AND post_deleted IS NULL)' @@ -178,7 +176,7 @@ class HomeRoutes implements RouteHandler, UrlSource { ); foreach($categoryIds as $categoryId) - $stmt->addParameter(++$args, (string)$categoryId); + $stmt->nextParameter((string)$categoryId); $stmt->execute(); $topics = []; diff --git a/src/Messages/MessagesDatabase.php b/src/Messages/MessagesDatabase.php index fdc52f6..6869e78 100644 --- a/src/Messages/MessagesDatabase.php +++ b/src/Messages/MessagesDatabase.php @@ -62,19 +62,18 @@ class MessagesDatabase { $query .= sprintf(' %s msg_deleted %s NULL', ++$args > 1 ? 'AND' : 'WHERE', $deleted ? 'IS NOT' : 'IS'); $query .= ' ORDER BY msg_created DESC'; - $args = 0; $stmt = $this->cache->get($query); if($hasOwnerInfo) - $stmt->addParameter(++$args, $ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); + $stmt->nextParameter($ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); if($hasAuthorInfo) - $stmt->addParameter(++$args, $authorInfo instanceof UserInfo ? $authorInfo->id : $authorInfo); + $stmt->nextParameter($authorInfo instanceof UserInfo ? $authorInfo->id : $authorInfo); if($hasRecipientInfo) - $stmt->addParameter(++$args, $recipientInfo instanceof UserInfo ? $recipientInfo->id : $recipientInfo); + $stmt->nextParameter($recipientInfo instanceof UserInfo ? $recipientInfo->id : $recipientInfo); if($hasRepliesFor) - $stmt->addParameter(++$args, $repliesFor instanceof MessageInfo ? $repliesFor->id : $repliesFor); + $stmt->nextParameter($repliesFor instanceof MessageInfo ? $repliesFor->id : $repliesFor); if($hasReplyTo) - $stmt->addParameter(++$args, $replyTo instanceof MessageInfo ? $replyTo->replyToId : $replyTo); + $stmt->nextParameter($replyTo instanceof MessageInfo ? $replyTo->replyToId : $replyTo); $stmt->execute(); $result = $stmt->getResult(); @@ -138,18 +137,18 @@ class MessagesDatabase { $stmt = $this->cache->get($query); if($hasOwnerInfo) - $stmt->addParameter(++$args, $ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); + $stmt->nextParameter($ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); if($hasAuthorInfo) - $stmt->addParameter(++$args, $authorInfo instanceof UserInfo ? $authorInfo->id : $authorInfo); + $stmt->nextParameter($authorInfo instanceof UserInfo ? $authorInfo->id : $authorInfo); if($hasRecipientInfo) - $stmt->addParameter(++$args, $recipientInfo instanceof UserInfo ? $recipientInfo->id : $recipientInfo); + $stmt->nextParameter($recipientInfo instanceof UserInfo ? $recipientInfo->id : $recipientInfo); if($hasRepliesFor) - $stmt->addParameter(++$args, $repliesFor instanceof MessageInfo ? $repliesFor->id : $repliesFor); + $stmt->nextParameter($repliesFor instanceof MessageInfo ? $repliesFor->id : $repliesFor); if($hasReplyTo) - $stmt->addParameter(++$args, $replyTo instanceof MessageInfo ? $replyTo->replyToId : $replyTo); + $stmt->nextParameter($replyTo instanceof MessageInfo ? $replyTo->replyToId : $replyTo); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -168,10 +167,10 @@ class MessagesDatabase { )); if($messageInfoOrId instanceof MessageInfo) - $stmt->addParameter(1, $useReplyTo ? $messageInfoOrId->replyToId : $messageInfoOrId->id); + $stmt->nextParameter($useReplyTo ? $messageInfoOrId->replyToId : $messageInfoOrId->id); else - $stmt->addParameter(1, $messageInfoOrId); - $stmt->addParameter(2, $ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); + $stmt->nextParameter($messageInfoOrId); + $stmt->nextParameter($ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -194,16 +193,16 @@ class MessagesDatabase { DateTimeInterface|int|null $readAt = null ): MessageInfo { $stmt = $this->cache->get('INSERT INTO msz_messages (msg_id, msg_owner_id, msg_author_id, msg_recipient_id, msg_reply_to, msg_title, msg_body, msg_parser, msg_sent, msg_read) VALUES (?, ?, ?, ?, ?, TO_BASE64(?), TO_BASE64(?), ?, FROM_UNIXTIME(?), FROM_UNIXTIME(?))'); - $stmt->addParameter(1, $messageId); - $stmt->addParameter(2, $ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); - $stmt->addParameter(3, $authorInfo instanceof UserInfo ? $authorInfo->id : $authorInfo); - $stmt->addParameter(4, $recipientInfo instanceof UserInfo ? $recipientInfo->id : $recipientInfo); - $stmt->addParameter(5, $replyTo instanceof MessageInfo ? $replyTo->id : $replyTo); - $stmt->addParameter(6, $title); - $stmt->addParameter(7, $body); - $stmt->addParameter(8, $parser); - $stmt->addParameter(9, $sentAt instanceof DateTimeInterface ? (int)$sentAt->format('U') : $sentAt); - $stmt->addParameter(10, $readAt instanceof DateTimeInterface ? (int)$readAt->format('U') : $readAt); + $stmt->nextParameter($messageId); + $stmt->nextParameter($ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); + $stmt->nextParameter($authorInfo instanceof UserInfo ? $authorInfo->id : $authorInfo); + $stmt->nextParameter($recipientInfo instanceof UserInfo ? $recipientInfo->id : $recipientInfo); + $stmt->nextParameter($replyTo instanceof MessageInfo ? $replyTo->id : $replyTo); + $stmt->nextParameter($title); + $stmt->nextParameter($body); + $stmt->nextParameter($parser); + $stmt->nextParameter($sentAt instanceof DateTimeInterface ? (int)$sentAt->format('U') : $sentAt); + $stmt->nextParameter($readAt instanceof DateTimeInterface ? (int)$readAt->format('U') : $readAt); $stmt->execute(); return $this->getMessageInfo($ownerInfo, $messageId); @@ -263,7 +262,6 @@ class MessagesDatabase { if(empty($setQuery)) return; - $args = 0; $stmt = $this->cache->get(sprintf( 'UPDATE msz_messages SET %s WHERE %s', implode(', ', $setQuery), @@ -271,9 +269,9 @@ class MessagesDatabase { )); foreach($setValues as $value) - $stmt->addParameter(++$args, $value); + $stmt->nextParameter($value); foreach($whereValues as $value) - $stmt->addParameter(++$args, $value); + $stmt->nextParameter($value); $stmt->execute(); } @@ -299,17 +297,16 @@ class MessagesDatabase { ); } - $args = 0; $stmt = $this->cache->get($query); if($hasOwnerInfo) - $stmt->addParameter(++$args, $ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); + $stmt->nextParameter($ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); if($hasMessageInfos) foreach($messageInfos as $messageInfo) { if(is_string($messageInfo)) - $stmt->addParameter(++$args, $messageInfo); + $stmt->nextParameter($messageInfo); elseif($messageInfo instanceof MessageInfo) - $stmt->addParameter(++$args, $messageInfo->id); + $stmt->nextParameter($messageInfo->id); else throw new InvalidArgumentException('$messageInfos must be an array of strings or MessageInfo instances.'); } @@ -338,17 +335,16 @@ class MessagesDatabase { ); } - $args = 0; $stmt = $this->cache->get($query); if($hasOwnerInfo) - $stmt->addParameter(++$args, $ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); + $stmt->nextParameter($ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); if($hasMessageInfos) foreach($messageInfos as $messageInfo) { if(is_string($messageInfo)) - $stmt->addParameter(++$args, $messageInfo); + $stmt->nextParameter($messageInfo); elseif($messageInfo instanceof MessageInfo) - $stmt->addParameter(++$args, $messageInfo->id); + $stmt->nextParameter($messageInfo->id); else throw new InvalidArgumentException('$messageInfos must be an array of strings or MessageInfo instances.'); } @@ -377,17 +373,16 @@ class MessagesDatabase { ); } - $args = 0; $stmt = $this->cache->get($query); if($hasOwnerInfo) - $stmt->addParameter(++$args, $ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); + $stmt->nextParameter($ownerInfo instanceof UserInfo ? $ownerInfo->id : $ownerInfo); if($hasMessageInfos) foreach($messageInfos as $messageInfo) { if(is_string($messageInfo)) - $stmt->addParameter(++$args, $messageInfo); + $stmt->nextParameter($messageInfo); elseif($messageInfo instanceof MessageInfo) - $stmt->addParameter(++$args, $messageInfo->id); + $stmt->nextParameter($messageInfo->id); else throw new InvalidArgumentException('$messageInfos must be an array of strings or MessageInfo instances.'); } diff --git a/src/News/News.php b/src/News/News.php index bd6a466..a1fc22b 100644 --- a/src/News/News.php +++ b/src/News/News.php @@ -52,10 +52,9 @@ class News { $query .= ' LIMIT ? OFFSET ?'; $stmt = $this->cache->get($query); - $args = 0; if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -93,7 +92,7 @@ class News { } $stmt = $this->cache->get($query); - $stmt->addParameter(1, $value); + $stmt->nextParameter($value); $stmt->execute(); $result = $stmt->getResult(); @@ -117,9 +116,9 @@ class News { throw new InvalidArgumentException('$description may not be empty'); $stmt = $this->cache->get('INSERT INTO msz_news_categories (category_name, category_description, category_is_hidden) VALUES (?, ?, ?)'); - $stmt->addParameter(1, $name); - $stmt->addParameter(2, $description); - $stmt->addParameter(3, $hidden ? 1 : 0); + $stmt->nextParameter($name); + $stmt->nextParameter($description); + $stmt->nextParameter($hidden ? 1 : 0); $stmt->execute(); return $this->getCategory(categoryId: (string)$this->dbConn->getLastInsertId()); @@ -130,7 +129,7 @@ class News { $infoOrId = $infoOrId->id; $stmt = $this->cache->get('DELETE FROM msz_news_categories WHERE category_id = ?'); - $stmt->addParameter(1, $infoOrId); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -158,11 +157,11 @@ class News { $hasHidden = $hidden !== null; $stmt = $this->cache->get('UPDATE msz_news_categories SET category_name = COALESCE(?, category_name), category_description = COALESCE(?, category_description), category_is_hidden = IF(?, ?, category_is_hidden) WHERE category_id = ?'); - $stmt->addParameter(1, $name); - $stmt->addParameter(2, $description); - $stmt->addParameter(3, $hasHidden ? 1 : 0); - $stmt->addParameter(4, $hidden ? 1 : 0); - $stmt->addParameter(5, $infoOrId); + $stmt->nextParameter($name); + $stmt->nextParameter($description); + $stmt->nextParameter($hasHidden ? 1 : 0); + $stmt->nextParameter($hidden ? 1 : 0); + $stmt->nextParameter($infoOrId); $stmt->execute(); } @@ -198,7 +197,7 @@ class News { $stmt = $this->cache->get($query); if($hasCategoryInfo) - $stmt->addParameter(1, $categoryInfo); + $stmt->nextParameter($categoryInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -253,14 +252,13 @@ class News { $query .= ' LIMIT ? OFFSET ?'; $stmt = $this->cache->get($query); - $args = 0; if($hasCategoryInfo) - $stmt->addParameter(++$args, $categoryInfo); + $stmt->nextParameter($categoryInfo); if($hasSearchQuery) - $stmt->addParameter(++$args, $searchQuery); + $stmt->nextParameter($searchQuery); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -270,7 +268,7 @@ class News { public function getPost(string $postId): NewsPostInfo { $stmt = $this->cache->get('SELECT post_id, category_id, user_id, comment_section_id, post_is_featured, post_title, post_text, UNIX_TIMESTAMP(post_scheduled), UNIX_TIMESTAMP(post_created), UNIX_TIMESTAMP(post_updated), UNIX_TIMESTAMP(post_deleted) FROM msz_news_posts WHERE post_id = ?'); - $stmt->addParameter(1, $postId); + $stmt->nextParameter($postId); $stmt->execute(); $result = $stmt->getResult(); @@ -304,12 +302,12 @@ class News { throw new InvalidArgumentException('$body may not be empty'); $stmt = $this->cache->get('INSERT INTO msz_news_posts (category_id, user_id, post_is_featured, post_title, post_text, post_scheduled) VALUES (?, ?, ?, ?, ?, ?)'); - $stmt->addParameter(1, $categoryInfo); - $stmt->addParameter(2, $userInfo); - $stmt->addParameter(3, $featured ? 1 : 0); - $stmt->addParameter(4, $title); - $stmt->addParameter(5, $body); - $stmt->addParameter(6, $schedule); + $stmt->nextParameter($categoryInfo); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($featured ? 1 : 0); + $stmt->nextParameter($title); + $stmt->nextParameter($body); + $stmt->nextParameter($schedule); $stmt->execute(); return $this->getPost((string)$this->dbConn->getLastInsertId()); @@ -320,7 +318,7 @@ class News { $postInfo = $postInfo->id; $stmt = $this->cache->get('UPDATE msz_news_posts SET post_deleted = COALESCE(post_deleted, NOW()) WHERE post_id = ?'); - $stmt->addParameter(1, $postInfo); + $stmt->nextParameter($postInfo); $stmt->execute(); } @@ -329,7 +327,7 @@ class News { $postInfo = $postInfo->id; $stmt = $this->cache->get('UPDATE msz_news_posts SET post_deleted = NULL WHERE post_id = ?'); - $stmt->addParameter(1, $postInfo); + $stmt->nextParameter($postInfo); $stmt->execute(); } @@ -339,7 +337,7 @@ class News { // should this enforce a soft delete first? (AND post_deleted IS NOT NULL) $stmt = $this->cache->get('DELETE FROM msz_news_posts WHERE post_id = ?'); - $stmt->addParameter(1, $postInfo); + $stmt->nextParameter($postInfo); $stmt->execute(); } @@ -377,15 +375,15 @@ class News { $hasFeatured = $featured !== null; $stmt = $this->cache->get('UPDATE msz_news_posts SET category_id = COALESCE(?, category_id), user_id = IF(?, ?, user_id), post_is_featured = IF(?, ?, post_is_featured), post_title = COALESCE(?, post_title), post_text = COALESCE(?, post_text), post_scheduled = COALESCE(?, post_scheduled) WHERE post_id = ?'); - $stmt->addParameter(1, $categoryInfo); - $stmt->addParameter(2, $updateUserInfo ? 1 : 0); - $stmt->addParameter(3, $userInfo); - $stmt->addParameter(4, $hasFeatured ? 1 : 0); - $stmt->addParameter(5, $featured ? 1 : 0); - $stmt->addParameter(6, $title); - $stmt->addParameter(7, $body); - $stmt->addParameter(8, $schedule); - $stmt->addParameter(9, $postInfo); + $stmt->nextParameter($categoryInfo); + $stmt->nextParameter($updateUserInfo ? 1 : 0); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($hasFeatured ? 1 : 0); + $stmt->nextParameter($featured ? 1 : 0); + $stmt->nextParameter($title); + $stmt->nextParameter($body); + $stmt->nextParameter($schedule); + $stmt->nextParameter($postInfo); $stmt->execute(); } @@ -399,8 +397,8 @@ class News { $commentsCategory = $commentsCategory->id; $stmt = $this->cache->get('UPDATE msz_news_posts SET comment_section_id = ? WHERE post_id = ?'); - $stmt->addParameter(1, $commentsCategory); - $stmt->addParameter(2, $postInfo); + $stmt->nextParameter($commentsCategory); + $stmt->nextParameter($postInfo); $stmt->execute(); } } diff --git a/src/Perms/Permissions.php b/src/Perms/Permissions.php index 147471b..4caa15f 100644 --- a/src/Perms/Permissions.php +++ b/src/Perms/Permissions.php @@ -55,20 +55,19 @@ class Permissions { if($hasCategoryName) $query .= ' AND perms_category ' . ($categoryNamesIsArray ? sprintf('IN (%s)', DbTools::prepareListString($categoryNames)) : '= ?'); - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo instanceof UserInfo ? $userInfo->id : $userInfo); + $stmt->nextParameter($userInfo instanceof UserInfo ? $userInfo->id : $userInfo); if($hasRoleInfo) - $stmt->addParameter(++$args, $roleInfo instanceof RoleInfo ? $roleInfo->id : $roleInfo); + $stmt->nextParameter($roleInfo instanceof RoleInfo ? $roleInfo->id : $roleInfo); if($hasForumCategoryInfo) - $stmt->addParameter(++$args, $forumCategoryInfo instanceof ForumCategoryInfo ? $forumCategoryInfo->id : $forumCategoryInfo); + $stmt->nextParameter($forumCategoryInfo instanceof ForumCategoryInfo ? $forumCategoryInfo->id : $forumCategoryInfo); if($hasCategoryName) { if($categoryNamesIsArray) { foreach($categoryNames as $name) - $stmt->addParameter(++$args, $name); + $stmt->nextParameter($name); } else - $stmt->addParameter(++$args, $categoryNames); + $stmt->nextParameter($categoryNames); } $stmt->execute(); @@ -107,12 +106,12 @@ class Permissions { return; $stmt = $this->cache->get('INSERT INTO msz_perms (user_id, role_id, forum_id, perms_category, perms_allow, perms_deny) VALUES (?, ?, ?, ?, ?, ?)'); - $stmt->addParameter(1, $userInfo instanceof UserInfo ? $userInfo->id : $userInfo); - $stmt->addParameter(2, $roleInfo instanceof RoleInfo ? $roleInfo->id : $roleInfo); - $stmt->addParameter(3, $forumCategoryInfo instanceof ForumCategoryInfo ? $forumCategoryInfo->id : $forumCategoryInfo); - $stmt->addParameter(4, $categoryName); - $stmt->addParameter(5, $allow); - $stmt->addParameter(6, $deny); + $stmt->nextParameter($userInfo instanceof UserInfo ? $userInfo->id : $userInfo); + $stmt->nextParameter($roleInfo instanceof RoleInfo ? $roleInfo->id : $roleInfo); + $stmt->nextParameter($forumCategoryInfo instanceof ForumCategoryInfo ? $forumCategoryInfo->id : $forumCategoryInfo); + $stmt->nextParameter($categoryName); + $stmt->nextParameter($allow); + $stmt->nextParameter($deny); $stmt->execute(); } @@ -136,19 +135,18 @@ class Permissions { if($hasCategoryNames) $query .= ' AND perms_category ' . ($categoryNamesIsArray ? sprintf('IN (%s)', DbTools::prepareListString($categoryNames)) : '= ?'); - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo instanceof UserInfo ? $userInfo->id : $userInfo); + $stmt->nextParameter($userInfo instanceof UserInfo ? $userInfo->id : $userInfo); if($hasRoleInfo) - $stmt->addParameter(++$args, $roleInfo instanceof RoleInfo ? $roleInfo->id : $roleInfo); + $stmt->nextParameter($roleInfo instanceof RoleInfo ? $roleInfo->id : $roleInfo); if($hasForumCategoryInfo) - $stmt->addParameter(++$args, $forumCategoryInfo instanceof ForumCategoryInfo ? $forumCategoryInfo->id : $forumCategoryInfo); + $stmt->nextParameter($forumCategoryInfo instanceof ForumCategoryInfo ? $forumCategoryInfo->id : $forumCategoryInfo); if($categoryNamesIsArray) { foreach($categoryNames as $name) - $stmt->addParameter(++$args, $name); + $stmt->nextParameter($name); } else - $stmt->addParameter(++$args, $categoryNames); + $stmt->nextParameter($categoryNames); $stmt->execute(); } @@ -165,14 +163,13 @@ class Permissions { $query .= sprintf(' AND forum_id %s', $hasForumCategoryInfo ? '= ?' : 'IS NULL'); $query .= sprintf(' AND user_id %s', $hasUserInfo ? '= ?' : 'IS NULL'); - $args = 0; $stmt = $this->cache->get($query); - $stmt->addParameter(++$args, $perms); - $stmt->addParameter(++$args, $categoryName); + $stmt->nextParameter($perms); + $stmt->nextParameter($categoryName); if($hasForumCategoryInfo) - $stmt->addParameter(++$args, $forumCategoryInfo instanceof ForumCategoryInfo ? $forumCategoryInfo->id : $forumCategoryInfo); + $stmt->nextParameter($forumCategoryInfo instanceof ForumCategoryInfo ? $forumCategoryInfo->id : $forumCategoryInfo); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo instanceof UserInfo ? $userInfo->id : $userInfo); + $stmt->nextParameter($userInfo instanceof UserInfo ? $userInfo->id : $userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -198,18 +195,17 @@ class Permissions { $query .= sprintf(' AND user_id %s', $hasUserInfo ? '= ?' : 'IS NULL'); $query .= ' GROUP BY perms_category'; - $args = 0; $stmt = $this->cache->get($query); if($categoryNamesIsArray) { foreach($categoryNames as $name) - $stmt->addParameter(++$args, $name); + $stmt->nextParameter($name); } else - $stmt->addParameter(++$args, $categoryNames); + $stmt->nextParameter($categoryNames); if($hasForumCategoryInfo) - $stmt->addParameter(++$args, $forumCategoryInfo instanceof ForumCategoryInfo ? $forumCategoryInfo->id : $forumCategoryInfo); + $stmt->nextParameter($forumCategoryInfo instanceof ForumCategoryInfo ? $forumCategoryInfo->id : $forumCategoryInfo); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo instanceof UserInfo ? $userInfo->id : $userInfo); + $stmt->nextParameter($userInfo instanceof UserInfo ? $userInfo->id : $userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -321,13 +317,12 @@ class Permissions { if($doGuest) { self::precalculatePermissionsLog('Calculating guest permission for forum category #%s...', $currentCatId); - $args = 0; $stmt = $this->cache->get(sprintf( 'SELECT perms_category, BIT_OR(perms_allow) & ~BIT_OR(perms_deny) FROM msz_perms WHERE forum_id IN (%s) AND user_id IS NULL AND role_id IS NULL GROUP BY perms_category', DbTools::prepareListString($catIds) )); foreach($catIds as $catId) - $stmt->addParameter(++$args, $catId); + $stmt->nextParameter($catId); $stmt->execute(); $insert->reset(); diff --git a/src/Profile/ProfileFields.php b/src/Profile/ProfileFields.php index f2a79fb..df95d36 100644 --- a/src/Profile/ProfileFields.php +++ b/src/Profile/ProfileFields.php @@ -33,13 +33,12 @@ class ProfileFields { $query .= ' ORDER BY field_order ASC'; $stmt = $this->cache->get($query); - $args = 0; if($hasFieldValueInfos) foreach($fieldValueInfos as $fieldValueInfo) { if(!($fieldValueInfo instanceof ProfileFieldValueInfo)) throw new InvalidArgumentException('All values in $fieldValueInfos must be of ProfileFieldValueInfo type.'); - $stmt->addParameter(++$args, $fieldValueInfo->fieldId); + $stmt->nextParameter($fieldValueInfo->fieldId); } $stmt->execute(); @@ -49,7 +48,7 @@ class ProfileFields { public function getField(string $fieldId): ProfileFieldInfo { $stmt = $this->cache->get('SELECT field_id, field_order, field_key, field_title, field_regex FROM msz_profile_fields WHERE field_id = ?'); - $stmt->addParameter(1, $fieldId); + $stmt->nextParameter($fieldId); $stmt->execute(); $result = $stmt->getResult(); @@ -100,20 +99,19 @@ class ProfileFields { ); $stmt = $this->cache->get($query); - $args = 0; if($hasFieldInfos) foreach($fieldInfos as $fieldInfo) { if(!($fieldInfo instanceof ProfileFieldInfo)) throw new InvalidArgumentException('All values in $fieldInfos must be of ProfileFieldInfo type.'); - $stmt->addParameter(++$args, $fieldInfo->id); + $stmt->nextParameter($fieldInfo->id); } if($hasFieldValueInfos) foreach($fieldValueInfos as $fieldValueInfo) { if(!($fieldValueInfo instanceof ProfileFieldValueInfo)) throw new InvalidArgumentException('All values in $fieldValueInfos must be of ProfileFieldValueInfo type.'); - $stmt->addParameter(++$args, $fieldValueInfo->formatId); + $stmt->nextParameter($fieldValueInfo->formatId); } $stmt->execute(); @@ -123,7 +121,7 @@ class ProfileFields { public function getFieldFormat(string $formatId): ProfileFieldFormatInfo { $stmt = $this->cache->get('SELECT format_id, field_id, format_regex, format_link, format_display FROM msz_profile_fields_formats WHERE format_id = ?'); - $stmt->addParameter(1, $formatId); + $stmt->nextParameter($formatId); $stmt->execute(); $result = $stmt->getResult(); @@ -141,8 +139,8 @@ class ProfileFields { $fieldInfo = $fieldInfo->id; $stmt = $this->cache->get('SELECT format_id, field_id, format_regex, format_link, format_display FROM msz_profile_fields_formats WHERE field_id = ? AND (format_regex IS NULL OR ? REGEXP format_regex) ORDER BY format_regex IS NULL ASC'); - $stmt->addParameter(1, $fieldInfo); - $stmt->addParameter(2, $value); + $stmt->nextParameter($fieldInfo); + $stmt->nextParameter($value); $stmt->execute(); $result = $stmt->getResult(); @@ -160,7 +158,7 @@ class ProfileFields { // i don't really want to bother with the join for the ordering so i'll just do that somewhere in PHP for now // will probably add the ability for people to order them in whatever way they want, as well as visibility controls $stmt = $this->cache->get('SELECT field_id, user_id, format_id, field_value FROM msz_profile_fields_values WHERE user_id = ?'); - $stmt->addParameter(1, $userInfo); + $stmt->nextParameter($userInfo); $stmt->execute(); return $stmt->getResult()->getIterator(ProfileFieldValueInfo::fromResult(...)); @@ -176,8 +174,8 @@ class ProfileFields { $userInfo = $userInfo->id; $stmt = $this->cache->get('SELECT field_id, user_id, format_id, field_value FROM msz_profile_fields_values WHERE field_id = ? AND user_id = ?'); - $stmt->addParameter(1, $fieldInfo); - $stmt->addParameter(2, $userInfo); + $stmt->nextParameter($fieldInfo); + $stmt->nextParameter($userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -234,17 +232,16 @@ class ProfileFields { ]; } - $args = 0; $stmt = $this->cache->get( 'REPLACE INTO msz_profile_fields_values (field_id, user_id, format_id, field_value) VALUES ' . DbTools::prepareListString($rows, '(?, ?, ?, ?)') ); foreach($rows as $row) { - $stmt->addParameter(++$args, $row[0]); - $stmt->addParameter(++$args, $userInfo); - $stmt->addParameter(++$args, $row[1]); - $stmt->addParameter(++$args, $row[2]); + $stmt->nextParameter($row[0]); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($row[1]); + $stmt->nextParameter($row[2]); } $stmt->execute(); @@ -272,14 +269,13 @@ class ProfileFields { throw new InvalidArgumentException('$fieldInfos array may only contain string IDs or instances of ProfileFieldInfo'); } - $args = 0; $stmt = $this->cache->get(sprintf( 'DELETE FROM msz_profile_fields_values WHERE user_id = ? AND field_id IN (%s)', DbTools::prepareListString($fieldInfos) )); - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); foreach($fieldInfos as $value) - $stmt->addParameter(++$args, $value); + $stmt->nextParameter($value); $stmt->execute(); } } diff --git a/src/Users/Bans.php b/src/Users/Bans.php index e318144..7ad0240 100644 --- a/src/Users/Bans.php +++ b/src/Users/Bans.php @@ -42,10 +42,9 @@ class Bans { if($hasUserInfo) $query .= sprintf(' %s user_id = ?', ++$args > 1 ? 'AND' : 'WHERE'); - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -90,13 +89,12 @@ class Bans { if($hasPagination) $query .= ' LIMIT ? OFFSET ?'; - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -105,7 +103,7 @@ class Bans { public function getBan(string $banId): BanInfo { $stmt = $this->cache->get('SELECT ban_id, user_id, mod_id, ban_severity, ban_reason_public, ban_reason_private, UNIX_TIMESTAMP(ban_created), UNIX_TIMESTAMP(ban_expires) FROM msz_users_bans WHERE ban_id = ?'); - $stmt->addParameter(1, $banId); + $stmt->nextParameter($banId); $stmt->execute(); $result = $stmt->getResult(); @@ -124,8 +122,8 @@ class Bans { // orders by ban_expires descending with NULLs (permanent) first $stmt = $this->cache->get('SELECT COUNT(*) FROM msz_users_bans WHERE user_id = ? AND ban_severity >= ? AND (ban_expires IS NULL OR ban_expires > NOW()) ORDER BY ban_expires IS NULL DESC, ban_expires DESC'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $minimumSeverity); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($minimumSeverity); $stmt->execute(); $result = $stmt->getResult(); @@ -141,8 +139,8 @@ class Bans { // orders by ban_expires descending with NULLs (permanent) first $stmt = $this->cache->get('SELECT ban_id, user_id, mod_id, ban_severity, ban_reason_public, ban_reason_private, UNIX_TIMESTAMP(ban_created), UNIX_TIMESTAMP(ban_expires) FROM msz_users_bans WHERE user_id = ? AND ban_severity >= ? AND (ban_expires IS NULL OR ban_expires > NOW()) ORDER BY ban_expires IS NULL DESC, ban_expires DESC'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $minimumSeverity); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($minimumSeverity); $stmt->execute(); $result = $stmt->getResult(); @@ -167,12 +165,12 @@ class Bans { $expires = (int)$expires->format('U'); $stmt = $this->cache->get('INSERT INTO msz_users_bans (user_id, mod_id, ban_severity, ban_reason_public, ban_reason_private, ban_expires) VALUES (?, ?, ?, ?, ?, FROM_UNIXTIME(?))'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $modInfo); - $stmt->addParameter(3, $severity); - $stmt->addParameter(4, $publicReason); - $stmt->addParameter(5, $privateReason); - $stmt->addParameter(6, $expires); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($modInfo); + $stmt->nextParameter($severity); + $stmt->nextParameter($publicReason); + $stmt->nextParameter($privateReason); + $stmt->nextParameter($expires); $stmt->execute(); return $this->getBan((string)$this->dbConn->getLastInsertId()); @@ -190,14 +188,13 @@ class Bans { DbTools::prepareListString($banInfos) )); - $args = 0; foreach($banInfos as $banInfo) { if($banInfo instanceof BanInfo) $banInfo = $banInfo->id; elseif(!is_string($banInfo)) throw new InvalidArgumentException('$banInfos must be strings of instances of BanInfo.'); - $stmt->addParameter(++$args, $banInfo); + $stmt->nextParameter($banInfo); } $stmt->execute(); diff --git a/src/Users/ModNotes.php b/src/Users/ModNotes.php index 34534e9..f7ffc0d 100644 --- a/src/Users/ModNotes.php +++ b/src/Users/ModNotes.php @@ -36,12 +36,11 @@ class ModNotes { if($hasAuthorInfo) $query .= sprintf(' %s author_id = ?', ++$args > 1 ? 'AND' : 'WHERE'); - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasAuthorInfo) - $stmt->addParameter(++$args, $authorInfo); + $stmt->nextParameter($authorInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -80,15 +79,14 @@ class ModNotes { if($hasPagination) $query .= ' LIMIT ? OFFSET ?'; - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasAuthorInfo) - $stmt->addParameter(++$args, $authorInfo); + $stmt->nextParameter($authorInfo); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -97,7 +95,7 @@ class ModNotes { public function getNote(string $noteId): ModNoteInfo { $stmt = $this->cache->get('SELECT note_id, user_id, author_id, UNIX_TIMESTAMP(note_created), note_title, note_body FROM msz_users_modnotes WHERE note_id = ?'); - $stmt->addParameter(1, $noteId); + $stmt->nextParameter($noteId); $stmt->execute(); $result = $stmt->getResult(); @@ -119,10 +117,10 @@ class ModNotes { $authorInfo = $authorInfo->id; $stmt = $this->cache->get('INSERT INTO msz_users_modnotes (user_id, author_id, note_title, note_body) VALUES (?, ?, ?, ?)'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $authorInfo); - $stmt->addParameter(3, $title); - $stmt->addParameter(4, $body); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($authorInfo); + $stmt->nextParameter($title); + $stmt->nextParameter($body); $stmt->execute(); return $this->getNote((string)$this->dbConn->getLastInsertId()); @@ -140,14 +138,13 @@ class ModNotes { DbTools::prepareListString($noteInfos) )); - $args = 0; foreach($noteInfos as $noteInfo) { if($noteInfo instanceof ModNoteInfo) $noteInfo = $noteInfo->id; elseif(!is_string($noteInfo)) throw new InvalidArgumentException('$noteInfos must be strings of instances of ModNoteInfo.'); - $stmt->addParameter(++$args, $noteInfo); + $stmt->nextParameter($noteInfo); } $stmt->execute(); @@ -162,9 +159,9 @@ class ModNotes { $noteInfo = $noteInfo->id; $stmt = $this->cache->get('UPDATE msz_users_modnotes SET note_title = COALESCE(?, note_title), note_body = COALESCE(?, note_body) WHERE note_id = ?'); - $stmt->addParameter(1, $title); - $stmt->addParameter(2, $body); - $stmt->addParameter(3, $noteInfo); + $stmt->nextParameter($title); + $stmt->nextParameter($body); + $stmt->nextParameter($noteInfo); $stmt->execute(); } } diff --git a/src/Users/Roles.php b/src/Users/Roles.php index f4c41fd..fb8db21 100644 --- a/src/Users/Roles.php +++ b/src/Users/Roles.php @@ -37,10 +37,9 @@ class Roles { if($hasHidden) $query .= sprintf(' %s role_hidden %s 0', ++$args > 1 ? 'AND' : 'WHERE', $hidden ? '=' : '<>'); - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); $stmt->execute(); $count = 0; @@ -96,7 +95,7 @@ class Roles { public function getRole(string $roleId): RoleInfo { $stmt = $this->cache->get('SELECT role_id, role_string, role_hierarchy, role_name, role_title, role_description, role_hidden, role_can_leave, role_colour, UNIX_TIMESTAMP(role_created) FROM msz_roles WHERE role_id = ?'); - $stmt->addParameter(1, $roleId); + $stmt->nextParameter($roleId); $stmt->execute(); $result = $stmt->getResult(); @@ -151,14 +150,13 @@ class Roles { DbTools::prepareListString($roleInfos) )); - $args = 0; foreach($roleInfos as $roleInfo) { if($roleInfo instanceof RoleInfo) $roleInfo = $roleInfo->id; elseif(!is_string($roleInfo)) throw new InvalidArgumentException('$roleInfos must be strings of instances of RoleInfo.'); - $stmt->addParameter(++$args, $roleInfo); + $stmt->nextParameter($roleInfo); } $stmt->execute(); @@ -223,7 +221,7 @@ class Roles { $roleInfo = $roleInfo->id; $stmt = $this->cache->get('SELECT COUNT(*) FROM msz_users_roles WHERE role_id = ?'); - $stmt->addParameter(1, $roleInfo); + $stmt->nextParameter($roleInfo); $stmt->execute(); $count = 0; diff --git a/src/Users/Users.php b/src/Users/Users.php index d3ba114..68be1b7 100644 --- a/src/Users/Users.php +++ b/src/Users/Users.php @@ -73,16 +73,15 @@ class Users { if($hasDeleted) $query .= sprintf(' %s user_deleted %s NULL', ++$args > 1 ? 'AND' : 'WHERE', $deleted ? 'IS NOT' : 'IS'); - $args = 0; $stmt = $this->cache->get($query); if($hasRoleInfo) - $stmt->addParameter(++$args, $roleInfo); + $stmt->nextParameter($roleInfo); if($hasAfter) - $stmt->addParameter(++$args, $after); + $stmt->nextParameter($after); if($hasLastActiveInMinutes) - $stmt->addParameter(++$args, $lastActiveInMinutes); + $stmt->nextParameter($lastActiveInMinutes); if($hasNewerThanDays) - $stmt->addParameter(++$args, $newerThanDays); + $stmt->nextParameter($newerThanDays); $stmt->execute(); $result = $stmt->getResult(); @@ -192,23 +191,22 @@ class Users { elseif($hasPagination) $query .= ' LIMIT ? OFFSET ?'; - $args = 0; $stmt = $this->cache->get($query); if($hasRoleInfo) - $stmt->addParameter(++$args, $roleInfo); + $stmt->nextParameter($roleInfo); if($hasAfter) - $stmt->addParameter(++$args, $after); + $stmt->nextParameter($after); if($hasLastActiveInMinutes) - $stmt->addParameter(++$args, $lastActiveInMinutes); + $stmt->nextParameter($lastActiveInMinutes); if($hasNewerThanDays) - $stmt->addParameter(++$args, $newerThanDays); + $stmt->nextParameter($newerThanDays); if($hasBirthdate) - $stmt->addParameter(++$args, $birthdate->format('%-m-d')); + $stmt->nextParameter($birthdate->format('%-m-d')); if($hasSearchQuery) - $stmt->addParameter(++$args, $searchQuery); + $stmt->nextParameter($searchQuery); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -264,14 +262,13 @@ class Users { if($selectMail) $query .= sprintf(' %s email = ?', ++$args > 1 ? 'OR' : 'WHERE'); - $args = 0; $stmt = $this->cache->get($query); if($selectId) - $stmt->addParameter(++$args, $value); + $stmt->nextParameter($value); if($selectName) - $stmt->addParameter(++$args, $value); + $stmt->nextParameter($value); if($selectMail) - $stmt->addParameter(++$args, $value); + $stmt->nextParameter($value); $stmt->execute(); $result = $stmt->getResult(); @@ -302,13 +299,13 @@ class Users { throw new InvalidArgumentException('$email is not a valid e-mail address.'); $stmt = $this->cache->get('INSERT INTO msz_users (username, password, email, register_ip, last_ip, user_country, display_role) VALUES (?, ?, ?, INET6_ATON(?), INET6_ATON(?), ?, ?)'); - $stmt->addParameter(1, $name); - $stmt->addParameter(2, $password); - $stmt->addParameter(3, $email); - $stmt->addParameter(4, $remoteAddr); - $stmt->addParameter(5, $remoteAddr); - $stmt->addParameter(6, $countryCode); - $stmt->addParameter(7, $displayRoleInfo); + $stmt->nextParameter($name); + $stmt->nextParameter($password); + $stmt->nextParameter($email); + $stmt->nextParameter($remoteAddr); + $stmt->nextParameter($remoteAddr); + $stmt->nextParameter($countryCode); + $stmt->nextParameter($displayRoleInfo); $stmt->execute(); return $this->getUser((string)$this->dbConn->getLastInsertId(), self::GET_USER_ID); @@ -427,11 +424,10 @@ class Users { if(empty($fields)) return; - $args = 0; $stmt = $this->cache->get(sprintf('UPDATE msz_users SET %s WHERE user_id = ?', implode(', ', $fields))); foreach($values as $value) - $stmt->addParameter(++$args, $value); - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($value); + $stmt->nextParameter($userInfo); $stmt->execute(); } @@ -443,8 +439,8 @@ class Users { $userInfo = $userInfo->id; $stmt = $this->cache->get('UPDATE msz_users SET user_active = NOW(), last_ip = INET6_ATON(?) WHERE user_id = ?'); - $stmt->addParameter(1, $remoteAddr); - $stmt->addParameter(2, $userInfo); + $stmt->nextParameter($remoteAddr); + $stmt->nextParameter($userInfo); $stmt->execute(); } @@ -475,12 +471,11 @@ class Users { elseif(empty($roleInfos)) return []; - $args = 0; $stmt = $this->cache->get(sprintf( 'SELECT role_id FROM msz_users_roles WHERE user_id = ? AND role_id IN (%s)', DbTools::prepareListString($roleInfos) )); - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); foreach($roleInfos as $roleInfo) { if($roleInfo instanceof RoleInfo) @@ -488,7 +483,7 @@ class Users { elseif(!is_string($roleInfo)) throw new InvalidArgumentException('$roleInfos must be strings of instances of RoleInfo.'); - $stmt->addParameter(++$args, $roleInfo); + $stmt->nextParameter($roleInfo); } $stmt->execute(); @@ -519,15 +514,14 @@ class Users { DbTools::prepareListString($roleInfos, '(?, ?)') )); - $args = 0; foreach($roleInfos as $roleInfo) { if($roleInfo instanceof RoleInfo) $roleInfo = $roleInfo->id; elseif(!is_string($roleInfo)) throw new InvalidArgumentException('$roleInfos must be strings of instances of RoleInfo.'); - $stmt->addParameter(++$args, $userInfo); - $stmt->addParameter(++$args, $roleInfo); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($roleInfo); } $stmt->execute(); @@ -545,12 +539,11 @@ class Users { elseif(empty($roleInfos)) return; - $args = 0; $stmt = $this->cache->get(sprintf( 'DELETE FROM msz_users_roles WHERE user_id = ? AND role_id IN (%s)', DbTools::prepareListString($roleInfos) )); - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); foreach($roleInfos as $roleInfo) { if($roleInfo instanceof RoleInfo) @@ -558,7 +551,7 @@ class Users { elseif(!is_string($roleInfo)) throw new InvalidArgumentException('$roleInfos must be strings of instances of RoleInfo.'); - $stmt->addParameter(++$args, $roleInfo); + $stmt->nextParameter($roleInfo); } $stmt->execute(); @@ -580,7 +573,7 @@ class Users { } $stmt = $this->cache->get(sprintf('SELECT role_colour FROM msz_roles WHERE role_id = %s', $query)); - $stmt->addParameter(1, $value); + $stmt->nextParameter($value); $stmt->execute(); $result = $stmt->getResult(); @@ -592,7 +585,7 @@ class Users { $userInfo = $userInfo->id; $stmt = $this->cache->get('SELECT MAX(role_hierarchy) FROM msz_roles WHERE role_id IN (SELECT role_id FROM msz_users_roles WHERE user_id = ?)'); - $stmt->addParameter(1, $userInfo); + $stmt->nextParameter($userInfo); $stmt->execute(); $result = $stmt->getResult(); @@ -601,7 +594,7 @@ class Users { public function checkNameInUse(string $name): bool { $stmt = $this->cache->get('SELECT COUNT(*) FROM msz_users WHERE username = ?'); - $stmt->addParameter(1, $name); + $stmt->nextParameter($name); $stmt->execute(); $result = $stmt->getResult(); if(!$result->next()) @@ -646,7 +639,7 @@ class Users { public function checkEMailAddressInUse(string $address): bool { $stmt = $this->cache->get('SELECT COUNT(*) FROM msz_users WHERE email = ?'); - $stmt->addParameter(1, $address); + $stmt->nextParameter($address); $stmt->execute(); $result = $stmt->getResult(); if(!$result->next()) diff --git a/src/Users/Warnings.php b/src/Users/Warnings.php index 4c21c38..6182967 100644 --- a/src/Users/Warnings.php +++ b/src/Users/Warnings.php @@ -45,9 +45,9 @@ class Warnings { $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasBacklog) - $stmt->addParameter(++$args, $backlog); + $stmt->nextParameter($backlog); $stmt->execute(); $result = $stmt->getResult(); @@ -95,15 +95,14 @@ class Warnings { if($hasPagination) $query .= ' LIMIT ? OFFSET ?'; - $args = 0; $stmt = $this->cache->get($query); if($hasUserInfo) - $stmt->addParameter(++$args, $userInfo); + $stmt->nextParameter($userInfo); if($hasBacklog) - $stmt->addParameter(++$args, $backlog); + $stmt->nextParameter($backlog); if($hasPagination) { - $stmt->addParameter(++$args, $pagination->range); - $stmt->addParameter(++$args, $pagination->offset); + $stmt->nextParameter($pagination->range); + $stmt->nextParameter($pagination->offset); } $stmt->execute(); @@ -112,7 +111,7 @@ class Warnings { public function getWarning(string $warnId): WarningInfo { $stmt = $this->cache->get('SELECT warn_id, user_id, mod_id, warn_body, UNIX_TIMESTAMP(warn_created) FROM msz_users_warnings WHERE warn_id = ?'); - $stmt->addParameter(1, $warnId); + $stmt->nextParameter($warnId); $stmt->execute(); $result = $stmt->getResult(); @@ -134,9 +133,9 @@ class Warnings { $modInfo = $modInfo->id; $stmt = $this->cache->get('INSERT INTO msz_users_warnings (user_id, mod_id, warn_body) VALUES (?, ?, ?)'); - $stmt->addParameter(1, $userInfo); - $stmt->addParameter(2, $modInfo); - $stmt->addParameter(3, $body); + $stmt->nextParameter($userInfo); + $stmt->nextParameter($modInfo); + $stmt->nextParameter($body); $stmt->execute(); return $this->getWarning((string)$this->dbConn->getLastInsertId()); @@ -154,14 +153,13 @@ class Warnings { DbTools::prepareListString($warnInfos) )); - $args = 0; foreach($warnInfos as $warnInfo) { if($warnInfo instanceof WarningInfo) $warnInfo = $warnInfo->id; elseif(!is_string($warnInfo)) throw new InvalidArgumentException('$warnInfos must be strings of instances of WarningInfo.'); - $stmt->addParameter(++$args, $warnInfo); + $stmt->nextParameter($warnInfo); } $stmt->execute();