added: column 'guest_name' to 'item' table
used when user_id is -1 added: mount parameters: thread_with_info, thread_with_header added: function rm can remove threads git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@506 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -12,7 +12,8 @@ db_itemcolumns.o: db.h item.h user.h group.h thread.h error.h log.h
|
||||
db_itemcolumns.o: dircontainer.h ugcontainer.h
|
||||
dircontainer.o: dircontainer.h item.h log.h
|
||||
dirs.o: dirs.h item.h dircontainer.h error.h log.h db.h user.h group.h
|
||||
dirs.o: thread.h ugcontainer.h
|
||||
dirs.o: thread.h ugcontainer.h data.h users.h groups.h functions.h function.h
|
||||
dirs.o: lastcontainer.h mounts.h mount.h
|
||||
done.o: done.h
|
||||
error.o: error.h log.h
|
||||
function.o: function.h item.h
|
||||
|
||||
97
core/db.cpp
97
core/db.cpp
@@ -420,7 +420,7 @@ Error Db::AddItemIntoItem(Item & item)
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, parent_id, content_id, default_item, subject, url) values (";
|
||||
query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, parent_id, content_id, default_item, subject, guest_name, url) values (";
|
||||
query << '\'' << item.user_id << "', ";
|
||||
query << '\'' << item.group_id << "', ";
|
||||
query << '\'' << item.privileges << "', ";
|
||||
@@ -431,6 +431,7 @@ Error Db::AddItemIntoItem(Item & item)
|
||||
query << '\'' << item.content_id << "', ";
|
||||
query << '\'' << item.default_item << "', ";
|
||||
query << '\'' << Escape(item.subject) << "', ";
|
||||
query << '\'' << Escape(item.guest_name) << "', ";
|
||||
|
||||
url_without_id = AddItemCreateUrlSubject(item);
|
||||
|
||||
@@ -522,7 +523,7 @@ Error Db::EditItemInItem(Item & item, bool with_url)
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id, subject";
|
||||
query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id, subject, guest_name";
|
||||
|
||||
if( with_url )
|
||||
query << ", url";
|
||||
@@ -536,7 +537,8 @@ Error Db::EditItemInItem(Item & item, bool with_url)
|
||||
query << '\'' << static_cast<int>(item.type) << "', ";
|
||||
query << '\'' << item.default_item << "', ";
|
||||
query << '\'' << item.parent_id << "', ";
|
||||
query << '\'' << Escape(item.subject) << "' ";
|
||||
query << '\'' << Escape(item.subject) << "', ";
|
||||
query << '\'' << Escape(item.guest_name) << "' ";
|
||||
|
||||
if( with_url )
|
||||
{
|
||||
@@ -749,7 +751,7 @@ return result;
|
||||
PGresult * Db::GetItemsQuery(long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc)
|
||||
{
|
||||
std::ostringstream query;
|
||||
query << "select item.id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item";
|
||||
query << "select item.id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item, guest_name";
|
||||
|
||||
if( type != Item::dir )
|
||||
{
|
||||
@@ -819,7 +821,7 @@ void Db::GetItems(std::vector<Item> & item_table, long parent_id, Item::Type typ
|
||||
}
|
||||
|
||||
|
||||
|
||||
// !! ta chyba nie uzywana juz?
|
||||
void Db::GetItem(std::vector<Item> & item_table, long id)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
@@ -957,7 +959,7 @@ bool result = false;
|
||||
AssertConnection();
|
||||
|
||||
std::ostringstream query;
|
||||
query << "select user_id, group_id, privileges, subject, content from core.item left join core.content on item.content_id = content.id where item.id='" << id << "';"; // !! tymczasowo odczytujemy z content i subject
|
||||
query << "select user_id, group_id, privileges, subject, content, guest_name from core.item left join core.content on item.content_id = content.id where item.id='" << id << "';"; // !! tymczasowo odczytujemy z content i subject
|
||||
|
||||
r = AssertQuery( query.str() );
|
||||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||
@@ -993,10 +995,11 @@ Error Db::EditPrivById(Item & item, long id)
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "update core.item set (user_id, group_id, privileges) = (";
|
||||
query << "update core.item set (user_id, group_id, privileges, guest_name) = (";
|
||||
query << '\'' << item.user_id << "', ";
|
||||
query << '\'' << item.group_id << "', ";
|
||||
query << '\'' << item.privileges << "' ";
|
||||
query << '\'' << item.privileges << "', ";
|
||||
query << '\'' << Escape(item.guest_name) << "' ";
|
||||
|
||||
query << ") where id='" << id << "';";
|
||||
|
||||
@@ -1449,7 +1452,7 @@ Error Db::GetThreads(long parent_id, std::vector<Thread> & thread_tab)
|
||||
AssertConnection();
|
||||
|
||||
std::ostringstream query;
|
||||
query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id "
|
||||
query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id, item.guest_name "
|
||||
"from core.thread left join core.item on thread.last_item = item.id "
|
||||
"where thread.parent_id = '" << parent_id << "' order by date_modification asc;";
|
||||
|
||||
@@ -1467,6 +1470,9 @@ Error Db::GetThreads(long parent_id, std::vector<Thread> & thread_tab)
|
||||
int clast_item = AssertColumn(r, "last_item");
|
||||
int cdate_modification = PQfnumber(r, "date_modification");
|
||||
int cuser_id = PQfnumber(r, "user_id");
|
||||
int cguest_name = PQfnumber(r, "guest_name");
|
||||
|
||||
|
||||
|
||||
for(int i=0 ; i<rows ; ++i)
|
||||
{
|
||||
@@ -1478,7 +1484,8 @@ Error Db::GetThreads(long parent_id, std::vector<Thread> & thread_tab)
|
||||
thread.last_item.id = atol( AssertValue(r, i, clast_item) );
|
||||
thread.last_item.date_modification = ConvertTime( Db::AssertValue(r, i, cdate_modification) );
|
||||
thread.last_item.user_id = atol( Db::AssertValue(r, i, cuser_id) );
|
||||
|
||||
thread.last_item.guest_name = Db::AssertValue(r, i, cguest_name);
|
||||
|
||||
thread_tab.push_back(thread);
|
||||
}
|
||||
}
|
||||
@@ -1554,3 +1561,73 @@ Error Db::EditThreadAddItem(long dir_id, long item_id)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Error Db::EditThreadRemoveItem(long dir_id)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
Error status = Error::ok;
|
||||
|
||||
try
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query, query2;
|
||||
|
||||
long last_item_id = -1;
|
||||
|
||||
query << "select id from core.item where parent_id='" << dir_id << "' order by date_creation desc limit 1;";
|
||||
r = AssertQuery( query.str() );
|
||||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||
|
||||
if( PQntuples(r) == 1 )
|
||||
last_item_id = atol( AssertValue(r, 0, 0) );
|
||||
|
||||
ClearResult(r);
|
||||
|
||||
query2 << "update core.thread set (items, last_item) = (items-1,'" << last_item_id
|
||||
<< "') where dir_id='" << dir_id << "';";
|
||||
|
||||
r = AssertQuery(query2.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
status = e;
|
||||
}
|
||||
|
||||
ClearResult(r);
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
Error Db::RemoveThread(long dir_id)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
Error status = Error::ok;
|
||||
|
||||
try
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "delete from core.thread where dir_id='" << dir_id << "';";
|
||||
|
||||
const char * crows = PQcmdTuples(r);
|
||||
if( crows )
|
||||
log << log2 << "Db: deleted " << atol(crows) << " rows from core.thread" << logend;
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
status = e;
|
||||
}
|
||||
|
||||
ClearResult(r);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,8 @@ public:
|
||||
Error GetThreadByDirId(long dir_id, Thread & thread);
|
||||
Error GetThreads(long parent_id, std::vector<Thread> & thread_tab);
|
||||
Error EditThreadAddItem(long dir_id, long item_id);
|
||||
Error EditThreadRemoveItem(long dir_id);
|
||||
Error RemoveThread(long dir_id);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -125,7 +127,7 @@ protected:
|
||||
|
||||
struct ItemColumns
|
||||
{
|
||||
int id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item, subject, content, content_type;
|
||||
int id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item, subject, content, content_type, guest_name;
|
||||
|
||||
|
||||
void SetColumns(PGresult * r);
|
||||
|
||||
@@ -28,6 +28,7 @@ void Db::ItemColumns::SetColumns(PGresult * r)
|
||||
subject = PQfnumber(r, "subject");
|
||||
content = PQfnumber(r, "content");
|
||||
content_type = PQfnumber(r, "content_type");
|
||||
guest_name = PQfnumber(r, "guest_name");
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +49,7 @@ void Db::ItemColumns::SetItem(PGresult * r, long row, Item & item)
|
||||
if( subject != -1 ) item.subject = Db::AssertValue(r, row, subject);
|
||||
if( content != -1 ) item.content = Db::AssertValue(r, row, content);
|
||||
if( content_type != -1 ) item.content_type = atoi( Db::AssertValue(r, row, content_type) );
|
||||
if( guest_name != -1 ) item.guest_name = Db::AssertValue(r, row, guest_name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "error.h"
|
||||
#include "log.h"
|
||||
#include "db.h"
|
||||
|
||||
#include "data.h"
|
||||
|
||||
|
||||
void Dirs::Clear()
|
||||
@@ -404,6 +404,9 @@ void Dirs::DeleteDir(long id)
|
||||
|
||||
if( db.DelDirById(id) == Error::ok )
|
||||
dir_table.DelById(id);
|
||||
|
||||
if( data.mounts.CurrentMountType() == Mount::thread )
|
||||
db.RemoveThread(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ long user_id;
|
||||
long group_id;
|
||||
int privileges;
|
||||
|
||||
// used as a user name when user_id is equal -1
|
||||
std::string guest_name;
|
||||
|
||||
tm date_creation;
|
||||
tm date_modification;
|
||||
|
||||
@@ -77,6 +80,8 @@ void Clear()
|
||||
group_id = -1;
|
||||
privileges = 0;
|
||||
|
||||
guest_name.clear();
|
||||
|
||||
subject.clear();
|
||||
content.clear();
|
||||
url.clear();
|
||||
|
||||
@@ -59,6 +59,12 @@ bool Mount::ParseStrParam(const std::string & param, const std::vector<int> & ar
|
||||
if( param == "withinfo" )
|
||||
p = withinfo;
|
||||
else
|
||||
if( param == "thread_with_header" )
|
||||
p = thread_with_header;
|
||||
else
|
||||
if( param == "thread_with_info" )
|
||||
p = thread_with_info;
|
||||
else
|
||||
if( param == "restrictcreatethread" )
|
||||
p = restrictcreatethread;
|
||||
else
|
||||
|
||||
@@ -35,6 +35,8 @@ public:
|
||||
desc,
|
||||
withheader,
|
||||
withinfo,
|
||||
thread_with_header,
|
||||
thread_with_info,
|
||||
restrictcreatethread,
|
||||
only_root_can_remove,
|
||||
can_use_emacs_on,
|
||||
|
||||
@@ -22,7 +22,7 @@ void Mounts::ReadMounts()
|
||||
std::string temp =
|
||||
"cms / withheader, withinfo \n"
|
||||
"thread /news desc, withheader, withinfo, restrictcreatethread(-1) \n"
|
||||
"thread /forum asc, withinfo, restrictcreatethread(3), only_root_can_remove, can_use_emacs_on(4), can_use_mkdir_on(3)";
|
||||
"thread /forum asc, withheader, withinfo, thread_with_info, restrictcreatethread(3), only_root_can_remove, can_use_emacs_on(4), can_use_mkdir_on(3)";
|
||||
|
||||
Error err = mp.Parse(temp, mount_table);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user