aboutsummaryrefslogtreecommitdiff
path: root/app/Models/CategoryDAOSQLite.php
blob: 575656e67b9e76e497c85852dd7e2a20dae93e4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
declare(strict_types=1);

class FreshRSS_CategoryDAOSQLite extends FreshRSS_CategoryDAO {

	#[\Override]
	public function sqlResetSequence(): bool {
		return true;	// Nothing to do for SQLite
	}

	/** @param array{0:string,1:int,2:string} $errorInfo */
	#[\Override]
	protected function autoUpdateDb(array $errorInfo): bool {
		if (isset($errorInfo[0])) {
			$errorLines = explode("\n", $errorInfo[2], 2);	// The relevant column name is on the first line, other lines are noise
			if (str_contains($errorLines[0], 'f.')) {	// Coming from a feed sub-query
				$feedDao = FreshRSS_Factory::createFeedDao();
				if ($feedDao->autoUpdateDb($errorInfo)) {
					return true;
				}
			}
		}
		if (($tableInfo = $this->pdo->query("PRAGMA table_info('category')")) !== false) {
			$columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1);
			foreach (['kind', 'lastUpdate', 'error', 'attributes'] as $column) {
				if (!in_array($column, $columns, true)) {
					return $this->addColumn($column);
				}
			}
		}
		return false;
	}
}