Item class has been moved to a new directory 'models', a new class has been added: ItemContent
and same fields from Item were moved to ItemContent Item - id - parent_id - type (file, dir, symlink) - url - subject - template (html template) - sort_index - content_id ItemContent - id - ref -> references (renamed) - user_id - modification_user_id - group_id - privileges - date_creation - date_modification - guest_name - link_to - link_redirect - file_path - file_fs - file_type - file_size - has_thumb -> file_has_thumb (renamed) - hash -> file_hash (renamed) - hash_type -> file_hash_type (renamed) - content -> content_raw (renamed) - content_type -> content_raw_type (renamed) - content_parsed - content_parsed_type - meta - ameta -> meta_admin (renamed) - modify_index (removed) WIP: #4
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* Copyright (c) 2008-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -62,7 +62,7 @@ bool Mv::HasAccess()
|
||||
{
|
||||
if( cur->request->is_item )
|
||||
{
|
||||
if( !system->CanRemoveRenameChild(*cur->request->dir_tab.back(), cur->request->item.user_id) )
|
||||
if( !system->CanRemoveRenameChild(*cur->request->dir_tab.back(), cur->request->item.item_content.user_id) )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -102,7 +102,7 @@ bool Mv::CheckAccessFromToDir(const Item & dir, bool only_content)
|
||||
// ops, there is no a parent dir
|
||||
return false;
|
||||
|
||||
if( !system->CanRemoveRenameChild(*last_but_one_dir, dir.user_id) )
|
||||
if( !system->CanRemoveRenameChild(*last_but_one_dir, dir.item_content.user_id) )
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -115,26 +115,26 @@ return true;
|
||||
// !! IMPROVE ME: may a better name?
|
||||
void Mv::Prepare()
|
||||
{
|
||||
content_dir_iq.SetAll(false, false);
|
||||
content_dir_iq.sel_parent_id = true;
|
||||
content_dir_iq.sel_type = true;
|
||||
content_dir_iq.sel_url = true;
|
||||
content_dir_iq.sel_file = true;
|
||||
content_dir_iq.sel_user_id = true;
|
||||
content_dir_iq.sel_group_id = true;
|
||||
content_dir_iq.sel_privileges = true;
|
||||
content_dir_iq.sel_meta = true;
|
||||
|
||||
files_iq.SetAll(false, false);
|
||||
files_iq.sel_parent_id = true;
|
||||
files_iq.sel_type = true;
|
||||
files_iq.sel_url = true;
|
||||
files_iq.sel_file = true;
|
||||
files_iq.sel_user_id = true;
|
||||
files_iq.sel_group_id = true;
|
||||
files_iq.sel_privileges = true;
|
||||
files_iq.sel_meta = true;
|
||||
files_iq.WhereType(Item::dir, false);
|
||||
// content_dir_iq.SetAll(false, false);
|
||||
// content_dir_iq.sel_parent_id = true;
|
||||
// content_dir_iq.sel_type = true;
|
||||
// content_dir_iq.sel_url = true;
|
||||
// content_dir_iq.sel_file = true;
|
||||
// content_dir_iq.sel_user_id = true;
|
||||
// content_dir_iq.sel_group_id = true;
|
||||
// content_dir_iq.sel_privileges = true;
|
||||
// content_dir_iq.sel_meta = true;
|
||||
//
|
||||
// files_iq.SetAll(false, false);
|
||||
// files_iq.sel_parent_id = true;
|
||||
// files_iq.sel_type = true;
|
||||
// files_iq.sel_url = true;
|
||||
// files_iq.sel_file = true;
|
||||
// files_iq.sel_user_id = true;
|
||||
// files_iq.sel_group_id = true;
|
||||
// files_iq.sel_privileges = true;
|
||||
// files_iq.sel_meta = true;
|
||||
// files_iq.WhereType(Item::dir, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,17 @@ bool Mv::ParseDirCheckLastName()
|
||||
}
|
||||
else
|
||||
{
|
||||
if( db->GetItem(out_dir_tab.back()->id, out_filename, out_item) == WINIX_ERR_OK )
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
|
||||
out_item = finder.
|
||||
select().
|
||||
where().
|
||||
eq(L"parent_id", out_dir_tab.back()->id).
|
||||
eq(L"url", out_filename).
|
||||
get();
|
||||
|
||||
//if( db->GetItem(out_dir_tab.back()->id, out_filename, out_item) == WINIX_ERR_OK )
|
||||
if( out_item.found() )
|
||||
{
|
||||
out_has_file = true;
|
||||
out_filename.clear();
|
||||
@@ -219,7 +229,7 @@ bool Mv::CanRemoveRenameChild(const Item & child)
|
||||
{
|
||||
Item * parent_dir = system->dirs.GetDir(child.parent_id);
|
||||
|
||||
if( !parent_dir || !system->CanRemoveRenameChild(*parent_dir, child.user_id) )
|
||||
if( !parent_dir || !system->CanRemoveRenameChild(*parent_dir, child.item_content.user_id) )
|
||||
{
|
||||
log << log1 << "Mv: permission denied to: " << child.url << logend;
|
||||
slog << logerror << T("mv_permission_denied_to") << ": " << child.url << logend;
|
||||
@@ -255,15 +265,16 @@ bool Mv::MoveStaticFile(const std::wstring & from, const std::wstring & to)
|
||||
|
||||
void Mv::MoveStaticFile(Item & item)
|
||||
{
|
||||
bool res1, res2, res3, res4, res5;
|
||||
bool ok = true;
|
||||
//bool res1, res2, res3, res4, res5;
|
||||
|
||||
res1 = system->MakeFilePath(item, old_static_path, false);
|
||||
res2 = !item.has_thumb || system->MakeFilePath(item, old_static_thumb_path, true);
|
||||
res3 = system->CreateNewFile(item);
|
||||
res4 = system->MakeFilePath(item, new_static_path, false, true, config->upload_dirs_chmod);
|
||||
res5 = !item.has_thumb || system->MakeFilePath(item, new_static_thumb_path, true, true, config->upload_dirs_chmod);
|
||||
ok = ok && system->MakeFilePath(item, old_static_path, false);
|
||||
ok = ok && (!item.item_content.file_has_thumb || system->MakeFilePath(item, old_static_thumb_path, true));
|
||||
ok = ok && system->CreateNewFile(item);
|
||||
ok = ok && system->MakeFilePath(item, new_static_path, false, true, config->upload_dirs_chmod);
|
||||
ok = ok && (!item.item_content.file_has_thumb || system->MakeFilePath(item, new_static_thumb_path, true, true, config->upload_dirs_chmod));
|
||||
|
||||
if( !res1 || !res2 || !res3 || !res4 || !res5 )
|
||||
if( !ok )
|
||||
{
|
||||
log << log1 << "Mv: cannot create a static path" << logend;
|
||||
slog << logerror << T("internal_error") << logend;
|
||||
@@ -272,14 +283,15 @@ bool res1, res2, res3, res4, res5;
|
||||
|
||||
if( MoveStaticFile(old_static_path, new_static_path) )
|
||||
{
|
||||
if( db->EditFileById(item, item.id) != WINIX_ERR_OK )
|
||||
//if( db->EditFileById(item, item.id) != WINIX_ERR_OK )
|
||||
if( !item.update(false, true) )
|
||||
{
|
||||
log << log1 << "Mv: cannot move static file (database problem)" << logend;
|
||||
slog << logerror << T("internal_error") << logend;
|
||||
return;
|
||||
}
|
||||
|
||||
if( item.has_thumb )
|
||||
if( item.item_content.file_has_thumb )
|
||||
MoveStaticFile(old_static_thumb_path, new_static_thumb_path);
|
||||
}
|
||||
}
|
||||
@@ -294,8 +306,17 @@ void Mv::MoveFilesPrepareTreeGo(const Item & src_dir)
|
||||
for( ; i != system->dirs.ParentEnd() ; i = system->dirs.NextChild(i) )
|
||||
MoveFilesPrepareTreeGo(*(i->second));
|
||||
|
||||
files_iq.WhereParentId(src_dir.id);
|
||||
db->GetItems(files_item_tab, files_iq);
|
||||
//files_iq.WhereParentId(src_dir.id);
|
||||
//db->GetItems(files_item_tab, files_iq);
|
||||
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
|
||||
finder.
|
||||
select().
|
||||
where().
|
||||
eq(L"parent_id", src_dir.id).
|
||||
neq(L"type", static_cast<int>(Item::dir)).
|
||||
get_vector(files_item_tab);
|
||||
|
||||
for(size_t i=0 ; i<files_item_tab.size() ; ++i)
|
||||
plugin->Call(WINIX_FILE_PREPARE_TO_MOVE, &files_item_tab[i]);
|
||||
@@ -324,12 +345,21 @@ void Mv::MoveFilesTree(const Item & dir)
|
||||
for( ; i != system->dirs.ParentEnd() ; i = system->dirs.NextChild(i) )
|
||||
MoveFilesTree(*(i->second));
|
||||
|
||||
files_iq.WhereParentId(dir.id);
|
||||
db->GetItems(files_item_tab, files_iq);
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
|
||||
finder.
|
||||
select().
|
||||
where().
|
||||
eq(L"parent_id", dir.id).
|
||||
neq(L"type", static_cast<int>(Item::dir)).
|
||||
get_vector(files_item_tab);
|
||||
|
||||
//files_iq.WhereParentId(dir.id);
|
||||
//db->GetItems(files_item_tab, files_iq);
|
||||
|
||||
for(size_t i=0 ; i<files_item_tab.size() ; ++i)
|
||||
{
|
||||
if( files_item_tab[i].file_type != WINIX_ITEM_FILETYPE_NONE )
|
||||
if( files_item_tab[i].item_content.file_type != WINIX_ITEM_FILETYPE_NONE )
|
||||
{
|
||||
plugin->Call(WINIX_FILE_PREPARE_TO_MOVE, &files_item_tab[i]);
|
||||
MoveStaticFile(files_item_tab[i]);
|
||||
@@ -370,9 +400,8 @@ bool Mv::MoveDir(Item & src_dir, std::vector<Item*> & dst_dir_tab, const std::ws
|
||||
functions->PrepareUrl(src_dir);
|
||||
}
|
||||
|
||||
Error status = db->EditParentUrlById(src_dir, src_dir.id);
|
||||
|
||||
if( status == WINIX_ERR_OK )
|
||||
//Error status = db->EditParentUrlById(src_dir, src_dir.id);
|
||||
if( src_dir.update(true, false) )
|
||||
{
|
||||
log << log3 << "Mv: directory: " << old_url << " was moved to: ";
|
||||
system->dirs.LogDir(dst_dir_tab);
|
||||
@@ -499,9 +528,9 @@ bool Mv::MoveFileOrSymlink(Item & src_file, std::vector<Item*> & dst_dir_tab, co
|
||||
}
|
||||
|
||||
src_file.parent_id = dst_dir_tab.back()->id;
|
||||
Error status = db->EditParentUrlById(src_file, src_file.id);
|
||||
|
||||
if( status == WINIX_ERR_OK )
|
||||
//Error status = db->EditParentUrlById(src_file, src_file.id);
|
||||
if( src_file.update(true, false) )
|
||||
{
|
||||
if( src_file.type == Item::file )
|
||||
log << log3 << "Mv: file: ";
|
||||
@@ -512,7 +541,7 @@ bool Mv::MoveFileOrSymlink(Item & src_file, std::vector<Item*> & dst_dir_tab, co
|
||||
system->dirs.LogDir(dst_dir_tab);
|
||||
log << src_file.url << logend;
|
||||
|
||||
if( src_file.file_type != WINIX_ITEM_FILETYPE_NONE )
|
||||
if( src_file.item_content.file_type != WINIX_ITEM_FILETYPE_NONE )
|
||||
MoveStaticFile(src_file);
|
||||
|
||||
plugin->Call(WINIX_FILE_MOVED, &src_file);
|
||||
@@ -604,13 +633,22 @@ bool Mv::MoveFileOrSymlink2(Item & src_file, const std::wstring & dst_path, bool
|
||||
// private
|
||||
void Mv::MoveAllFilesFromDir(Item & src_dir, std::vector<Item*> & dst_dir_tab, bool check_access)
|
||||
{
|
||||
content_dir_iq.WhereParentId(src_dir.id);
|
||||
db->GetItems(item_tab, content_dir_iq);
|
||||
// content_dir_iq.WhereParentId(src_dir.id);
|
||||
// db->GetItems(item_tab, content_dir_iq);
|
||||
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
|
||||
finder.
|
||||
select().
|
||||
where().
|
||||
eq(L"parent_id", src_dir.id).
|
||||
get_vector(item_tab);
|
||||
|
||||
out_filename.clear();
|
||||
|
||||
for(size_t i=0 ; i<item_tab.size() ; ++i)
|
||||
{
|
||||
if( check_access && !system->CanRemoveRenameChild(src_dir, item_tab[i].user_id) )
|
||||
if( check_access && !system->CanRemoveRenameChild(src_dir, item_tab[i].item_content.user_id) )
|
||||
{
|
||||
log << log1 << "Mv: permission denied to: " << src_dir.url << logend;
|
||||
slog << logerror << T("mv_permission_denied_to") << ": " << src_dir.url << logend;
|
||||
|
||||
Reference in New Issue
Block a user