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:
@@ -51,6 +51,7 @@ createticket.o: ../../functions/tinymce.h ../../functions/uname.h
|
||||
createticket.o: ../../functions/upload.h ../../functions/uptime.h
|
||||
createticket.o: ../../functions/who.h ../../functions/vim.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: ../../db/dbtextstream.h ../../core/textstream.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/vim.h ../../core/htmlfilter.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: ../../db/dbtextstream.h ../../core/textstream.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: ../../core/log.h ../../templates/indexpatterns.h
|
||||
init.o: ../../core/sessionmanager.h sessiondata.h ../../core/plugindata.h
|
||||
init.o: ../../plugins/thread/showthreads.h ../../plugins/thread/threadinfo.h
|
||||
init.o: ../../plugins/thread/thread.h ../../plugins/thread/pluginmsg.h
|
||||
init.o: ../../functions/rm.h ../../plugins/thread/showthreads.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: ../../functions/rm.h
|
||||
showtickets.o: showtickets.h tdb.h ticket.h ../../db/dbbase.h
|
||||
showtickets.o: ../../db/dbconn.h ../../db/dbtextstream.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: ../../core/httpsimpleparser.h ../../core/log.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
|
||||
ticketconf.o: 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: ../../db/dbbase.h ../../db/dbconn.h ../../db/dbtextstream.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: ../../core/misc.h
|
||||
|
||||
@@ -53,7 +53,7 @@ return true;
|
||||
|
||||
void CreateTicket::AddTicket(Ticket & ticket, Item & item)
|
||||
{
|
||||
ticket.file_id = item.id;
|
||||
ticket.file_id = item.id;
|
||||
cur->request->status = tdb->AddTicket(ticket);
|
||||
|
||||
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 )
|
||||
{
|
||||
log << log2 << "CreateTicket: added a new ticket" << logend;
|
||||
RemoveTicket();
|
||||
RemoveTmpTicket();
|
||||
system->RedirectTo(item);
|
||||
}
|
||||
else
|
||||
@@ -103,13 +103,14 @@ void CreateTicket::Submit(Ticket & ticket, Item & item)
|
||||
|
||||
|
||||
|
||||
void CreateTicket::RemoveTicket()
|
||||
void CreateTicket::RemoveTmpTicket()
|
||||
{
|
||||
SessionData * session_data = reinterpret_cast<SessionData*>(
|
||||
cur->session->plugin_data.Get(ticket_info->plugin_id) );
|
||||
|
||||
long dir_id = cur->request->dir_tab.back()->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()
|
||||
{
|
||||
@@ -135,8 +147,9 @@ void CreateTicket::MakePost()
|
||||
Ticket & ticket = PrepareTicket();
|
||||
Item & item = cur->request->item;
|
||||
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);
|
||||
|
||||
if( !cur->request->IsPostVar(L"fileuploadsubmit") )
|
||||
|
||||
@@ -36,8 +36,9 @@ private:
|
||||
|
||||
void AddTicket(Ticket & ticket, Item & item);
|
||||
void Submit(Ticket & ticket, Item & item);
|
||||
void RemoveTicket();
|
||||
void RemoveTmpTicket();
|
||||
Ticket & PrepareTicket();
|
||||
std::vector<long> & PrepareFileMap();
|
||||
|
||||
TDb * tdb;
|
||||
TicketInfo * ticket_info;
|
||||
|
||||
@@ -91,7 +91,7 @@ void EditTicket::Submit(Ticket & ticket, Item & item)
|
||||
if( cur->request->status == WINIX_ERR_OK )
|
||||
{
|
||||
log << log2 << "EditTicket: ticket modified" << logend;
|
||||
RemoveTicket();
|
||||
RemoveTmpTicket();
|
||||
system->RedirectTo(item);
|
||||
}
|
||||
else
|
||||
@@ -104,13 +104,13 @@ void EditTicket::Submit(Ticket & ticket, Item & item)
|
||||
|
||||
|
||||
|
||||
void EditTicket::RemoveTicket()
|
||||
void EditTicket::RemoveTmpTicket()
|
||||
{
|
||||
SessionData * session_data = reinterpret_cast<SessionData*>(
|
||||
cur->session->plugin_data.Get(ticket_info->plugin_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);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
void RemoveTicket();
|
||||
void RemoveTmpTicket();
|
||||
Ticket & PrepareTicket();
|
||||
std::vector<long> & PrepareFileMap();
|
||||
std::wstring old_url;
|
||||
|
||||
@@ -88,7 +88,7 @@ void ProcessRequest(PluginInfo & info)
|
||||
|
||||
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)
|
||||
{
|
||||
SessionData * p = new SessionData();
|
||||
|
||||
p->fun_rm = &info.functions->fun_rm;
|
||||
info.cur->session->plugin_data.Assign(p);
|
||||
log << log4 << "Ticket: created ticket plugin data: " << (void*)p << logend;
|
||||
}
|
||||
@@ -115,14 +117,7 @@ void CreateSession(PluginInfo & info)
|
||||
void RemoveSession(PluginInfo & info)
|
||||
{
|
||||
delete info.plugin_data_base;
|
||||
log << log4 << "Ticket: removed ticket plugin date: " << (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;
|
||||
log << log4 << "Ticket: removed ticket plugin data: " << (void*)info.plugin_data_base << logend;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +144,6 @@ using namespace Ticket;
|
||||
plugin.Assign(WINIX_NOTIFY_ADD_TEMPLATE, AddNotifyTemplate);
|
||||
plugin.Assign(WINIX_SESSION_CREATED, CreateSession);
|
||||
plugin.Assign(WINIX_SESSION_REMOVE, RemoveSession);
|
||||
plugin.Assign(WINIX_PL_THREAD_CAN_USE_REPLY, CanUseReply);
|
||||
|
||||
tdb.SetConn(info.db->GetConn());
|
||||
tdb.LogQueries(info.config->log_db_query);
|
||||
|
||||
@@ -13,6 +13,39 @@
|
||||
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)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <map>
|
||||
#include "core/plugindata.h"
|
||||
#include "ticket.h"
|
||||
#include "functions/rm.h"
|
||||
|
||||
|
||||
namespace Ticket
|
||||
@@ -23,9 +24,14 @@ namespace Ticket
|
||||
|
||||
struct SessionData : public PluginDataBase
|
||||
{
|
||||
SessionData();
|
||||
~SessionData();
|
||||
|
||||
|
||||
typedef std::map<long, Ticket> TicketMap;
|
||||
typedef std::map<long, std::vector<long> > FileMap;
|
||||
|
||||
|
||||
// temporary tickets for 'createticket' function
|
||||
// <parent_dir_id, Ticket>
|
||||
TicketMap create_ticket_map;
|
||||
@@ -34,8 +40,14 @@ struct SessionData : public PluginDataBase
|
||||
// <file_id, Ticket>
|
||||
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
|
||||
// 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;
|
||||
|
||||
|
||||
@@ -44,6 +56,10 @@ struct SessionData : public PluginDataBase
|
||||
|
||||
std::vector<long> & GetFileTab(long id, FileMap & file_map);
|
||||
|
||||
// for deleting new_file_map files
|
||||
Fun::Rm * fun_rm;
|
||||
|
||||
void RemoveFileMap(FileMap & file_map);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ bool ShowTickets::Sort::operator()(const Item * item1, const Item * item2)
|
||||
time_t time1 = Time(tm1);
|
||||
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()
|
||||
{
|
||||
@@ -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()
|
||||
{
|
||||
ticket_info->Clear();
|
||||
|
||||
@@ -38,9 +38,9 @@ private:
|
||||
std::vector<long> file_id_tab;
|
||||
|
||||
void ReadFiles();
|
||||
void ReadTickets();
|
||||
void CreatePointers();
|
||||
void SortPointers();
|
||||
void ReadTickets();
|
||||
|
||||
struct Sort
|
||||
{
|
||||
|
||||
@@ -71,6 +71,8 @@ Error TDb::GetTicket(long file_id, Ticket & ticket)
|
||||
int cintvalue = AssertColumn(r, "int_value");
|
||||
int cstrvalue = AssertColumn(r, "str_value");
|
||||
|
||||
// !! mozna dodac uzycie ticket.par_tab.reserve()
|
||||
|
||||
for(int i=0 ; i<rows ; ++i)
|
||||
{
|
||||
par.param = AssertValueInt(r, i, cparam);
|
||||
|
||||
@@ -49,6 +49,7 @@ return percent;
|
||||
|
||||
|
||||
// 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)
|
||||
{
|
||||
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 )
|
||||
{
|
||||
while( o2 > 0 && ticket.par_tab[o2-1].param == conf_item.id )
|
||||
--o2;
|
||||
|
||||
ticket_par_index = o2;
|
||||
return true;
|
||||
}
|
||||
@@ -81,7 +85,12 @@ bool find_ticket_value(const TicketConf::TicketItem & conf_item, const Ticket &
|
||||
ticket_par_index = (o1 + o2) / 2;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if( ticket.par_tab[ticket_par_index].param < conf_item.id )
|
||||
o1 = ticket_par_index;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace Ticket
|
||||
@@ -27,7 +28,6 @@ struct Ticket
|
||||
|
||||
void Clear()
|
||||
{
|
||||
// !! what about file_id?
|
||||
param = 0;
|
||||
int_value = 0;
|
||||
str_value.clear();
|
||||
@@ -52,6 +52,19 @@ struct Ticket
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -302,6 +302,7 @@ bool add = false;
|
||||
if( cur->request->status == WINIX_ERR_OK )
|
||||
{
|
||||
add = true;
|
||||
par.int_value = file.id;
|
||||
system->MakePath(file, par.str_value);
|
||||
|
||||
if( file_map )
|
||||
@@ -335,6 +336,8 @@ bool exists = false;
|
||||
|
||||
ticket_param.Clear();
|
||||
|
||||
log << log1 << "szukamy dla param_id: " << param_id << logend;
|
||||
|
||||
for(size_t i=0 ; i<cur_conf->tab.size() ; ++i)
|
||||
{
|
||||
if( param_id == cur_conf->tab[i].id )
|
||||
@@ -420,10 +423,27 @@ PostFileTab::iterator i2;
|
||||
if( IsSubString(config->ticket_form_prefix, i2->first) )
|
||||
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
|
||||
|
||||
@@ -93,6 +93,8 @@ public:
|
||||
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 RemoveTicket(long file_id);
|
||||
|
||||
private:
|
||||
|
||||
Db * db;
|
||||
@@ -119,6 +121,9 @@ private:
|
||||
const TicketConf cur_conf_empty;
|
||||
const Ticket ticket_empty;
|
||||
|
||||
// for removing a ticket
|
||||
Ticket rm_ticket;
|
||||
|
||||
bool GetConfContent(const std::wstring & path);
|
||||
bool ParseTicketConf(long mount_dir_id, const std::wstring & path);
|
||||
void ReadTicketConf(Mounts & mounts, bool skip_existing_configs);
|
||||
|
||||
Reference in New Issue
Block a user