fixed: find_ticket_value (in plugins/ticket/templates.cpp)

should find the first item (can be more than one item with the same 'param')

fixed: added sorting tickets params in ReadTicketParams() (in plugins/ticket/ticketinfo.cpp)

fixed: plugin should have its own 'PluginInfo info' struct
a plugin's function can call another plugin's functions

added: removing tickets files/images

added: removing threads

changed: rm function will call WINIX_FILE_REMOVED now when deleting directories





git-svn-id: svn://ttmath.org/publicrep/winix/trunk@710 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2011-01-23 23:23:24 +00:00
parent 915cabdf97
commit 3071df227a
47 changed files with 418 additions and 222 deletions

View File

@ -55,9 +55,9 @@ public:
std::vector<Item*> & out_dir_tab, std::wstring & out_item); std::vector<Item*> & out_dir_tab, std::wstring & out_item);
static void SplitPath(const std::wstring & path, std::wstring & dir, std::wstring & file); static void SplitPath(const std::wstring & path, std::wstring & dir, std::wstring & file);
DirContainer::ParentIterator FindFirstChild(long parent_id); // !! zmienic w koncu nazwe na FindFirstChild DirContainer::ParentIterator FindFirstChild(long parent_id);
DirContainer::ParentIterator NextChild(DirContainer::ParentIterator i); DirContainer::ParentIterator NextChild(DirContainer::ParentIterator i);
DirContainer::ParentIterator ParentEnd(); DirContainer::ParentIterator ParentEnd(); // !! pozostalo do zamiany na child
// these methods return null if there is no such a dir // these methods return null if there is no such a dir

View File

@ -184,6 +184,7 @@ void Plugin::LoadPlugin(const char * filename)
Fun1 fun_init; Fun1 fun_init;
void * plugin_handle; void * plugin_handle;
int old_current_plugin; int old_current_plugin;
PluginInfo info;
if( !SetPointers(info) ) if( !SetPointers(info) )
return; return;
@ -244,7 +245,7 @@ bool Plugin::HasPlugin(const std::wstring & name)
void Plugin::Call(int message, Slots::iterator & slot) void Plugin::Call(int message, Slots::iterator & slot, PluginInfo & info)
{ {
if( !SetPointers(info) ) if( !SetPointers(info) )
return; return;
@ -295,6 +296,7 @@ void Plugin::Call(int message, void * p1_, void * p2_, long l1_, long l2_)
int ret_false_loc = 0; int ret_false_loc = 0;
int ret_true_loc = 0; int ret_true_loc = 0;
int old_current_plugin = current_plugin; int old_current_plugin = current_plugin;
PluginInfo info;
Slots::iterator i = slots.lower_bound(message); Slots::iterator i = slots.lower_bound(message);
@ -306,7 +308,7 @@ int old_current_plugin = current_plugin;
info.l1 = l1_; info.l1 = l1_;
info.l2 = l2_; info.l2 = l2_;
Call(message, i); Call(message, i, info);
if( info.res ) if( info.res )
++ret_true_loc; ++ret_true_loc;

View File

@ -202,12 +202,10 @@ private:
typedef std::multimap<int, Slot> Slots; typedef std::multimap<int, Slot> Slots;
Slots slots; Slots slots;
PluginInfo info;
std::string afilename; std::string afilename;
void * LoadInitFun(const char * filename, Fun1 & fun_init); void * LoadInitFun(const char * filename, Fun1 & fun_init);
void Call(int message, Slots::iterator & slot); void Call(int message, Slots::iterator & slot, PluginInfo & info);
bool SetPointers(PluginInfo & info); bool SetPointers(PluginInfo & info);
}; };

View File

@ -56,8 +56,9 @@
// the is not any session available (cur->session is null) // the is not any session available (cur->session is null)
#define WINIX_CLOSE 3004 #define WINIX_CLOSE 3004
// item was removed (rm function) // a file or symlink was removed (rm function)
// PluginInfo::l1 is the file (item) id // PluginInfo::l1 is the file (item) id
// !! moze zmienic nazwe i dodac symlink w nazwie?
#define WINIX_FILE_REMOVED 3005 #define WINIX_FILE_REMOVED 3005
// directory was removed (rm function) // directory was removed (rm function)

View File

@ -13,7 +13,7 @@
#define WINIX_VER_MAJOR 0 #define WINIX_VER_MAJOR 0
#define WINIX_VER_MINOR 4 #define WINIX_VER_MINOR 4
#define WINIX_VER_REVISION 5 #define WINIX_VER_REVISION 6
#endif #endif

View File

