Skip to content

Commit

Permalink
Compatibility PHP 8.2 for running automated tests (#5826)
Browse files Browse the repository at this point in the history
https://php.net/pdo.errorinfo has slightly changed signature
  • Loading branch information
Alkarex committed Nov 7, 2023
1 parent 711e215 commit 8534555
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/Models/CategoryDAO.php
Expand Up @@ -82,11 +82,11 @@ protected function addColumn(string $name): bool {
return false;
}

/** @param array<string> $errorInfo */
/** @param array<string|int> $errorInfo */
protected function autoUpdateDb(array $errorInfo): bool {
if (isset($errorInfo[0])) {
if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_FIELD_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_COLUMN) {
$errorLines = explode("\n", $errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise
$errorLines = explode("\n", (string)$errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise
foreach (['kind', 'lastUpdate', 'error', 'attributes'] as $column) {
if (stripos($errorLines[0], $column) !== false) {
return $this->addColumn($column);
Expand Down
2 changes: 1 addition & 1 deletion app/Models/CategoryDAOSQLite.php
Expand Up @@ -2,7 +2,7 @@

class FreshRSS_CategoryDAOSQLite extends FreshRSS_CategoryDAO {

/** @param array<string> $errorInfo */
/** @param array<int|string> $errorInfo */
protected function autoUpdateDb(array $errorInfo): bool {
if ($tableInfo = $this->pdo->query("PRAGMA table_info('category')")) {
$columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1);
Expand Down
7 changes: 4 additions & 3 deletions app/Models/EntryDAO.php
Expand Up @@ -65,11 +65,11 @@ protected function addColumn(string $name): bool {
}

//TODO: Move the database auto-updates to DatabaseDAO
/** @param array<string> $errorInfo */
/** @param array<string|int> $errorInfo */
protected function autoUpdateDb(array $errorInfo): bool {
if (isset($errorInfo[0])) {
if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_FIELD_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_COLUMN) {
$errorLines = explode("\n", $errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise
$errorLines = explode("\n", (string)$errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise
foreach (['attributes'] as $column) {
if (stripos($errorLines[0], $column) !== false) {
return $this->addColumn($column);
Expand All @@ -78,8 +78,9 @@ protected function autoUpdateDb(array $errorInfo): bool {
}
}
if (isset($errorInfo[1])) {
// May be a string or an int
if ($errorInfo[1] == FreshRSS_DatabaseDAO::ER_DATA_TOO_LONG) {
if (stripos($errorInfo[2], 'content_bin') !== false) {
if (stripos((string)$errorInfo[2], 'content_bin') !== false) {
return $this->updateToMediumBlob(); //v1.15.0
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/EntryDAOPGSQL.php
Expand Up @@ -18,11 +18,11 @@ public static function sqlIgnoreConflict(string $sql): string {
return rtrim($sql, ' ;') . ' ON CONFLICT DO NOTHING';
}

/** @param array<string> $errorInfo */
/** @param array<string|int> $errorInfo */
protected function autoUpdateDb(array $errorInfo): bool {
if (isset($errorInfo[0])) {
if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_FIELD_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_COLUMN) {
$errorLines = explode("\n", $errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise
$errorLines = explode("\n", (string)$errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise
foreach (['attributes'] as $column) {
if (stripos($errorLines[0], $column) !== false) {
return $this->addColumn($column);
Expand Down
2 changes: 1 addition & 1 deletion app/Models/EntryDAOSQLite.php
Expand Up @@ -22,7 +22,7 @@ public static function sqlIgnoreConflict(string $sql): string {
return str_replace('INSERT INTO ', 'INSERT OR IGNORE INTO ', $sql);
}

/** @param array<string> $errorInfo */
/** @param array<string|int> $errorInfo */
protected function autoUpdateDb(array $errorInfo): bool {
if ($tableInfo = $this->pdo->query("PRAGMA table_info('entry')")) {
$columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1) ?: [];
Expand Down
4 changes: 2 additions & 2 deletions app/Models/FeedDAO.php
Expand Up @@ -17,11 +17,11 @@ protected function addColumn(string $name): bool {
return false;
}

/** @param array<string> $errorInfo */
/** @param array<int|string> $errorInfo */
protected function autoUpdateDb(array $errorInfo): bool {
if (isset($errorInfo[0])) {
if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_FIELD_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_COLUMN) {
$errorLines = explode("\n", $errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise
$errorLines = explode("\n", (string)$errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise
foreach (['kind'] as $column) {
if (stripos($errorLines[0], $column) !== false) {
return $this->addColumn($column);
Expand Down
2 changes: 1 addition & 1 deletion app/Models/FeedDAOSQLite.php
Expand Up @@ -2,7 +2,7 @@

class FreshRSS_FeedDAOSQLite extends FreshRSS_FeedDAO {

/** @param array<string> $errorInfo */
/** @param array<int|string> $errorInfo */
protected function autoUpdateDb(array $errorInfo): bool {
if ($tableInfo = $this->pdo->query("PRAGMA table_info('feed')")) {
$columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1);
Expand Down

0 comments on commit 8534555

Please sign in to comment.