Page: Add 'title' column, storing title of last revision

Bu işleme şunda yer alıyor:
Albert S. 2022-03-27 09:23:35 +02:00
ebeveyn ac793c6d39
işleme f7cf06cdd5
5 değiştirilmiş dosya ile 17 ekleme ve 8 silme

Dosyayı Görüntüle

@ -58,9 +58,9 @@ std::optional<Page> PageDaoSqlite::find(unsigned int id)
result.pageid = id;
try
{
auto ps = *db << "SELECT name, lastrevision, visible FROM page WHERE id = ?";
auto ps = *db << "SELECT name, title, lastrevision, visible FROM page WHERE id = ?";
ps << id >> std::tie(result.name, result.current_revision, result.listed);
ps << id >> std::tie(result.name, result.title, result.current_revision, result.listed);
}
catch(const sqlite::errors::no_rows &e)
{
@ -97,9 +97,10 @@ void PageDaoSqlite::save(const Page &page)
{
try
{
*db << "INSERT OR REPLACE INTO page (id, name, lastrevision, visible) VALUES((SELECT id FROM page WHERE name = "
"? OR id = ?), ?, ?, ?)"
<< page.name << page.pageid << page.name << page.current_revision << page.listed;
*db << "INSERT OR REPLACE INTO page (id, name, title, lastrevision, visible) VALUES((SELECT id FROM page WHERE "
"name = "
"? OR id = ?), ?, ?, ?, ?)"
<< page.name << page.pageid << page.name << page.title << page.current_revision << page.listed;
}
catch(sqlite::sqlite_exception &e)
{
@ -183,7 +184,8 @@ std::vector<SearchResult> PageDaoSqlite::search(std::string name, QueryOption op
auto query =
*db << "SELECT page.name FROM search INNER JOIN page ON search.page = page.id WHERE search MATCH ? "
<< ftsEscape(name);
query >> [&](std::string pagename) {
query >> [&](std::string pagename)
{
SearchResult sresult;
sresult.pagename = pagename;
sresult.query = name;

Dosyayı Görüntüle

@ -34,7 +34,7 @@ std::string DynamicContentPostList::render()
Varreplacer replacer{"{"};
replacer.addKeyValue("url", link);
replacer.addKeyValue("date", date);
replacer.addKeyValue("page", pair.first);
replacer.addKeyValue("title", pageDao->find(pair.first)->title);
stream << replacer.parse(postLink);
}

Dosyayı Görüntüle

@ -66,6 +66,7 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename,
this->database->beginTransaction();
std::string visiblecmd = parser.extractCommand("visible", newContent);
std::string rename = parser.extractCommand("rename", newContent);
std::string customtitle = parser.extractCommand("pagetitle", newContent);
Page page;
std::optional<Page> currentPage = pageDao.find(pagename);
if(currentPage)
@ -83,6 +84,11 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename,
page.current_revision = current_revision;
page.listed = !(visiblecmd == "0");
page.name = pagename;
page.title = customtitle;
if(page.title.empty())
{
page.title = page.name;
}
pageDao.save(page);
Revision newRevision;

1
page.h
Dosyayı Görüntüle

@ -7,6 +7,7 @@ class Page
public:
Page();
std::string name;
std::string title;
bool listed;
unsigned int current_revision;
unsigned int pageid;

Dosyayı Görüntüle

@ -1,4 +1,4 @@
CREATE TABLE page(id INTEGER PRIMARY KEY, name varchar(256), lastrevision integer, visible integer DEFAULT 1);
CREATE TABLE page(id INTEGER PRIMARY KEY, name varchar(256), title varchar(1024), lastrevision integer, visible integer DEFAULT 1);
CREATE TABLE user(id INTEGER PRIMARY KEY,username varchar(64),
password blob, salt blob, permissions integer, enabled integer DEFAULT 1);
CREATE TABLE session(id INTEGER PRIMARY KEY, csrf_token varchar(32),