|
|
@ -16,17 +16,15 @@ class Database |
|
|
|
$this->_database = new \PDO( |
|
|
|
$this->_database = new \PDO( |
|
|
|
sprintf( |
|
|
|
sprintf( |
|
|
|
'sqlite:%s', |
|
|
|
'sqlite:%s', |
|
|
|
realpath( |
|
|
|
str_starts_with( |
|
|
|
str_starts_with( |
|
|
|
$database, |
|
|
|
$database, |
|
|
|
DIRECTORY_SEPARATOR |
|
|
|
DIRECTORY_SEPARATOR |
|
|
|
) ? $database |
|
|
|
) ? $database |
|
|
|
: __DIR__ . |
|
|
|
: __DIR__ . |
|
|
|
DIRECTORY_SEPARATOR . '..'. |
|
|
|
DIRECTORY_SEPARATOR . '..'. |
|
|
|
DIRECTORY_SEPARATOR . '..'. |
|
|
|
DIRECTORY_SEPARATOR . '..'. |
|
|
|
DIRECTORY_SEPARATOR . 'config'. |
|
|
|
DIRECTORY_SEPARATOR . 'config'. |
|
|
|
DIRECTORY_SEPARATOR . $database |
|
|
|
DIRECTORY_SEPARATOR . $database |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
$username, |
|
|
|
$username, |
|
|
|
$password |
|
|
|
$password |
|
|
@ -47,6 +45,7 @@ class Database |
|
|
|
( |
|
|
|
( |
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
|
|
|
"time" INTEGER NOT NULL, |
|
|
|
"time" INTEGER NOT NULL, |
|
|
|
|
|
|
|
"alias" VARCHAR NOT NULL, |
|
|
|
"source" TEXT NOT NULL, |
|
|
|
"source" TEXT NOT NULL, |
|
|
|
"link" TEXT, |
|
|
|
"link" TEXT, |
|
|
|
"title" TEXT, |
|
|
|
"title" TEXT, |
|
|
@ -102,6 +101,24 @@ class Database |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getChannelByAlias( |
|
|
|
|
|
|
|
string $alias |
|
|
|
|
|
|
|
): ?object |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$query = $this->_database->prepare( |
|
|
|
|
|
|
|
'SELECT * FROM `channel` WHERE `alias` LIKE ? LIMIT 1' |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$query->execute([$alias]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($result = $query->fetch()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return $result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getChannelIdBySource( |
|
|
|
public function getChannelIdBySource( |
|
|
|
string $source |
|
|
|
string $source |
|
|
|
): ?int |
|
|
|
): ?int |
|
|
@ -125,6 +142,7 @@ class Database |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function addChannel( |
|
|
|
public function addChannel( |
|
|
|
|
|
|
|
string $alias, |
|
|
|
string $source, |
|
|
|
string $source, |
|
|
|
?string $link, |
|
|
|
?string $link, |
|
|
|
?string $title, |
|
|
|
?string $title, |
|
|
@ -133,12 +151,13 @@ class Database |
|
|
|
): ?int |
|
|
|
): ?int |
|
|
|
{ |
|
|
|
{ |
|
|
|
$query = $this->_database->prepare( |
|
|
|
$query = $this->_database->prepare( |
|
|
|
'INSERT INTO `channel` (`source`, `link`, `title`, `description`, `time`) |
|
|
|
'INSERT INTO `channel` (`alias`, `source`, `link`, `title`, `description`, `time`) |
|
|
|
VALUES (:source, :link, :title, :description, :time)' |
|
|
|
VALUES (:alias, :source, :link, :title, :description, :time)' |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$query->execute( |
|
|
|
$query->execute( |
|
|
|
[ |
|
|
|
[ |
|
|
|
|
|
|
|
':alias' => $alias, |
|
|
|
':source' => $source, |
|
|
|
':source' => $source, |
|
|
|
':link' => $link, |
|
|
|
':link' => $link, |
|
|
|
':title' => $title, |
|
|
|
':title' => $title, |
|
|
|