fixed: plugin ticket: when a session expires all files from editticket were removed

it should be removed only those new added


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@798 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2012-01-21 12:29:44 +00:00
parent 4311f06ade
commit c9931da5ba
11 changed files with 174 additions and 54 deletions

View File

@@ -7,6 +7,7 @@
*
*/
#include <algorithm>
#include "sessiondata.h"
@@ -19,59 +20,134 @@ SessionData::SessionData()
}
SessionData::~SessionData()
{
RemoveFiles(create_space_map);
RemoveFiles(edit_space_map);
Clear();
}
void SessionData::Clear()
{
RemoveFiles(create_space_map, false);
RemoveFiles(edit_space_map, true);
}
void SessionData::RemoveFiles(SessionData::SpaceMap & space_map)
void SessionData::RemoveFiles(SessionData::SpaceMap & space_map, bool only_stale_files)
{
SpaceMap::iterator i;
if( fun_rm )
{
for(i=space_map.begin() ; i!=space_map.end() ; ++i)
RemoveFiles(i->second);
{
if( only_stale_files )
RemoveAllStaleFiles(i->second.new_space, i->second.old_space);
else
RemoveAllFiles(i->second.new_space);
}
space_map.clear();
}
}
void SessionData::RemoveFiles(PT::Space & space)
void SessionData::RemoveAllFiles(PT::Space & new_space)
{
std::vector<long> new_file_tab;
BuildFileList(new_file_tab, new_space);
for(size_t i=0 ; i<new_file_tab.size() ; ++i)
fun_rm->RemoveItemById(new_file_tab[i]);
}
void SessionData::RemoveAllStaleFiles(PT::Space & new_space, PT::Space & old_space)
{
std::vector<long> new_file_tab;
std::vector<long> old_file_tab;
size_t n = 0;
size_t o = 0;
BuildFileList(new_file_tab, new_space);
BuildFileList(old_file_tab, old_space);
std::sort(new_file_tab.begin(), new_file_tab.end());
std::sort(old_file_tab.begin(), old_file_tab.end());
// removes only those items present on new_file_tab
// but not existing on old_space_tab
while( n < new_file_tab.size() && o < old_file_tab.size() )
{
if( new_file_tab[n] < old_file_tab[o] )
{
fun_rm->RemoveItemById(new_file_tab[n]);
n += 1;
}
else
if( new_file_tab[n] == old_file_tab[o] )
{
n += 1;
o += 1;
}
else
{
o += 1;
}
}
while( n < new_file_tab.size() )
{
fun_rm->RemoveItemById(new_file_tab[n]);
n += 1;
}
}
void SessionData::BuildFileList(std::vector<long> & file_tab, PT::Space & space)
{
file_tab.clear();
for(size_t i=0 ; i<space.spaces.size() ; ++i)
{
PT::Space & sp = *space.spaces[i];
if( sp.name == L"param" )
CheckFile(file_tab, sp);
}
}
void SessionData::CheckFile(std::vector<long> & file_tab, PT::Space & space)
{
for(size_t i=0 ; i<space.spaces.size() ; ++i)
{
PT::Space & subsp = *space.spaces[i];
if( subsp.name == L"file" )
{
// !! wywalic to do osobnej metody
for(size_t a=0 ; a<sp.spaces.size() ; ++a)
std::wstring * file_id_str = subsp.GetValue(L"itemid");
if( file_id_str )
{
PT::Space & subsp = *sp.spaces[a];
if( subsp.name == L"file" )
{
std::wstring * file_id_str = subsp.GetValue(L"itemid");
if( file_id_str )
{
long file_id = Tol(*file_id_str);
fun_rm->RemoveItemById(file_id);
}
}
long file_id = Tol(*file_id_str);
file_tab.push_back(file_id);
}
}
}
}
Ticket & SessionData::GetTicket(long id, SessionData::TicketMap & ticket_map, bool * is_new)
{
std::pair<TicketMap::iterator, bool> res = ticket_map.insert( std::make_pair(id, Ticket()) );
@@ -84,17 +160,27 @@ return res.first->second;
PT::Space & SessionData::GetSpace(long id, SpaceMap & space_map, bool * is_new)
PT::Space & SessionData::GetOldSpace(long id, SpaceMap & space_map, bool * is_new)
{
std::pair<SpaceMap::iterator, bool> res = space_map.insert( std::make_pair(id, PT::Space()) );
std::pair<SpaceMap::iterator, bool> res = space_map.insert( std::make_pair(id, SpacePair()) );
if( is_new )
*is_new = res.second;
return res.first->second;
return res.first->second.old_space;
}
PT::Space & SessionData::GetNewSpace(long id, SpaceMap & space_map, bool * is_new)
{
std::pair<SpaceMap::iterator, bool> res = space_map.insert( std::make_pair(id, SpacePair()) );
if( is_new )
*is_new = res.second;
return res.first->second.new_space;
}
} // namespace