@ -433,9 +433,8 @@ long Db::GetContentId(long item_id)
if( Rows(r) == 1 && Cols(r) == 1 ) if( Rows(r) == 1 && Cols(r) == 1 )
result = AssertValueLong(r, 0, 0); result = AssertValueLong(r, 0, 0);
} }
catch(const Error & e) catch(const Error)
{ {
result = e;
} }
ClearResult(r); ClearResult(r);
@ -1204,16 +1203,18 @@ return EndTrans(result);
Error Db::DelItemDelItem(const Item & item) Error Db::DelItemDelItem(long item_id, int type)
{ {
PGresult * r = 0; PGresult * r = 0;
Error result = WINIX_ERR_OK; Error result = WINIX_ERR_OK;
try try
{ {
query.Clear(); query.Clear();
query << R("delete from core.item where id=") query << R("delete from core.item where id=")
<< item.id << item_id
<< R(" and type=")
<< type
<< R(";"); << R(";");
r = AssertQuery(query); r = AssertQuery(query);
@ -1234,20 +1235,20 @@ return result;
Error Db::DelItemDelContent(const Item & item) Error Db::DelItemDelContent(long content_id)
{ {
PGresult * r = 0; PGresult * r = 0;
Error result = WINIX_ERR_OK; Error result = WINIX_ERR_OK;
try try
{ {
result = DecrementContentRef(item.content_id); result = DecrementContentRef(content_id);
if( result == WINIX_ERR_OK ) if( result == WINIX_ERR_OK )
{ {
query.Clear(); query.Clear();
query << R("delete from core.content where ref=0 and id=") query << R("delete from core.content where ref=0 and id=")
<< item.content_id << content_id
<< R(";"); << R(";");
r = AssertQuery(query); r = AssertQuery(query);
@ -1278,17 +1279,17 @@ Error result = WINIX_ERR_NO_ITEM;
if( item.type == Item::file ) if( item.type == Item::file )
{ {
BeginTrans(); BeginTrans();
result = DelItemDelContent(item); result = DelItemDelContent(item.content_id);
if( result == WINIX_ERR_OK ) if( result == WINIX_ERR_OK )
result = DelItemDelItem(item); result = DelItemDelItem(item.id, 1);
result = EndTrans(result); result = EndTrans(result);
} }
else else
if( item.type == Item::symlink ) if( item.type == Item::symlink )
{ {
result = DelItemDelItem(item); result = DelItemDelItem(item.id, 2);
} }
else else
if( item.type == Item::dir ) if( item.type == Item::dir )
@ -1302,6 +1303,33 @@ return result;
Error Db::DelFileById(long file_id)
{
Error result = WINIX_ERR_NO_ITEM;
BeginTrans();
long content_id = GetContentId(file_id);
if( content_id != -1 )
{
result = DelItemDelContent(content_id);
if( result == WINIX_ERR_OK )
result = DelItemDelItem(file_id, 1);
}
result = EndTrans(result);
return result;
}
Error Db::DelSymlinkById(long symlink_id)
{
return DelItemDelItem(symlink_id, 2);
}
void Db::GetDirs(DirContainer & dir_tab) void Db::GetDirs(DirContainer & dir_tab)

View File

@ -60,7 +60,10 @@ public:
Error EditParentUrlById(Item & item, long id); Error EditParentUrlById(Item & item, long id);
Error EditFileById(const Item & item, long id); // file_path, file_fs, file_type Error EditFileById(const Item & item, long id); // file_path, file_fs, file_type
Error EditHasThumbById(bool has_thumb, long id); Error EditHasThumbById(bool has_thumb, long id);
Error DelDirById(long id); Error DelDirById(long id);
Error DelFileById(long file_id);
Error DelSymlinkById(long symlink_id);
Error EditSubjectById(Item & item, long id); Error EditSubjectById(Item & item, long id);
@ -106,8 +109,8 @@ protected:
PGresult * GetItemsQuery(const DbItemQuery & iq, bool skip_other_sel = false); PGresult * GetItemsQuery(const DbItemQuery & iq, bool skip_other_sel = false);
Error DelItemDelItem(const Item & item); Error DelItemDelItem(long item_id, int type);
Error DelItemDelContent(const Item & item); Error DelItemDelContent(long content_id);
Error IncrementContentRef(long content_id); Error IncrementContentRef(long content_id);
Error DecrementContentRef(long content_id); Error DecrementContentRef(long content_id);

View File

@ -422,7 +422,7 @@ Error DbBase::EndTrans(Error err)
} }
else else
{ {
// we returned the old err code // we return the old err code
RollbackTrans(); RollbackTrans();
} }

View File

@ -76,20 +76,20 @@ return true;
void Rm::Prepare() void Rm::Prepare()
{ {
// selecting files and symlinks (without directories)
content_dir_iq.SetAll(false, false); content_dir_iq.SetAll(false, false);
content_dir_iq.sel_parent_id = true; content_dir_iq.sel_parent_id = true;
content_dir_iq.sel_type = true; content_dir_iq.sel_type = true;
content_dir_iq.sel_url = true; content_dir_iq.sel_url = true;
content_dir_iq.sel_file = true; content_dir_iq.sel_file = true;
content_dir_iq.WhereType(Item::dir, false);
static_iq.SetAll(false, false); // selecting files, symlinks and directories
static_iq.sel_parent_id = true; content_dir_iq2.SetAll(false, false);
static_iq.sel_type = true; content_dir_iq2.sel_parent_id = true;
static_iq.sel_url = true; content_dir_iq2.sel_type = true;
static_iq.sel_file = true; content_dir_iq2.sel_url = true;
content_dir_iq2.sel_file = true;
static_iq.WhereType(Item::file);
static_iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE, false);
} }
@ -147,16 +147,31 @@ void Rm::RemoveFileOrSymlink(Item & item)
TemplatesFunctions::pattern_cacher.DeletePattern(item); TemplatesFunctions::pattern_cacher.DeletePattern(item);
plugin.Call(WINIX_FILE_REMOVED, item.id); plugin.Call(WINIX_FILE_REMOVED, item.id);
// !! nie potrzebne
//db->EditThreadRemoveItem(item.parent_id);
if( item.file_type != WINIX_ITEM_FILETYPE_NONE ) if( item.file_type != WINIX_ITEM_FILETYPE_NONE )
RemoveStaticFile(item); RemoveStaticFile(item);
} }
else }
// for other uses (plugins etc)
void Rm::RemoveItemById(long item_id)
{
// selecting files, symlinks and directories
rm_by_id_iq.SetAll(false, false);
rm_by_id_iq.sel_parent_id = true;
rm_by_id_iq.sel_type = true;
rm_by_id_iq.sel_url = true;
rm_by_id_iq.sel_file = true;
rm_by_id_iq.WhereId(item_id);
if( db->GetItem(rm_by_id_item, rm_by_id_iq) == WINIX_ERR_OK )
{ {
// cur->request->status = WINIX_ERR_NO_ITEM; if( rm_by_id_item.type == Item::dir )
RemoveDir(rm_by_id_item);
else
RemoveFileOrSymlink(rm_by_id_item);
} }
} }
@ -175,19 +190,15 @@ void Rm::RemoveDirTree(long dir_id)
plugin.Call(WINIX_DIR_PREPARE_TO_REMOVE, dir_id); plugin.Call(WINIX_DIR_PREPARE_TO_REMOVE, dir_id);
static_iq.WhereParentId(dir_id); content_dir_iq.WhereParentId(dir_id);
db->GetItems(static_item_tab, static_iq); db->GetItems(content_item_tab, content_dir_iq);
for(size_t i=0 ; i<static_item_tab.size() ; ++i) for(size_t i=0 ; i<content_item_tab.size() ; ++i)
RemoveStaticFile(static_item_tab[i]); RemoveFileOrSymlink(content_item_tab[i]);
if( db->DelDirById(dir_id) == WINIX_ERR_OK ) if( db->DelDirById(dir_id) == WINIX_ERR_OK )
{ {
system->dirs.DelDir(dir_id); system->dirs.DelDir(dir_id);
// !! nie potrzebne
//db->RemoveThread(dir_id);
plugin.Call(WINIX_DIR_REMOVED, dir_id); plugin.Call(WINIX_DIR_REMOVED, dir_id);
} }
} }
@ -215,6 +226,21 @@ void Rm::RemoveFile()
void Rm::RemoveDirContent(const Item & dir)
{
content_dir_iq2.WhereParentId(dir.id);
db->GetItems(content_item_tab2, content_dir_iq2);
for(size_t i=0 ; i<content_item_tab2.size() ; ++i)
{
if( content_item_tab2[i].type == Item::dir )
RemoveDir(content_item_tab2[i]);
else
RemoveFileOrSymlink(content_item_tab2[i]);
}
}
void Rm::RemoveDirContent() void Rm::RemoveDirContent()
{ {
if( !cur->request->IsParam(L"r") ) if( !cur->request->IsParam(L"r") )
@ -223,16 +249,7 @@ void Rm::RemoveDirContent()
return; return;
} }
content_dir_iq.WhereParentId(cur->request->dir_tab.back()->id); RemoveDirContent(*cur->request->dir_tab.back());
db->GetItems(item_tab, content_dir_iq);
for(size_t i=0 ; i<item_tab.size() ; ++i)
{
if( item_tab[i].type == Item::dir )
RemoveDir(item_tab[i]);
else
RemoveFileOrSymlink(item_tab[i]);
}
if( cur->request->status == WINIX_ERR_OK ) if( cur->request->status == WINIX_ERR_OK )
system->RedirectToLastDir(); system->RedirectToLastDir();
@ -261,8 +278,8 @@ void Rm::RemoveDir()
void Rm::Clear() void Rm::Clear()
{ {
static_item_tab.clear(); content_item_tab.clear();
item_tab.clear(); content_item_tab2.clear();
} }

View File

@ -26,25 +26,34 @@ public:
bool HasAccess(); bool HasAccess();
void MakePost(); void MakePost();
void RemoveDir(const Item & dir);
void RemoveDirContent(const Item & dir);
void RemoveFileOrSymlink(Item & item);
// removing either a directory or a symlink or a file
void RemoveItemById(long item_id);
private: private:
// for static files // for deleting content in a directory (files and symlinks)
DbItemQuery static_iq; DbItemQuery content_dir_iq;
std::vector<Item> static_item_tab; std::vector<Item> content_item_tab;
std::wstring path; std::wstring path;
// for directory content // for deleting content in a directory (files, symlinks and directories)
DbItemQuery content_dir_iq; DbItemQuery content_dir_iq2;
std::vector<Item> item_tab; std::vector<Item> content_item_tab2;
// for logging // for logging
std::wstring old_url; std::wstring old_url;
// for removing an item by id
DbItemQuery rm_by_id_iq;
Item rm_by_id_item;
bool HasAccess(const Item & item); bool HasAccess(const Item & item);
void Prepare(); void Prepare();
void Clear(); void Clear();
void RemoveFileOrSymlink(Item & item);
void RemoveDir(const Item & dir);
bool RemoveStaticFile(const std::wstring & path); bool RemoveStaticFile(const std::wstring & path);
void RemoveStaticFile(Item & item); void RemoveStaticFile(Item & item);
void RemoveDirTree(long dir_id); void RemoveDirTree(long dir_id);

View File

@ -9,22 +9,32 @@
[end] [end]
<div class="threadbox"> [if-no thread_mount_arg_is "sort_desc"]
[if item_can_write]<a class="threadedit" href="[item_link]/emacs" rel="nofollow">\[{edit}\]</a>[end] <div class="threadbox">
[if mount_thread_arg_is "subject"]<h2[if mount_thread_arg_is "info"] class="withinfo"[end]>[item_subject]</h2>[end] [if item_can_write]<a class="threadedit" href="[item_link]/emacs" rel="nofollow">\[{edit}\]</a>[end]
[if mount_thread_arg_is "info"][include "item_info.html"][end] [if thread_mount_arg_is "subject"]<h2[if thread_mount_arg_is "info"] class="withinfo"[end]>[item_subject]</h2>[end]
[item_print_content] [if thread_mount_arg_is "info"][include "item_info.html"][end]
</div> [item_print_content]
</div>
[end]
[for thread_sort_tab] [for thread_sort_tab]
<div class="threadbox[if-index even] threadboxcolor[end]"> <div class="threadbox[if-index even] threadboxcolor[end]">
[if thread_sort_tab_can_write]<a class="threadedit" href="[thread_sort_tab_link]/emacs" rel="nofollow">\[{edit}\]</a>[end] [if thread_sort_tab_can_write]<a class="threadedit" href="[thread_sort_tab_link]/emacs" rel="nofollow">\[{edit}\]</a>[end]
[if mount_thread_arg_is "subject"]<h2[if mount_thread_arg_is "info"] class="withinfo"[end]>[thread_sort_tab_subject]</h2>[end] [if thread_mount_arg_is "subject"]<h2[if thread_mount_arg_is "info"] class="withinfo"[end]>[thread_sort_tab_subject]</h2>[end]
[if mount_thread_arg_is "info"][include "thread_sort_tab_info.html"][end] [if thread_mount_arg_is "info"][include "thread_sort_tab_info.html"][end]
[thread_sort_tab_print_content] [thread_sort_tab_print_content]
</div> </div>
[end] [end]
[if thread_mount_arg_is "sort_desc"]
<div class="threadbox">
[if item_can_write]<a class="threadedit" href="[item_link]/emacs" rel="nofollow">\[{edit}\]</a>[end]
[if thread_mount_arg_is "subject"]<h2[if thread_mount_arg_is "info"] class="withinfo"[end]>[item_subject]</h2>[end]
[if thread_mount_arg_is "info"][include "item_info.html"][end]
[item_print_content]
</div>
[end]

View File

@ -36,21 +36,23 @@
</div> </div>
[if thread_can_reply] [if winix_has_plugin "thread"]
<ul class="itemmenu">
<li><a href="[doc_base_url][dir][item_url]/reply" rel="nofollow">{thread_reply_in_this_thread}</a></li> [if thread_can_reply]
</ul> <ul class="itemmenu">
<li><a href="[doc_base_url][dir][item_url]/reply" rel="nofollow">{thread_reply_in_this_thread}</a></li>
</ul>
[end]
[for thread_sort_tab]
<div class="threadbox[if-index odd] threadboxcolor[end]">
[if thread_sort_tab_can_write]<a class="threadedit" href="[thread_sort_tab_link]/emacs" rel="nofollow">\[{edit}\]</a>[end]
[if thread_mount_arg_is "subject"]<h2[if thread_mount_arg_is "info"] class="withinfo"[end]>[thread_sort_tab_subject]</h2>[end]
[if thread_mount_arg_is "info"][include "thread_sort_tab_info.html"][end]
[thread_sort_tab_print_content]
</div>
[end]
[end] [end]
[for thread_sort_tab]
<div class="threadbox[if-index even] threadboxcolor[end]">
[if thread_sort_tab_can_write]<a class="threadedit" href="[thread_sort_tab_link]/emacs" rel="nofollow">\[{edit}\]</a>[end]
[if mount_thread_arg_is "subject"]<h2[if mount_thread_arg_is "info"] class="withinfo"[end]>[thread_sort_tab_subject]</h2>[end]
[if mount_thread_arg_is "info"][include "thread_sort_tab_info.html"][end]
[thread_sort_tab_print_content]
</div>
[end]

View File

@ -1,4 +1,4 @@
<p class="[if-index odd]itemtabinfo[else][if mount_thread_arg_is "subject"]itemtabinfo[else]itemtabinfo2[end][end]"> <p class="[if-index even]itemtabinfo[else][if thread_mount_arg_is "subject"]itemtabinfo[else]itemtabinfo2[end][end]">
{added_by}: [thread_sort_tab_user], [thread_sort_tab_date_creation_nice][if-no thread_sort_tab_dates_equal], {added_by}: [thread_sort_tab_user], [thread_sort_tab_date_creation_nice][if-no thread_sort_tab_dates_equal],
{last_modified}[if thread_sort_tab_users_different] {by}: [thread_sort_tab_modification_user],[else]:[end] {last_modified}[if thread_sort_tab_users_different] {by}: [thread_sort_tab_modification_user],[else]:[end]

View File

@ -39,6 +39,7 @@ void print_syntax()
int main(int argv, char ** argc) int main(int argv, char ** argc)
{ {
std::srand(std::time(0)); std::srand(std::time(0));

View File

@ -178,20 +178,6 @@ void RemoveFile(PluginInfo & info)
void RemoveDir(PluginInfo & info) void RemoveDir(PluginInfo & info)
{ {
DbItemQuery query;
std::vector<long> items;
size_t i;
// !! may only files can be retrieved here?
query.SetAll(false, false);
query.WhereParentId(info.l1);
info.db->GetItems(items, query);
// removing childs
for(i=0 ; i<items.size() ; ++i)
stats.RemoveItem(items[i]);
// removing the directory
stats.RemoveItem(info.l1); stats.RemoveItem(info.l1);
} }

View File

@ -214,7 +214,7 @@ showthreads.o: ../../core/synchro.h tdb.h thread.h ../../db/dbbase.h
showthreads.o: threadinfo.h showthreads.o: threadinfo.h
tdb.o: tdb.h thread.h ../../db/dbbase.h ../../core/error.h ../../core/log.h tdb.o: tdb.h thread.h ../../db/dbbase.h ../../core/error.h ../../core/log.h
tdb.o: ../../core/textstream.h ../../core/log.h tdb.o: ../../core/textstream.h ../../core/log.h
templates.o: threadinfo.h thread.h ../../core/item.h ../../core/system.h templates.o: threadinfo.h ../../core/item.h ../../core/system.h
templates.o: ../../core/dirs.h ../../core/item.h ../../core/dircontainer.h templates.o: ../../core/dirs.h ../../core/item.h ../../core/dircontainer.h
templates.o: ../../db/db.h ../../db/dbbase.h ../../db/dbconn.h templates.o: ../../db/db.h ../../db/dbbase.h ../../db/dbconn.h
templates.o: ../../db/dbtextstream.h ../../core/textstream.h templates.o: ../../db/dbtextstream.h ../../core/textstream.h
@ -240,15 +240,15 @@ templates.o: ../../core/mount.h ../../core/mountparser.h ../../core/config.h
templates.o: ../../core/confparser.h ../../core/htmlfilter.h templates.o: ../../core/confparser.h ../../core/htmlfilter.h
templates.o: ../../core/users.h ../../core/groups.h ../../core/group.h templates.o: ../../core/users.h ../../core/groups.h ../../core/group.h
templates.o: ../../core/loadavg.h ../../core/thumb.h ../../core/basethread.h templates.o: ../../core/loadavg.h ../../core/thumb.h ../../core/basethread.h
templates.o: reply.h ../../functions/functionbase.h ../../core/request.h templates.o: thread.h tdb.h ../../db/dbbase.h reply.h
templates.o: ../../functions/functionbase.h ../../core/request.h
templates.o: ../../core/requesttypes.h ../../templates/htmltextstream.h templates.o: ../../core/requesttypes.h ../../templates/htmltextstream.h
templates.o: ../../core/synchro.h tdb.h ../../db/dbbase.h funthread.h templates.o: ../../core/synchro.h funthread.h createthread.h showthreads.h
templates.o: createthread.h showthreads.h ../../core/misc.h templates.o: ../../core/misc.h ../../core/plugin.h pluginmsg.h
templates.o: ../../core/plugin.h pluginmsg.h ../../core/system.h templates.o: ../../core/system.h ../../core/sessionmanager.h
templates.o: ../../core/sessionmanager.h ../../core/sessioncontainer.h templates.o: ../../core/sessioncontainer.h ../../functions/functions.h
templates.o: ../../functions/functions.h ../../functions/functionbase.h templates.o: ../../functions/functionbase.h ../../functions/functionparser.h
templates.o: ../../functions/functionparser.h ../../core/cur.h templates.o: ../../core/cur.h ../../functions/adduser.h ../../functions/cat.h
templates.o: ../../functions/adduser.h ../../functions/cat.h
templates.o: ../../functions/chmod.h ../../functions/privchanger.h templates.o: ../../functions/chmod.h ../../functions/privchanger.h
templates.o: ../../functions/chown.h ../../functions/ckeditor.h templates.o: ../../functions/chown.h ../../functions/ckeditor.h
templates.o: ../../functions/cp.h ../../functions/default.h templates.o: ../../functions/cp.h ../../functions/default.h
@ -269,7 +269,7 @@ templates.o: ../../templates/patterncacher.h
templates.o: ../../templates/ckeditorgetparser.h templates.o: ../../templates/ckeditorgetparser.h
templates.o: ../../core/httpsimpleparser.h ../../core/log.h templates.o: ../../core/httpsimpleparser.h ../../core/log.h
templates.o: ../../templates/indexpatterns.h ../../core/sessionmanager.h templates.o: ../../templates/indexpatterns.h ../../core/sessionmanager.h
threadinfo.o: threadinfo.h thread.h ../../core/item.h ../../core/system.h threadinfo.o: threadinfo.h ../../core/item.h ../../core/system.h
threadinfo.o: ../../core/dirs.h ../../core/item.h ../../core/dircontainer.h threadinfo.o: ../../core/dirs.h ../../core/item.h ../../core/dircontainer.h
threadinfo.o: ../../db/db.h ../../db/dbbase.h ../../db/dbconn.h threadinfo.o: ../../db/db.h ../../db/dbbase.h ../../db/dbconn.h
threadinfo.o: ../../db/dbtextstream.h ../../core/textstream.h threadinfo.o: ../../db/dbtextstream.h ../../core/textstream.h
@ -295,3 +295,4 @@ threadinfo.o: ../../core/mount.h ../../core/mountparser.h ../../core/config.h
threadinfo.o: ../../core/confparser.h ../../core/htmlfilter.h threadinfo.o: ../../core/confparser.h ../../core/htmlfilter.h
threadinfo.o: ../../core/users.h ../../core/groups.h ../../core/group.h threadinfo.o: ../../core/users.h ../../core/groups.h ../../core/group.h
threadinfo.o: ../../core/loadavg.h ../../core/thumb.h ../../core/basethread.h threadinfo.o: ../../core/loadavg.h ../../core/thumb.h ../../core/basethread.h
threadinfo.o: thread.h tdb.h ../../db/dbbase.h

View File

@ -69,7 +69,7 @@ void CreateThread::MakePost()
if( cur->request->status == WINIX_ERR_OK ) if( cur->request->status == WINIX_ERR_OK )
{ {
thread.Clear(); thread.Clear();
thread.file_id = cur->request->item.id; thread.file_id = cur->request->item.id;
cur->request->status = tdb->AddThread(thread); cur->request->status = tdb->AddThread(thread);
} }

View File

@ -51,9 +51,6 @@ return true;
void FunThread::PrepareThread(long file_id) void FunThread::PrepareThread(long file_id)
{ {
thread_info->Clear(); thread_info->Clear();
//cur->request->status = tdb->GetThreadByFileId(file_id, thread);
cur->request->status = tdb->GetAnswers(file_id, id_tab); cur->request->status = tdb->GetAnswers(file_id, id_tab);
if( !id_tab.empty() ) if( !id_tab.empty() )
@ -68,6 +65,7 @@ void FunThread::PrepareThread(long file_id)
iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE); iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE);
db->GetItems(thread_info->item_tab, iq); db->GetItems(thread_info->item_tab, iq);
system->CheckAccessToItems(thread_info->item_tab);
thread_info->item_sort_tab.resize(thread_info->item_tab.size()); thread_info->item_sort_tab.resize(thread_info->item_tab.size());
@ -75,8 +73,6 @@ void FunThread::PrepareThread(long file_id)
for(size_t i=0 ; i<thread_info->item_tab.size() ; ++i) for(size_t i=0 ; i<thread_info->item_tab.size() ; ++i)
thread_info->item_sort_tab[i] = &thread_info->item_tab[i]; thread_info->item_sort_tab[i] = &thread_info->item_tab[i];
} }
system->CheckAccessToItems(thread_info->item_tab);
} }

