aboutsummaryrefslogtreecommitdiff
path: root/app/Models/DatabaseDAO.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models/DatabaseDAO.php')
-rw-r--r--app/Models/DatabaseDAO.php57
1 files changed, 17 insertions, 40 deletions
diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php
index c46c91525..5a58ea2ad 100644
--- a/app/Models/DatabaseDAO.php
+++ b/app/Models/DatabaseDAO.php
@@ -25,10 +25,14 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
$db = FreshRSS_Context::systemConf()->db;
try {
- $sql = sprintf($GLOBALS['SQL_CREATE_DB'], empty($db['base']) ? '' : $db['base']);
+ $sql = $GLOBALS['SQL_CREATE_DB'];
+ if (!is_string($sql)) {
+ throw new Exception('SQL_CREATE_DB is not a string!');
+ }
+ $sql = sprintf($sql, empty($db['base']) ? '' : $db['base']);
return $this->pdo->exec($sql) === false ? 'Error during CREATE DATABASE' : '';
} catch (Exception $e) {
- syslog(LOG_DEBUG, __method__ . ' notice: ' . $e->getMessage());
+ syslog(LOG_DEBUG, __METHOD__ . ' notice: ' . $e->getMessage());
return $e->getMessage();
}
}
@@ -43,7 +47,7 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
return $res == false ? 'Error during SQL connection fetch test!' : '';
} catch (Exception $e) {
- syslog(LOG_DEBUG, __method__ . ' warning: ' . $e->getMessage());
+ syslog(LOG_DEBUG, __METHOD__ . ' warning: ' . $e->getMessage());
return $e->getMessage();
}
}
@@ -81,7 +85,7 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
return count(array_keys($tables, true, true)) === count($tables);
}
- /** @return array<array{name:string,type:string,notnull:bool,default:mixed}> */
+ /** @return list<array{name:string,type:string,notnull:bool,default:mixed}> */
public function getSchema(string $table): array {
$res = $this->fetchAssoc('DESC `_' . $table . '`');
return $res == null ? [] : $this->listDaoToSchema($res);
@@ -164,16 +168,16 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
*/
public function daoToSchema(array $dao): array {
return [
- 'name' => (string)($dao['Field']),
- 'type' => strtolower((string)($dao['Type'])),
- 'notnull' => (bool)$dao['Null'],
- 'default' => $dao['Default'],
+ 'name' => is_string($dao['Field'] ?? null) ? $dao['Field'] : '',
+ 'type' => is_string($dao['Type'] ?? null) ? strtolower($dao['Type']) : '',
+ 'notnull' => empty($dao['Null']),
+ 'default' => is_scalar($dao['Default'] ?? null) ? $dao['Default'] : null,
];
}
/**
* @param array<array<string,string|int|bool|null>> $listDAO
- * @return array<array{name:string,type:string,notnull:bool,default:mixed}>
+ * @return list<array{name:string,type:string,notnull:bool,default:mixed}>
*/
public function listDaoToSchema(array $listDAO): array {
$list = [];
@@ -198,7 +202,7 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
return self::$staticVersion;
}
static $version = null;
- if ($version === null) {
+ if (!is_string($version)) {
$version = $this->fetchValue('SELECT version()') ?? '';
}
return $version;
@@ -256,7 +260,7 @@ SQL;
$catDAO->resetDefaultCategoryName();
include_once(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php');
- if (!empty($GLOBALS['SQL_UPDATE_MINOR'])) {
+ if (!empty($GLOBALS['SQL_UPDATE_MINOR']) && is_string($GLOBALS['SQL_UPDATE_MINOR'])) {
$sql = $GLOBALS['SQL_UPDATE_MINOR'];
$isMariaDB = false;
@@ -272,7 +276,7 @@ SQL;
if ($this->pdo->exec($sql) === false) {
$info = $this->pdo->errorInfo();
if ($this->pdo->dbType() === 'mysql' &&
- !$isMariaDB && !empty($info[2]) && (stripos($info[2], "Can't DROP ") !== false)) {
+ !$isMariaDB && is_string($info[2] ?? null) && (stripos($info[2], "Can't DROP ") !== false)) {
// Too bad for MySQL, but ignore error
return;
}
@@ -444,7 +448,7 @@ SQL;
foreach ($tagFrom->selectEntryTag() as $entryTag) {
if (!empty($idMaps['t' . $entryTag['id_tag']])) {
$entryTag['id_tag'] = $idMaps['t' . $entryTag['id_tag']];
- if (!$tagTo->tagEntry($entryTag['id_tag'], $entryTag['id_entry'])) {
+ if (!$tagTo->tagEntry($entryTag['id_tag'], (string)$entryTag['id_entry'])) {
$error = 'Error during SQLite copy of entry-tags!';
return self::stdError($error);
}
@@ -454,31 +458,4 @@ SQL;
return true;
}
-
- /**
- * Ensure that some PDO columns are `int` and not `string`.
- * Compatibility with PHP 7.
- * @param array<string|int|null> $table
- * @param array<string> $columns
- */
- public static function pdoInt(array &$table, array $columns): void {
- foreach ($columns as $column) {
- if (isset($table[$column]) && is_string($table[$column])) {
- $table[$column] = (int)$table[$column];
- }
- }
- }
-
- /**
- * Ensure that some PDO columns are `string` and not `bigint`.
- * @param array<string|int|null> $table
- * @param array<string> $columns
- */
- public static function pdoString(array &$table, array $columns): void {
- foreach ($columns as $column) {
- if (isset($table[$column])) {
- $table[$column] = (string)$table[$column];
- }
- }
- }
}