View File

@ -74,7 +74,7 @@ void AddMounts(PluginInfo & info)
void RemoveThread(PluginInfo & i) void RemoveThread(PluginInfo & i)
{ {
thread_info.RemoveThread(i.l1);
} }
@ -97,6 +97,9 @@ void SetSortTab(PluginInfo & info)
typedef std::vector<Item*> SortTab; typedef std::vector<Item*> SortTab;
SortTab * psort_tab = reinterpret_cast<SortTab*>(info.p1); SortTab * psort_tab = reinterpret_cast<SortTab*>(info.p1);
// !! dodac jakies czyszczenie tej tablicy wskaznikow na koncu przetwarzania requestu
// aby kiedys przypadkowo nie odwolac sie do nie istniejacego obiektu
// poprzez bezposrednie uzycie jakiejs funkcji z ezc
thread_info.item_sort_tab = *psort_tab; thread_info.item_sort_tab = *psort_tab;
} }
@ -130,23 +133,25 @@ void Init(PluginInfo & info)
{ {
using namespace Thread; using namespace Thread;
plugin.Assign(WINIX_CREATE_FUNCTIONS, AddFunctions); plugin.Assign(WINIX_CREATE_FUNCTIONS, AddFunctions);
plugin.Assign(WINIX_SELECT_DEFAULT_FUNCTION, SelectDefaultFunction); plugin.Assign(WINIX_SELECT_DEFAULT_FUNCTION, SelectDefaultFunction);
plugin.Assign(WINIX_ADD_MOUNTS, AddMounts); plugin.Assign(WINIX_ADD_MOUNTS, AddMounts);
plugin.Assign(WINIX_FILE_REMOVED, RemoveThread); plugin.Assign(WINIX_FILE_REMOVED, RemoveThread);
plugin.Assign(WINIX_NOTIFY_ADD_TEMPLATE, AddNotifyTemplate); plugin.Assign(WINIX_NOTIFY_ADD_TEMPLATE, AddNotifyTemplate);
plugin.Assign(WINIX_TEMPLATES_CREATEFUNCTIONS, AddEzcFunctions); plugin.Assign(WINIX_TEMPLATES_CREATEFUNCTIONS, AddEzcFunctions);
// for other plugins // for other plugins
plugin.Assign(WINIX_PL_THREAD_SET_SORTTAB, SetSortTab); plugin.Assign(WINIX_PL_THREAD_SET_SORTTAB, SetSortTab);
plugin.Assign(WINIX_PL_THREAD_READ_THREADS, ReadThreads); plugin.Assign(WINIX_PL_THREAD_READ_THREADS, ReadThreads);
plugin.Assign(WINIX_PL_THREAD_SET_SORTTAB_INDEX, SetSortTabIndex); plugin.Assign(WINIX_PL_THREAD_SET_SORTTAB_INDEX, SetSortTabIndex);
plugin.Assign(WINIX_PL_THREAD_PREPARE_THREAD, PrepareThread); plugin.Assign(WINIX_PL_THREAD_PREPARE_THREAD, PrepareThread);
tdb.SetConn(info.db->GetConn()); tdb.SetConn(info.db->GetConn());
tdb.LogQueries(info.config->log_db_query); tdb.LogQueries(info.config->log_db_query);
// thread_info and fun_show_threads are used in 'ticket' plugins too // thread_info and fun_show_threads are used in 'ticket' plugins too
thread_info.SetDb(info.db);
thread_info.SetTDb(&tdb);
thread_info.SetSystem(info.system); thread_info.SetSystem(info.system);
thread_info.plugin_id = info.plugin_id; thread_info.plugin_id = info.plugin_id;

View File

@ -12,11 +12,13 @@
#define WINIX_PL_THREAD_SET_SORTTAB 4000 #define WINIX_PL_THREAD_SET_SORTTAB 4000
#define WINIX_PL_THREAD_READ_THREADS 4001 #define WINIX_PL_THREAD_READ_THREADS 4001
#define WINIX_PL_THREAD_SET_SORTTAB_INDEX 4002 #define WINIX_PL_THREAD_SET_SORTTAB_INDEX 4002
#define WINIX_PL_THREAD_CAN_USE_REPLY 4003 #define WINIX_PL_THREAD_PREPARE_THREAD 4003
#define WINIX_PL_THREAD_PREPARE_THREAD 4004
#endif #endif

View File

@ -21,6 +21,7 @@ namespace Thread
Reply::Reply() Reply::Reply()
{ {
fun.url = L"reply"; fun.url = L"reply";
files_dir = 0;
} }
@ -37,22 +38,18 @@ void Reply::SetThreadInfo(ThreadInfo * pthread_info)
} }
/*
we can use 'reply' function everywhere where 'thread_dir' mount option is defined
if there is no such a thread in 'thread' table it will be added automatically
*/
bool Reply::HasAccess() bool Reply::HasAccess()
{ {
if( !cur->request->is_item ) if( !cur->request->is_item )
return false; return false;
Item * dir = thread_info->FindThreadDir(); files_dir = thread_info->FindThreadDir();
if( !dir || !system->HasWriteAccess(*dir) ) if( !files_dir || !system->HasWriteAccess(*files_dir) )
return false;
plugin.Call(WINIX_PL_THREAD_CAN_USE_REPLY);
if( plugin.True() > 0 )
return true;
if( system->mounts.pmount->type != thread_info->mount_type_thread )
return false; return false;
return true; return true;
@ -62,13 +59,8 @@ return true;
void Reply::MakePost() void Reply::MakePost()
{ {
Item * dir = thread_info->FindThreadDir(); // !! jak bedzie dostepne assert
// ASSERT(files_dir)
if( !dir )
{
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
return;
}
if( tdb->GetThreadByFileId(cur->request->item.id, thread) != WINIX_ERR_OK ) if( tdb->GetThreadByFileId(cur->request->item.id, thread) != WINIX_ERR_OK )
{ {
@ -85,7 +77,7 @@ void Reply::MakePost()
functions->ReadItem(answer, Item::file); functions->ReadItem(answer, Item::file);
functions->SetUser(answer); functions->SetUser(answer);
functions->PrepareUrl(answer); functions->PrepareUrl(answer);
answer.parent_id = dir->id; answer.parent_id = files_dir->id;
answer.privileges = 0644; // !! tymczasowo answer.privileges = 0644; // !! tymczasowo
if( functions->CheckAbuse() ) if( functions->CheckAbuse() )

View File

@ -38,6 +38,7 @@ private:
ThreadInfo * thread_info; ThreadInfo * thread_info;
Item answer; Item answer;
Thread thread; Thread thread;
Item * files_dir;
}; };

View File

@ -96,17 +96,6 @@ void ShowThreads::ReadFiles()
} }
void ShowThreads::ReadThreads()
{
// reading threads for the files
file_id_tab.resize(thread_info->item_sort_tab.size());
for(size_t i=0 ; i<thread_info->item_sort_tab.size() ; ++i)
file_id_tab[i] = thread_info->item_sort_tab[i]->id;
tdb->GetThreads(file_id_tab, thread_info->thread_tab);
}
void ShowThreads::CreatePointers() void ShowThreads::CreatePointers()
{ {
@ -118,7 +107,6 @@ void ShowThreads::CreatePointers()
} }
void ShowThreads::SortPointers() void ShowThreads::SortPointers()
{ {
int sort_type = 1; int sort_type = 1;
@ -132,6 +120,19 @@ void ShowThreads::SortPointers()
void ShowThreads::ReadThreads()
{
// reading threads for the files
file_id_tab.resize(thread_info->item_sort_tab.size());
for(size_t i=0 ; i<thread_info->item_sort_tab.size() ; ++i)
file_id_tab[i] = thread_info->item_sort_tab[i]->id;
tdb->GetThreads(file_id_tab, thread_info->thread_tab);
}
void ShowThreads::MakeGet() void ShowThreads::MakeGet()
{ {
thread_info->Clear(); thread_info->Clear();

View File

@ -175,12 +175,12 @@ return status;
Error TDb::EditThreadAddItem(long file_id, long item_id) Error TDb::EditThreadAddItem(long file_id, long answer_id)
{ {
query.Clear(); query.Clear();
query << R("insert into plugins.thread_files (file_id, answer_id) values (") query << R("insert into plugins.thread_files (file_id, answer_id) values (")
<< file_id << file_id
<< item_id << answer_id
<< R(");"); << R(");");
Error status = DoCommand(query); Error status = DoCommand(query);
@ -190,7 +190,7 @@ Error TDb::EditThreadAddItem(long file_id, long item_id)
query.Clear(); query.Clear();
query << R("update plugins.thread set (last_item, replies) = (") query << R("update plugins.thread set (last_item, replies) = (")
<< item_id << answer_id
<< R(", replies+1) where file_id=") << R(", replies+1) where file_id=")
<< file_id << file_id
<< R(";"); << R(";");

View File

@ -17,6 +17,7 @@
#include "core/error.h" #include "core/error.h"
namespace Thread namespace Thread
{ {
@ -29,7 +30,7 @@ public:
Error GetThreadByFileId(long file_id, Thread & thread); Error GetThreadByFileId(long file_id, Thread & thread);
Error GetThreads(const std::vector<long> & file_id_tab, std::vector<Thread> & thread_tab); Error GetThreads(const std::vector<long> & file_id_tab, std::vector<Thread> & thread_tab);
Error GetAnswers(long file_id, std::vector<long> & answer_id_tab); Error GetAnswers(long file_id, std::vector<long> & answer_id_tab);
Error EditThreadAddItem(long file_id, long item_id); Error EditThreadAddItem(long file_id, long answer_id);
Error EditThreadRemoveItem(long file_id); Error EditThreadRemoveItem(long file_id);
Error RemoveThread(long file_id); Error RemoveThread(long file_id);
long FindLastItem(long file_id); long FindLastItem(long file_id);

View File

@ -472,6 +472,14 @@ void thread_can_create(Info & i)
void thread_mount_arg_is(Info & i)
{
if( system->mounts.pmount )
i.res = system->mounts.pmount->IsArg(thread_info.mount_par_thread, i.par);
}
void AddEzcFunctions(PluginInfo & info) void AddEzcFunctions(PluginInfo & info)
@ -518,6 +526,7 @@ void AddEzcFunctions(PluginInfo & info)
fun->Insert("thread_can_reply", thread_can_reply); fun->Insert("thread_can_reply", thread_can_reply);
fun->Insert("thread_can_create", thread_can_create); fun->Insert("thread_can_create", thread_can_create);
fun->Insert("thread_mount_arg_is", thread_mount_arg_is);
} }

View File

@ -14,6 +14,17 @@
namespace Thread namespace Thread
{ {
void ThreadInfo::SetDb(Db * pdb)
{
db = pdb;
}
void ThreadInfo::SetTDb(TDb * ptdb)
{
tdb = ptdb;
}
void ThreadInfo::SetSystem(System * psystem) void ThreadInfo::SetSystem(System * psystem)
{ {
@ -47,6 +58,18 @@ return out_dir_tab.back();
void ThreadInfo::RemoveThread(long file_id)
{
if( tdb->GetAnswers(file_id, remove_answer_id_tab) == WINIX_ERR_OK )
{
for(size_t i=0 ; i<remove_answer_id_tab.size() ; ++i)
db->DelFileById(remove_answer_id_tab[i]);
}
tdb->RemoveThread(file_id);
}
} // namespace } // namespace

View File

@ -11,10 +11,11 @@
#define headerfile_winix_plugins_thread_threadinfo #define headerfile_winix_plugins_thread_threadinfo
#include <vector> #include <vector>
#include "thread.h"
#include "core/item.h" #include "core/item.h"
#include "core/system.h" #include "core/system.h"
#include "db/db.h"
#include "thread.h"
#include "tdb.h"
@ -26,10 +27,14 @@ class ThreadInfo
public: public:
void SetDb(Db * pdb);
void SetTDb(TDb * ptdb);
void SetSystem(System * psystem); void SetSystem(System * psystem);
void Clear(); void Clear();
Item * FindThreadDir(); Item * FindThreadDir();
// id of a mount type // id of a mount type
int mount_type_thread; int mount_type_thread;
@ -57,11 +62,18 @@ public:
// template index for notifications // template index for notifications
size_t template_index; size_t template_index;
void RemoveThread(long file_id);
private: private:
Db * db;
TDb * tdb;
System * system; System * system;
std::vector<Item*> out_dir_tab; std::vector<Item*> out_dir_tab;
std::vector<long> remove_answer_id_tab;
Item out_item; Item out_item;

View File

@ -51,6 +51,7 @@ createticket.o: ../../functions/tinymce.h ../../functions/uname.h
createticket.o: ../../functions/upload.h ../../functions/uptime.h createticket.o: ../../functions/upload.h ../../functions/uptime.h
createticket.o: ../../functions/who.h ../../functions/vim.h createticket.o: ../../functions/who.h ../../functions/vim.h
createticket.o: ../../core/htmlfilter.h sessiondata.h ../../core/plugindata.h createticket.o: ../../core/htmlfilter.h sessiondata.h ../../core/plugindata.h
createticket.o: ../../functions/rm.h
editticket.o: editticket.h tdb.h ticket.h ../../db/dbbase.h ../../db/dbconn.h editticket.o: editticket.h tdb.h ticket.h ../../db/dbbase.h ../../db/dbconn.h
editticket.o: ../../db/dbtextstream.h ../../core/textstream.h editticket.o: ../../db/dbtextstream.h ../../core/textstream.h
editticket.o: ../../core/misc.h ../../core/item.h ../../core/error.h editticket.o: ../../core/misc.h ../../core/item.h ../../core/error.h
@ -99,7 +100,7 @@ editticket.o: ../../functions/uname.h ../../functions/upload.h
editticket.o: ../../functions/uptime.h ../../functions/who.h editticket.o: ../../functions/uptime.h ../../functions/who.h
editticket.o: ../../functions/vim.h ../../core/htmlfilter.h editticket.o: ../../functions/vim.h ../../core/htmlfilter.h
editticket.o: ../../functions/functionbase.h ../../core/synchro.h editticket.o: ../../functions/functionbase.h ../../core/synchro.h
editticket.o: sessiondata.h ../../core/plugindata.h editticket.o: sessiondata.h ../../core/plugindata.h ../../functions/rm.h
funticket.o: funticket.h tdb.h ticket.h ../../db/dbbase.h ../../db/dbconn.h funticket.o: funticket.h tdb.h ticket.h ../../db/dbbase.h ../../db/dbconn.h
funticket.o: ../../db/dbtextstream.h ../../core/textstream.h funticket.o: ../../db/dbtextstream.h ../../core/textstream.h
funticket.o: ../../core/misc.h ../../core/item.h ../../core/error.h funticket.o: ../../core/misc.h ../../core/item.h ../../core/error.h
@ -206,9 +207,11 @@ init.o: ../../templates/templates.h ../../templates/patterncacher.h
init.o: ../../templates/ckeditorgetparser.h ../../core/httpsimpleparser.h init.o: ../../templates/ckeditorgetparser.h ../../core/httpsimpleparser.h
init.o: ../../core/log.h ../../templates/indexpatterns.h init.o: ../../core/log.h ../../templates/indexpatterns.h
init.o: ../../core/sessionmanager.h sessiondata.h ../../core/plugindata.h init.o: ../../core/sessionmanager.h sessiondata.h ../../core/plugindata.h
init.o: ../../plugins/thread/showthreads.h ../../plugins/thread/threadinfo.h init.o: ../../functions/rm.h ../../plugins/thread/showthreads.h
init.o: ../../plugins/thread/thread.h ../../plugins/thread/pluginmsg.h init.o: ../../plugins/thread/threadinfo.h ../../plugins/thread/thread.h
init.o: ../../plugins/thread/pluginmsg.h
sessiondata.o: sessiondata.h ../../core/plugindata.h ticket.h sessiondata.o: sessiondata.h ../../core/plugindata.h ticket.h
sessiondata.o: ../../functions/rm.h
showtickets.o: showtickets.h tdb.h ticket.h ../../db/dbbase.h showtickets.o: showtickets.h tdb.h ticket.h ../../db/dbbase.h
showtickets.o: ../../db/dbconn.h ../../db/dbtextstream.h showtickets.o: ../../db/dbconn.h ../../db/dbtextstream.h
showtickets.o: ../../core/textstream.h ../../core/misc.h ../../core/item.h showtickets.o: ../../core/textstream.h ../../core/misc.h ../../core/item.h
@ -324,7 +327,7 @@ templates.o: ../../templates/templates.h ../../templates/patterncacher.h
templates.o: ../../templates/ckeditorgetparser.h templates.o: ../../templates/ckeditorgetparser.h
templates.o: ../../core/httpsimpleparser.h ../../core/log.h templates.o: ../../core/httpsimpleparser.h ../../core/log.h
templates.o: ../../templates/indexpatterns.h ../../core/sessionmanager.h templates.o: ../../templates/indexpatterns.h ../../core/sessionmanager.h
templates.o: sessiondata.h ../../core/plugindata.h templates.o: sessiondata.h ../../core/plugindata.h ../../functions/rm.h
templates.o: ../../plugins/thread/pluginmsg.h templates.o: ../../plugins/thread/pluginmsg.h
ticketconf.o: ticketconf.h ticketconf.o: ticketconf.h
ticketinfo.o: ticketinfo.h ticket.h ticketparser.h ticketconf.h ticketinfo.o: ticketinfo.h ticket.h ticketparser.h ticketconf.h
@ -375,6 +378,6 @@ ticketinfo.o: ../../functions/uptime.h ../../functions/who.h
ticketinfo.o: ../../functions/vim.h ../../core/htmlfilter.h tdb.h ticketinfo.o: ../../functions/vim.h ../../core/htmlfilter.h tdb.h
ticketinfo.o: ../../db/dbbase.h ../../db/dbconn.h ../../db/dbtextstream.h ticketinfo.o: ../../db/dbbase.h ../../db/dbconn.h ../../db/dbtextstream.h
ticketinfo.o: ../../core/error.h ../../core/log.h ../../core/misc.h ticketinfo.o: ../../core/error.h ../../core/log.h ../../core/misc.h
ticketinfo.o: sessiondata.h ../../core/plugindata.h ticketinfo.o: sessiondata.h ../../core/plugindata.h ../../functions/rm.h
ticketparser.o: ticketparser.h ticketconf.h ../../core/log.h ticketparser.o: ticketparser.h ticketconf.h ../../core/log.h
ticketparser.o: ../../core/misc.h ticketparser.o: ../../core/misc.h

View File

@ -53,7 +53,7 @@ return true;
void CreateTicket::AddTicket(Ticket & ticket, Item & item) void CreateTicket::AddTicket(Ticket & ticket, Item & item)
{ {
ticket.file_id = item.id; ticket.file_id = item.id;
cur->request->status = tdb->AddTicket(ticket); cur->request->status = tdb->AddTicket(ticket);
if( cur->request->status == WINIX_ERR_OK ) if( cur->request->status == WINIX_ERR_OK )
@ -91,7 +91,7 @@ void CreateTicket::Submit(Ticket & ticket, Item & item)
if( cur->request->status == WINIX_ERR_OK ) if( cur->request->status == WINIX_ERR_OK )
{ {
log << log2 << "CreateTicket: added a new ticket" << logend; log << log2 << "CreateTicket: added a new ticket" << logend;
RemoveTicket(); RemoveTmpTicket();
system->RedirectTo(item); system->RedirectTo(item);
} }
else else
@ -103,13 +103,14 @@ void CreateTicket::Submit(Ticket & ticket, Item & item)
void CreateTicket::RemoveTicket() void CreateTicket::RemoveTmpTicket()
{ {
SessionData * session_data = reinterpret_cast<SessionData*>( SessionData * session_data = reinterpret_cast<SessionData*>(
cur->session->plugin_data.Get(ticket_info->plugin_id) ); cur->session->plugin_data.Get(ticket_info->plugin_id) );
long dir_id = cur->request->dir_tab.back()->id; long dir_id = cur->request->dir_tab.back()->id;
session_data->create_ticket_map.erase(dir_id); session_data->create_ticket_map.erase(dir_id);
session_data->create_file_map.erase(dir_id);
} }
@ -126,6 +127,17 @@ return ticket;
} }
std::vector<long> & CreateTicket::PrepareFileMap()
{
SessionData * session_data = reinterpret_cast<SessionData*>(
cur->session->plugin_data.Get(ticket_info->plugin_id) );
long dir_id = cur->request->dir_tab.back()->id;
std::vector<long> & file_map = session_data->GetFileTab(dir_id, session_data->create_file_map);
return file_map;
}
void CreateTicket::MakePost() void CreateTicket::MakePost()
{ {
@ -135,8 +147,9 @@ void CreateTicket::MakePost()
Ticket & ticket = PrepareTicket(); Ticket & ticket = PrepareTicket();
Item & item = cur->request->item; Item & item = cur->request->item;
ticket_info->ticket = &ticket; ticket_info->ticket = &ticket;
std::vector<long> & file_map = PrepareFileMap();
ticket_info->ReadTicketParams(ticket, false); ticket_info->ReadTicketParams(ticket, false, &file_map);
functions->ReadItem(item, Item::file); functions->ReadItem(item, Item::file);
if( !cur->request->IsPostVar(L"fileuploadsubmit") ) if( !cur->request->IsPostVar(L"fileuploadsubmit") )

View File

@ -36,8 +36,9 @@ private:
void AddTicket(Ticket & ticket, Item & item); void AddTicket(Ticket & ticket, Item & item);
void Submit(Ticket & ticket, Item & item); void Submit(Ticket & ticket, Item & item);
void RemoveTicket(); void RemoveTmpTicket();
Ticket & PrepareTicket(); Ticket & PrepareTicket();
std::vector<long> & PrepareFileMap();
TDb * tdb; TDb * tdb;
TicketInfo * ticket_info; TicketInfo * ticket_info;

View File

@ -91,7 +91,7 @@ void EditTicket::Submit(Ticket & ticket, Item & item)
if( cur->request->status == WINIX_ERR_OK ) if( cur->request->status == WINIX_ERR_OK )
{ {
log << log2 << "EditTicket: ticket modified" << logend; log << log2 << "EditTicket: ticket modified" << logend;
RemoveTicket(); RemoveTmpTicket();
system->RedirectTo(item); system->RedirectTo(item);
} }
else else
@ -104,13 +104,13 @@ void EditTicket::Submit(Ticket & ticket, Item & item)
void EditTicket::RemoveTicket() void EditTicket::RemoveTmpTicket()
{ {
SessionData * session_data = reinterpret_cast<SessionData*>( SessionData * session_data = reinterpret_cast<SessionData*>(
cur->session->plugin_data.Get(ticket_info->plugin_id) ); cur->session->plugin_data.Get(ticket_info->plugin_id) );
long file_id = cur->request->item.id; long file_id = cur->request->item.id;
session_data->create_ticket_map.erase(file_id); session_data->edit_ticket_map.erase(file_id);
session_data->new_file_map.erase(file_id); session_data->new_file_map.erase(file_id);
} }

View File

@ -34,7 +34,7 @@ public:
private: private:
void RemoveTicket(); void RemoveTmpTicket();
Ticket & PrepareTicket(); Ticket & PrepareTicket();
std::vector<long> & PrepareFileMap(); std::vector<long> & PrepareFileMap();
std::wstring old_url; std::wstring old_url;

View File

@ -88,7 +88,7 @@ void ProcessRequest(PluginInfo & info)
void RemoveTicket(PluginInfo & i) void RemoveTicket(PluginInfo & i)
{ {
tdb.RemoveTicket(i.l1); ticket_info.RemoveTicket(i.l1);
} }
@ -107,6 +107,8 @@ void AddNotifyTemplate(PluginInfo & info)
void CreateSession(PluginInfo & info) void CreateSession(PluginInfo & info)
{ {
SessionData * p = new SessionData(); SessionData * p = new SessionData();
p->fun_rm = &info.functions->fun_rm;
info.cur->session->plugin_data.Assign(p); info.cur->session->plugin_data.Assign(p);
log << log4 << "Ticket: created ticket plugin data: " << (void*)p << logend; log << log4 << "Ticket: created ticket plugin data: " << (void*)p << logend;
} }
@ -115,14 +117,7 @@ void CreateSession(PluginInfo & info)
void RemoveSession(PluginInfo & info) void RemoveSession(PluginInfo & info)
{ {
delete info.plugin_data_base; delete info.plugin_data_base;
log << log4 << "Ticket: removed ticket plugin date: " << (void*)info.plugin_data_base << logend; log << log4 << "Ticket: removed ticket plugin data: " << (void*)info.plugin_data_base << logend;
}
void CanUseReply(PluginInfo & info)
{
if( info.system->mounts.pmount && info.system->mounts.pmount->type == ticket_info.mount_type_ticket )
info.res = true;
} }
@ -149,7 +144,6 @@ using namespace Ticket;
plugin.Assign(WINIX_NOTIFY_ADD_TEMPLATE, AddNotifyTemplate); plugin.Assign(WINIX_NOTIFY_ADD_TEMPLATE, AddNotifyTemplate);
plugin.Assign(WINIX_SESSION_CREATED, CreateSession); plugin.Assign(WINIX_SESSION_CREATED, CreateSession);
plugin.Assign(WINIX_SESSION_REMOVE, RemoveSession); plugin.Assign(WINIX_SESSION_REMOVE, RemoveSession);
plugin.Assign(WINIX_PL_THREAD_CAN_USE_REPLY, CanUseReply);
tdb.SetConn(info.db->GetConn()); tdb.SetConn(info.db->GetConn());
tdb.LogQueries(info.config->log_db_query); tdb.LogQueries(info.config->log_db_query);

View File

@ -13,6 +13,39 @@
namespace Ticket namespace Ticket
{ {
SessionData::SessionData()
{
fun_rm = 0;
}
SessionData::~SessionData()
{
RemoveFileMap(create_file_map);
RemoveFileMap(new_file_map);
}
void SessionData::RemoveFileMap(SessionData::FileMap & file_map)
{
FileMap::iterator i;
if( fun_rm )
{
for(i=file_map.begin() ; i!=file_map.end() ; ++i)
{
for(size_t a=0 ; a<i->second.size() ; ++a)
{
long file_id = i->second[a];
fun_rm->RemoveItemById(file_id);
}
}
file_map.clear();
}
}
Ticket & SessionData::GetTicket(long id, SessionData::TicketMap & ticket_map, bool * is_new) Ticket & SessionData::GetTicket(long id, SessionData::TicketMap & ticket_map, bool * is_new)

View File

@ -15,6 +15,7 @@
#include <map> #include <map>
#include "core/plugindata.h" #include "core/plugindata.h"
#include "ticket.h" #include "ticket.h"
#include "functions/rm.h"
namespace Ticket namespace Ticket
@ -23,9 +24,14 @@ namespace Ticket
struct SessionData : public PluginDataBase struct SessionData : public PluginDataBase
{ {
SessionData();
~SessionData();
typedef std::map<long, Ticket> TicketMap; typedef std::map<long, Ticket> TicketMap;
typedef std::map<long, std::vector<long> > FileMap; typedef std::map<long, std::vector<long> > FileMap;
// temporary tickets for 'createticket' function // temporary tickets for 'createticket' function
// <parent_dir_id, Ticket> // <parent_dir_id, Ticket>
TicketMap create_ticket_map; TicketMap create_ticket_map;
@ -34,8 +40,14 @@ struct SessionData : public PluginDataBase
// <file_id, Ticket> // <file_id, Ticket>
TicketMap edit_ticket_map; TicketMap edit_ticket_map;
// temporary files for 'createticket' function
// these files should be deleted if a user will not click on the submit button
FileMap create_file_map;
// temporary files for 'editticket' function // temporary files for 'editticket' function
// these files should be deleted if a user will not click on the submit button // these files should be deleted if a user will not click on the submit button
// !! zmienic nazwe na edit_file_map albo podobnie
FileMap new_file_map; FileMap new_file_map;
@ -44,6 +56,10 @@ struct SessionData : public PluginDataBase
std::vector<long> & GetFileTab(long id, FileMap & file_map); std::vector<long> & GetFileTab(long id, FileMap & file_map);
// for deleting new_file_map files
Fun::Rm * fun_rm;
void RemoveFileMap(FileMap & file_map);
}; };

View File

@ -62,7 +62,7 @@ bool ShowTickets::Sort::operator()(const Item * item1, const Item * item2)
time_t time1 = Time(tm1); time_t time1 = Time(tm1);
time_t time2 = Time(tm2); time_t time2 = Time(tm2);
return time1 < time2; return time1 > time2;
} }
} }
@ -91,17 +91,6 @@ void ShowTickets::ReadFiles()
} }
void ShowTickets::ReadTickets()
{
// reading tickets for the files
file_id_tab.resize(ticket_info->item_sort_tab.size());
for(size_t i=0 ; i<ticket_info->item_sort_tab.size() ; ++i)
file_id_tab[i] = ticket_info->item_sort_tab[i]->id;
tdb->GetTickets(file_id_tab, ticket_info->ticket_tab);
}
void ShowTickets::CreatePointers() void ShowTickets::CreatePointers()
{ {
@ -127,6 +116,18 @@ void ShowTickets::SortPointers()
void ShowTickets::ReadTickets()
{
// reading tickets for the files
file_id_tab.resize(ticket_info->item_sort_tab.size());
for(size_t i=0 ; i<ticket_info->item_sort_tab.size() ; ++i)
file_id_tab[i] = ticket_info->item_sort_tab[i]->id;
tdb->GetTickets(file_id_tab, ticket_info->ticket_tab);
}
void ShowTickets::MakeGet() void ShowTickets::MakeGet()
{ {
ticket_info->Clear(); ticket_info->Clear();

View File

@ -38,9 +38,9 @@ private:
std::vector<long> file_id_tab; std::vector<long> file_id_tab;
void ReadFiles(); void ReadFiles();
void ReadTickets();
void CreatePointers(); void CreatePointers();
void SortPointers(); void SortPointers();
void ReadTickets();
struct Sort struct Sort
{ {

View File

@ -71,6 +71,8 @@ Error TDb::GetTicket(long file_id, Ticket & ticket)
int cintvalue = AssertColumn(r, "int_value"); int cintvalue = AssertColumn(r, "int_value");
int cstrvalue = AssertColumn(r, "str_value"); int cstrvalue = AssertColumn(r, "str_value");
// !! mozna dodac uzycie ticket.par_tab.reserve()
for(int i=0 ; i<rows ; ++i) for(int i=0 ; i<rows ; ++i)
{ {
par.param = AssertValueInt(r, i, cparam); par.param = AssertValueInt(r, i, cparam);

View File

@ -49,6 +49,7 @@ return percent;
// binary search for conf_item.id in ticket.par_tab (ticket.par_tab must be sorted by 'param') // binary search for conf_item.id in ticket.par_tab (ticket.par_tab must be sorted by 'param')
// !! zmienic nazwe na find_ticket_param
bool find_ticket_value(const TicketConf::TicketItem & conf_item, const Ticket & ticket, size_t & ticket_par_index) bool find_ticket_value(const TicketConf::TicketItem & conf_item, const Ticket & ticket, size_t & ticket_par_index)
{ {
if( ticket.par_tab.empty() ) if( ticket.par_tab.empty() )
@ -68,6 +69,9 @@ bool find_ticket_value(const TicketConf::TicketItem & conf_item, const Ticket &
if( ticket.par_tab[o2].param == conf_item.id ) if( ticket.par_tab[o2].param == conf_item.id )
{ {
while( o2 > 0 && ticket.par_tab[o2-1].param == conf_item.id )
--o2;
ticket_par_index = o2; ticket_par_index = o2;
return true; return true;
} }
@ -81,7 +85,12 @@ bool find_ticket_value(const TicketConf::TicketItem & conf_item, const Ticket &
ticket_par_index = (o1 + o2) / 2; ticket_par_index = (o1 + o2) / 2;
if( ticket.par_tab[ticket_par_index].param == conf_item.id ) if( ticket.par_tab[ticket_par_index].param == conf_item.id )
{
while( ticket_par_index > 0 && ticket.par_tab[ticket_par_index-1].param == conf_item.id )
--ticket_par_index;
return true; return true;
}
if( ticket.par_tab[ticket_par_index].param < conf_item.id ) if( ticket.par_tab[ticket_par_index].param < conf_item.id )
o1 = ticket_par_index; o1 = ticket_par_index;

View File

@ -12,6 +12,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <algorithm>
namespace Ticket namespace Ticket
@ -27,7 +28,6 @@ struct Ticket
void Clear() void Clear()
{ {
// !! what about file_id?
param = 0; param = 0;
int_value = 0; int_value = 0;
str_value.clear(); str_value.clear();
@ -52,6 +52,19 @@ struct Ticket
sort_id = 0; sort_id = 0;
} }
struct Sort
{
bool operator()(const TicketParam & par1, const TicketParam & par2)
{
return par1.param < par2.param;
}
};
void SortParTab()
{
std::sort(par_tab.begin(), par_tab.end(), Sort());
}
Ticket() Ticket()
{ {

View File

@ -302,6 +302,7 @@ bool add = false;
if( cur->request->status == WINIX_ERR_OK ) if( cur->request->status == WINIX_ERR_OK )
{ {
add = true; add = true;
par.int_value = file.id;
system->MakePath(file, par.str_value); system->MakePath(file, par.str_value);
if( file_map ) if( file_map )
@ -335,6 +336,8 @@ bool exists = false;
ticket_param.Clear(); ticket_param.Clear();
log << log1 << "szukamy dla param_id: " << param_id << logend;
for(size_t i=0 ; i<cur_conf->tab.size() ; ++i) for(size_t i=0 ; i<cur_conf->tab.size() ; ++i)
{ {
if( param_id == cur_conf->tab[i].id ) if( param_id == cur_conf->tab[i].id )
@ -420,10 +423,27 @@ PostFileTab::iterator i2;
if( IsSubString(config->ticket_form_prefix, i2->first) ) if( IsSubString(config->ticket_form_prefix, i2->first) )
ReadTicketParam(ticket, Toi(i2->first.c_str() + config->ticket_form_prefix.size()), i2->second, file_map); ReadTicketParam(ticket, Toi(i2->first.c_str() + config->ticket_form_prefix.size()), i2->second, file_map);
} }
ticket.SortParTab();
} }
void TicketInfo::RemoveTicket(long file_id)
{
if( tdb->GetTicket(file_id, rm_ticket) == WINIX_ERR_OK )
{
for(size_t i=0 ; i<rm_ticket.par_tab.size(); ++i)
{
long id = rm_ticket.par_tab[i].int_value;
functions->fun_rm.RemoveItemById(id);
}
tdb->RemoveTicket(file_id);
}
}
} // namespace } // namespace

View File

@ -93,6 +93,8 @@ public:
void CheckMinMaxValue(const TicketConf::TicketItem & conf_item, Ticket::TicketParam & par); void CheckMinMaxValue(const TicketConf::TicketItem & conf_item, Ticket::TicketParam & par);
void ReadTicketParams(Ticket & ticket, bool clear_ticket = true, std::vector<long> * file_map = 0); void ReadTicketParams(Ticket & ticket, bool clear_ticket = true, std::vector<long> * file_map = 0);
void RemoveTicket(long file_id);
private: private:
Db * db; Db * db;
@ -119,6 +121,9 @@ private:
const TicketConf cur_conf_empty; const TicketConf cur_conf_empty;
const Ticket ticket_empty; const Ticket ticket_empty;
// for removing a ticket
Ticket rm_ticket;
bool GetConfContent(const std::wstring & path); bool GetConfContent(const std::wstring & path);
bool ParseTicketConf(long mount_dir_id, const std::wstring & path); bool ParseTicketConf(long mount_dir_id, const std::wstring & path);
void ReadTicketConf(Mounts & mounts, bool skip_existing_configs); void ReadTicketConf(Mounts & mounts, bool skip_existing_configs);

View File

@ -33,12 +33,6 @@ void mount_page_arg_is(Info & i)
} }
// !! nie potrzebne
void mount_thread_arg_is(Info & i)
{
//i.res = system->mounts.pmount->IsArg(system->mounts.MountParThread(), i.par);
}
void mount_has_html_template(Info & i) void mount_has_html_template(Info & i)
{ {

View File

@ -118,10 +118,7 @@ PatternTab::iterator i;
i = pattern_tab.find(item.id); i = pattern_tab.find(item.id);
if( i == pattern_tab.end() ) if( i == pattern_tab.end() )
{
//log << log2 << "PC: there is no such an item to update, id: " << item.id << ", url: " << item.url << logend;
return; return;
}
++(i->second.used); ++(i->second.used);
CreatePattern(item, i->second.pattern); CreatePattern(item, i->second.pattern);
@ -138,10 +135,7 @@ PatternTab::iterator i;
i = pattern_tab.find(item.id); i = pattern_tab.find(item.id);
if( i == pattern_tab.end() ) if( i == pattern_tab.end() )
{
log << log3 << "PC: there is no such an item to delete, id: " << item.id << ", url: " << item.url << logend;
return; return;
}
log << log2 << "PC: deleted pattern, id: " << item.id << ", url: " << item.url << logend; log << log2 << "PC: deleted pattern, id: " << item.id << ", url: " << item.url << logend;

View File

@ -285,7 +285,6 @@ void Templates::CreateFunctions()
*/ */
ezc_functions.Insert("mount_type_is", mount_type_is); ezc_functions.Insert("mount_type_is", mount_type_is);
ezc_functions.Insert("mount_page_arg_is", mount_page_arg_is); ezc_functions.Insert("mount_page_arg_is", mount_page_arg_is);
ezc_functions.Insert("mount_thread_arg_is", mount_thread_arg_is);
ezc_functions.Insert("mount_has_html_template", mount_has_html_template); ezc_functions.Insert("mount_has_html_template", mount_has_html_template);
ezc_functions.Insert("mount_first_html_template", mount_first_html_template); ezc_functions.Insert("mount_first_html_template", mount_first_html_template);

View File

@ -216,7 +216,6 @@ namespace TemplatesFunctions
*/ */
void mount_type_is(Info & i); void mount_type_is(Info & i);
void mount_page_arg_is(Info & i); void mount_page_arg_is(Info & i);
void mount_thread_arg_is(Info & i);
void mount_has_html_template(Info & i); void mount_has_html_template(Info & i);
void mount_first_html_template(Info & i); void mount_first_html_template(Info & i);