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:
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o crypt.o dircontainer.o dirs.o filelog.o groups.o htmlfilter.o httpsimpleparser.o image.o ipbancontainer.o item.o job.o lastcontainer.o loadavg.o lock.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o run.o session.o sessioncontainer.o sessionidmanager.o sessionmanager.o sessionparser.o slog.o synchro.o system.o threadmanager.o timezone.o timezones.o user.o users.o winixbase.o winixmodel.o winixrequest.o winixsystem.o
|
||||
o = acceptbaseparser.o app.o basethread.o bbcodeparser.o compress.o config.o crypt.o dircontainer.o dirs.o filelog.o groups.o htmlfilter.o httpsimpleparser.o image.o ipbancontainer.o job.o lastcontainer.o loadavg.o lock.o log.o misc.o mount.o mountparser.o mounts.o plugin.o plugindata.o postmultiparser.o rebus.o request.o run.o session.o sessioncontainer.o sessionidmanager.o sessionmanager.o sessionparser.o slog.o synchro.o system.o threadmanager.o timezone.o timezones.o user.o users.o winixbase.o winixmodel.o winixrequest.o winixsystem.o
|
||||
@@ -284,6 +284,14 @@ bool App::Init()
|
||||
model_connector.set_db_connector(postgresql_connector);
|
||||
//model_connector.set_doc_connector(doc_html_connector);
|
||||
|
||||
// temporary
|
||||
Item item_temp;
|
||||
item_temp.set_connector(model_connector);
|
||||
item_temp.do_migration(&model_connector);
|
||||
//std::exit(0);
|
||||
// -----------
|
||||
|
||||
|
||||
db_conn.SetConnParam(config.db_database, config.db_user, config.db_pass);
|
||||
db_conn.WaitForConnection();
|
||||
db.PostgreSQLsmallerThan10(config.db_postgresql_smaller_than_10);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* Copyright (c) 2008-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -37,8 +37,8 @@
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include "item.h"
|
||||
#include "winixbase.h"
|
||||
#include "models/item.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
|
||||
@@ -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
|
||||
@@ -76,7 +76,7 @@ void Dirs::Clear()
|
||||
bool Dirs::HasReadExecAccessForRoot(const Item & item)
|
||||
{
|
||||
// there must be at least one 'x' (for the root)
|
||||
return (item.privileges & 01111) != 0;
|
||||
return (item.item_content.privileges & 01111) != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,28 +88,33 @@ void Dirs::CheckRootDir()
|
||||
{
|
||||
if( !HasReadExecAccessForRoot(*i) )
|
||||
{
|
||||
i->privileges = 07555;
|
||||
i->item_content.privileges = 07555;
|
||||
log << log1 << "Dirs: there is no access for a root (admin) to the root dir, setting 07555 for the root directory" << logend;
|
||||
db->EditPrivById(*i, i->id);
|
||||
i->update(false, false);
|
||||
//db->EditPrivById(*i, i->id);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
log << log1 << "Dirs: there is no a root directory in the database (creating one)" << logend;
|
||||
|
||||
Item root;
|
||||
root.set_connector(model_connector);
|
||||
|
||||
root.type = Item::dir;
|
||||
root.parent_id = -1;
|
||||
root.user_id = -1;
|
||||
root.group_id = -1;
|
||||
root.privileges = 07555;
|
||||
root.item_content.user_id = -1;
|
||||
root.item_content.group_id = -1;
|
||||
root.item_content.privileges = 07555;
|
||||
|
||||
// !! upewnic sie ze baza nie zmieni url (gdyby wczesniej juz byl w bazie pusty url)
|
||||
// !! zrobic jakis wyjatek do wprowadzania roota?
|
||||
if( db->AddItem(root) == WINIX_ERR_OK )
|
||||
// if( db->AddItem(root) == WINIX_ERR_OK )
|
||||
// {
|
||||
// dir_tab.PushBack(root);
|
||||
// }
|
||||
if( root.insert() )
|
||||
{
|
||||
dir_tab.PushBack(root);
|
||||
}
|
||||
@@ -122,7 +127,15 @@ void Dirs::ReadDirs()
|
||||
{
|
||||
Clear();
|
||||
|
||||
db->GetDirs(dir_tab);
|
||||
//db->GetDirs(dir_tab);
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
std::list<Item> all_dirs = finder.select().where().eq(L"type", static_cast<int>(Item::Type::dir)).get_list();
|
||||
|
||||
for(Item & item : all_dirs)
|
||||
{
|
||||
dir_tab.PushBack(item);
|
||||
}
|
||||
|
||||
CheckRootDir();
|
||||
dir_tab.FindSpecialFolders();
|
||||
}
|
||||
@@ -723,7 +736,7 @@ bool Dirs::DelDir(long dir_id)
|
||||
}
|
||||
|
||||
|
||||
Error Dirs::AddDirectory(Item & item, bool add_to_dir_tab, Item ** pdir, int notify_code)
|
||||
bool Dirs::AddDirectory(Item & item, bool add_to_dir_tab, Item ** pdir, int notify_code)
|
||||
{
|
||||
if( pdir )
|
||||
*pdir = 0;
|
||||
@@ -731,9 +744,11 @@ Error Dirs::AddDirectory(Item & item, bool add_to_dir_tab, Item ** pdir, int not
|
||||
if( item.type != Item::dir )
|
||||
return WINIX_ERR_DIR_EXPECTED;
|
||||
|
||||
Error status = db->AddItem(item);
|
||||
//Error status = db->AddItem(item);
|
||||
//item.set_connector(model_connector);
|
||||
bool status = item.insert();
|
||||
|
||||
if( status == WINIX_ERR_OK )
|
||||
if( status )
|
||||
{
|
||||
Item * d = AddDir(item);
|
||||
|
||||
@@ -764,10 +779,11 @@ Item * Dirs::CreateVarDir()
|
||||
|
||||
if( root )
|
||||
{
|
||||
v.set_connector(root->get_connector());
|
||||
v.parent_id = root->id;
|
||||
v.user_id = root->user_id;
|
||||
v.group_id = root->group_id;
|
||||
v.privileges = root->privileges;
|
||||
v.item_content.user_id = root->item_content.user_id;
|
||||
v.item_content.group_id = root->item_content.group_id;
|
||||
v.item_content.privileges = root->item_content.privileges;
|
||||
v.subject = L"var";
|
||||
v.url = L"var";
|
||||
v.type = Item::dir;
|
||||
|
||||
@@ -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
|
||||
@@ -39,12 +39,11 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "item.h"
|
||||
#include "dircontainer.h"
|
||||
#include "db/db.h"
|
||||
#include "request.h"
|
||||
#include "winixmodel.h"
|
||||
#include "models/item.h"
|
||||
|
||||
|
||||
|
||||
@@ -115,7 +114,7 @@ public:
|
||||
Item * CreateVarDir();
|
||||
|
||||
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir() /AddDir() juz istnieje przeciez?/
|
||||
Error AddDirectory(Item & item, bool add_to_dir_tab = false, Item ** pdir = 0, int notify_code = 0);
|
||||
bool AddDirectory(Item & item, bool add_to_dir_tab = false, Item ** pdir = 0, int notify_code = 0);
|
||||
|
||||
// returns how many levels of directories there are
|
||||
// "/" -> 0 (root dir)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -377,7 +377,7 @@ bool Image::CreateInputFileName()
|
||||
{
|
||||
bool thumb = (item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB);
|
||||
|
||||
if( thumb && !file_work.has_thumb )
|
||||
if( thumb && !file_work.item_content.file_has_thumb )
|
||||
{
|
||||
log << log1 << "Image: file id: " << file_work.id << ", url: " << file_work.url
|
||||
<< " doesn't have a thumbnail yet (skipping)" << logend;
|
||||
@@ -414,11 +414,19 @@ bool Image::CreateCommand()
|
||||
{
|
||||
class Lock lock_object(synchro);
|
||||
|
||||
iq.SetAll(true, false);
|
||||
iq.WhereId(item_work.file_id);
|
||||
// iq.SetAll(true, false);
|
||||
// iq.WhereId(item_work.file_id);
|
||||
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
|
||||
{
|
||||
// IMPROVEME we need a seperate model_connector for this thread
|
||||
Lock();
|
||||
file_work = finder.select().where().eq(L"id", item_work.file_id).get();
|
||||
}
|
||||
|
||||
// the file could have been changed especially when there is a long queue of files
|
||||
if( db->GetItem(file_work, iq) != WINIX_ERR_OK )
|
||||
if( !file_work.found() )
|
||||
return false;
|
||||
|
||||
if( !CreateInputFileName() )
|
||||
@@ -483,10 +491,16 @@ void Image::ImageSavedCorrectly()
|
||||
{
|
||||
if( item_work.type == WINIX_IMAGE_TYPE_CREATE_THUMB )
|
||||
{
|
||||
if( !file_work.has_thumb )
|
||||
if( !file_work.item_content.file_has_thumb )
|
||||
{
|
||||
file_work.has_thumb = true;
|
||||
db->EditHasThumbById(true, file_work.id);
|
||||
file_work.item_content.file_has_thumb = true;
|
||||
|
||||
{
|
||||
// IMPROVEME we need a separate model_connector for this thread
|
||||
Lock();
|
||||
file_work.update(false, false);
|
||||
//db->EditHasThumbById(true, file_work.id);
|
||||
}
|
||||
}
|
||||
|
||||
log << log3 << "Image: generated a thumbnail: " << dst_path << logend;
|
||||
@@ -528,11 +542,23 @@ void Image::SaveImage()
|
||||
class Lock lock_object(synchro);
|
||||
|
||||
// the file could have been changed especially when creating the image lasted too long
|
||||
iq.SetAll(true, false);
|
||||
iq.WhereId(item_work.file_id);
|
||||
//iq.SetAll(true, false);
|
||||
//iq.WhereId(item_work.file_id);
|
||||
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
|
||||
if( db->GetItem(file_work, iq) == WINIX_ERR_OK )
|
||||
{
|
||||
// IMPROVEME we need a seperate model_connector for this thread
|
||||
Lock();
|
||||
file_work = finder.select().where().eq(L"id", item_work.file_id).get();
|
||||
}
|
||||
|
||||
// the file could have been changed especially when there is a long queue of files
|
||||
if( !file_work.found() )
|
||||
return;
|
||||
|
||||
//if( db->GetItem(file_work, iq) == WINIX_ERR_OK )
|
||||
//{
|
||||
bool thumb = (item_work.type == WINIX_IMAGE_TYPE_CREATE_THUMB ||
|
||||
item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB ||
|
||||
item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB );
|
||||
@@ -558,7 +584,7 @@ void Image::SaveImage()
|
||||
{
|
||||
log << log1 << "Image: cannot create a destination path" << logend;
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,8 +40,8 @@
|
||||
#include "basethread.h"
|
||||
#include "textstream.h"
|
||||
#include "db/db.h"
|
||||
#include "core/item.h"
|
||||
#include "core/config.h"
|
||||
#include "models/item.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -187,7 +187,6 @@ private:
|
||||
std::wstring src_path, dst_path;
|
||||
TextStream<std::string> command;
|
||||
TextStream<std::wstring> stream_tmp_path;
|
||||
DbItemQuery iq;
|
||||
std::string add_tempa;
|
||||
std::string input_file_name;
|
||||
std::string tmp_file_name;
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "item.h"
|
||||
#include "misc.h"
|
||||
#include "crypt.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
Item::Item()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
// !! IMPROVE ME
|
||||
// now we have Request::start_time and Request::start_date
|
||||
// we can somehow get the current time from the request
|
||||
// may setting the date should be completetly removed from here?
|
||||
void Item::SetDateToNow()
|
||||
{
|
||||
date_creation = std::time(0);
|
||||
date_modification = date_creation;
|
||||
}
|
||||
|
||||
|
||||
void Item::SetDateModifyToNow()
|
||||
{
|
||||
date_modification = std::time(0);
|
||||
}
|
||||
|
||||
|
||||
void Item::Clear()
|
||||
{
|
||||
id = -1;
|
||||
|
||||
user_id = -1;
|
||||
group_id = -1;
|
||||
privileges = 0;
|
||||
modification_user_id = -1;
|
||||
|
||||
guest_name.clear();
|
||||
|
||||
subject.clear();
|
||||
content.clear();
|
||||
modify_index = 0;
|
||||
url.clear();
|
||||
|
||||
content_type = ct_formatted_text;
|
||||
|
||||
type = none;
|
||||
parent_id = -1;
|
||||
|
||||
link_to.clear();
|
||||
link_redirect = false;
|
||||
|
||||
content_id = -1;
|
||||
ref = 1;
|
||||
|
||||
file_path.clear();
|
||||
file_fs = -1;
|
||||
file_type = WINIX_ITEM_FILETYPE_NONE;
|
||||
hash.clear();
|
||||
hash_type = WINIX_CRYPT_HASH_NONE;
|
||||
file_size = 0;
|
||||
has_thumb = false;
|
||||
|
||||
html_template.clear();
|
||||
sort_index = 0;
|
||||
meta.Clear();
|
||||
ameta.Clear();
|
||||
|
||||
SetDateToNow();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* we're using the HtmlFilter only for those contents
|
||||
*
|
||||
*/
|
||||
bool Item::CanContentBeHtmlFiltered(Item::ContentType ct)
|
||||
{
|
||||
return ct == ct_text || ct == ct_formatted_text || ct == ct_html || ct == ct_bbcode;
|
||||
}
|
||||
|
||||
bool Item::CanContentBeHtmlFiltered()
|
||||
{
|
||||
return CanContentBeHtmlFiltered(content_type);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2016, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_item
|
||||
#define headerfile_winix_core_item
|
||||
|
||||
#include <string>
|
||||
#include "space/space.h"
|
||||
#include "date/date.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
#define WINIX_ITEM_FILETYPE_NONE 0
|
||||
#define WINIX_ITEM_FILETYPE_IMAGE 1
|
||||
#define WINIX_ITEM_FILETYPE_DOCUMENT 2
|
||||
#define WINIX_ITEM_FILETYPE_VIDEO 3
|
||||
#define WINIX_ITEM_FILETYPE_UNKNOWN 10
|
||||
|
||||
|
||||
|
||||
|
||||
struct Item
|
||||
{
|
||||
long id;
|
||||
long parent_id;
|
||||
|
||||
|
||||
long user_id;
|
||||
long group_id;
|
||||
std::wstring guest_name; // used as a user name when user_id is equal -1
|
||||
|
||||
long modification_user_id; // who has modified the item last (not taken into account when checking permissions)
|
||||
|
||||
int privileges;
|
||||
|
||||
PT::Date date_creation;
|
||||
PT::Date date_modification;
|
||||
|
||||
std::wstring subject;
|
||||
std::wstring content;
|
||||
|
||||
std::wstring url;
|
||||
int modify_index;
|
||||
|
||||
enum ContentType
|
||||
{
|
||||
ct_text = 0,
|
||||
ct_formatted_text,
|
||||
ct_html,
|
||||
ct_bbcode,
|
||||
ct_other, // no auto-formatting is applied
|
||||
};
|
||||
|
||||
ContentType content_type;
|
||||
|
||||
|
||||
|
||||
enum Type
|
||||
{
|
||||
dir = 0,
|
||||
file = 1,
|
||||
symlink = 2,
|
||||
|
||||
none = 1000
|
||||
};
|
||||
|
||||
|
||||
Type type;
|
||||
|
||||
|
||||
// used when type is symlink or to a directory too (function 'default')
|
||||
std::wstring link_to;
|
||||
int link_redirect; // !! IMPROVE ME should it be 'bool'?
|
||||
|
||||
|
||||
// static file (if exists)
|
||||
std::wstring file_path; // relative file path
|
||||
int file_fs; // file system type where the file was saved
|
||||
int file_type; // file type (none, image, doc, etc)
|
||||
bool has_thumb; // whether or not we have a thumbnail
|
||||
std::wstring hash; // file hash (md4, md5, ...)
|
||||
int hash_type; // hash type WINIX_CRYPT_HASH_* (see crypt.h)
|
||||
size_t file_size; // size of the file
|
||||
|
||||
std::wstring html_template;
|
||||
|
||||
|
||||
// sort index used when displaying a group of items
|
||||
int sort_index;
|
||||
|
||||
|
||||
// meta information
|
||||
PT::Space meta;
|
||||
PT::Space ameta;
|
||||
|
||||
|
||||
// methods
|
||||
Item();
|
||||
void SetDateToNow();
|
||||
void SetDateModifyToNow();
|
||||
void Clear();
|
||||
|
||||
|
||||
static bool CanContentBeHtmlFiltered(Item::ContentType ct);
|
||||
bool CanContentBeHtmlFiltered();
|
||||
|
||||
|
||||
private:
|
||||
// used by the database
|
||||
long content_id; // content id in 'content' table
|
||||
int ref; // content references
|
||||
|
||||
friend class Db;
|
||||
friend struct DbItemColumns;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -39,7 +39,6 @@
|
||||
#include <sstream>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
#include "item.h"
|
||||
#include "requesttypes.h"
|
||||
#include "date/date.h"
|
||||
#include "textstream/textstream.h"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2014, Tomasz Sowa
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,11 +40,10 @@
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "mount.h"
|
||||
#include "item.h"
|
||||
#include "dirs.h"
|
||||
#include "winixmodel.h"
|
||||
#include "models/item.h"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ void Mounts::ReadMounts(const std::wstring & mounts)
|
||||
|
||||
|
||||
// reading from /etc/fstab
|
||||
Error Mounts::ReadMounts()
|
||||
void Mounts::ReadMounts()
|
||||
{
|
||||
static std::wstring file = L"fstab";
|
||||
|
||||
@@ -242,27 +242,27 @@ Error Mounts::ReadMounts()
|
||||
if( !etc )
|
||||
{
|
||||
log << log1 << "M: there is no /etc directory" << logend;
|
||||
return WINIX_ERR_NO_ITEM;
|
||||
return;
|
||||
}
|
||||
|
||||
Item fstab;
|
||||
Error err = db->GetItem(etc->id, file, fstab);
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
Item fstab = finder.select().where().eq(L"parent_id", etc->id).eq(L"url", file).get();
|
||||
|
||||
if( err == WINIX_ERR_NO_ITEM )
|
||||
// Error err = db->GetItem(etc->id, file, fstab);
|
||||
|
||||
if( !fstab.found() )
|
||||
{
|
||||
log << log1 << "M: there is no /etc/fstab file" << logend;
|
||||
return err;
|
||||
return;
|
||||
}
|
||||
|
||||
if( err != WINIX_ERR_OK )
|
||||
{
|
||||
log << log1 << "M: cannot read /etc/fstab" << logend;
|
||||
return err;
|
||||
}
|
||||
// if( err != WINIX_ERR_OK )
|
||||
// {
|
||||
// log << log1 << "M: cannot read /etc/fstab" << logend;
|
||||
// return err;
|
||||
// }
|
||||
|
||||
ReadMounts(fstab.content);
|
||||
|
||||
return WINIX_ERR_OK;
|
||||
ReadMounts(fstab.item_content.content_raw);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
void CreateMounts();
|
||||
|
||||
void ReadMounts(const std::wstring & mounts);
|
||||
Error ReadMounts();
|
||||
void ReadMounts();
|
||||
|
||||
Mount * CalcCurMount();
|
||||
Mount * CalcMount(long dir_id);
|
||||
|
||||
@@ -69,6 +69,9 @@ void PluginInfo::set_dependency_for(WinixBase & winix_base)
|
||||
void PluginInfo::set_dependency_for(WinixModel * winix_model)
|
||||
{
|
||||
plugin->SetDependencyFor(winix_model);
|
||||
|
||||
//model_connector = winix_model->get_model_connector();
|
||||
// CHECKME what about model_connector here?
|
||||
}
|
||||
|
||||
void PluginInfo::set_dependency_for(WinixModel & winix_model)
|
||||
|
||||
@@ -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
|
||||
@@ -41,7 +41,7 @@
|
||||
#include "pluginmsg.h"
|
||||
#include "plugindata.h"
|
||||
#include "winixbase.h"
|
||||
|
||||
#include "modelconnector.h"
|
||||
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ struct Session;
|
||||
|
||||
|
||||
// move me to a different file
|
||||
// may it should be based on WinixModel?
|
||||
struct PluginInfo
|
||||
{
|
||||
// these variables are used for some purposes
|
||||
@@ -108,6 +109,7 @@ struct PluginInfo
|
||||
|
||||
Plugin * plugin;
|
||||
|
||||
morm::ModelConnector * model_connector;
|
||||
|
||||
// a session
|
||||
// some messages are sent in a session's context e.g. logging a user
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include "requesttypes.h"
|
||||
#include "item.h"
|
||||
#include "models/item.h"
|
||||
#include "error.h"
|
||||
#include "config.h"
|
||||
#include "textstream.h"
|
||||
|
||||
@@ -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
|
||||
@@ -39,7 +39,6 @@
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <map>
|
||||
#include "item.h"
|
||||
#include "error.h"
|
||||
#include "user.h"
|
||||
#include "plugindata.h"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2018, Tomasz Sowa
|
||||
* Copyright (c) 2010-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -337,14 +337,23 @@ void System::RedirectTo(long item_id, const wchar_t * postfix, bool use_reqtype)
|
||||
else
|
||||
{
|
||||
// item_id is pointing to a file
|
||||
DbItemQuery iq;
|
||||
// DbItemQuery iq;
|
||||
|
||||
iq.SetAllSel(false);
|
||||
iq.WhereId(item_id);
|
||||
iq.sel_parent_id = true;
|
||||
iq.sel_url = true;
|
||||
// iq.SetAllSel(false);
|
||||
// iq.WhereId(item_id);
|
||||
// iq.sel_parent_id = true;
|
||||
// iq.sel_url = true;
|
||||
|
||||
if( db->GetItem(item_temp, iq) == WINIX_ERR_OK )
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
|
||||
item_temp = finder.
|
||||
select().
|
||||
where().
|
||||
eq(L"id", item_id).
|
||||
get();
|
||||
|
||||
//if( db->GetItem(item_temp, iq) == WINIX_ERR_OK )
|
||||
if( item_temp.found() )
|
||||
{
|
||||
if( dirs.MakePath(item_temp.parent_id, cur->request->redirect_to, false) )
|
||||
cur->request->redirect_to += item_temp.url;
|
||||
@@ -528,7 +537,7 @@ bool System::CanChangeUser(const Item & item, long new_user_id)
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.user_id == -1 || new_user_id == -1 || item.user_id != new_user_id )
|
||||
if( item.item_content.user_id == -1 || new_user_id == -1 || item.item_content.user_id != new_user_id )
|
||||
// only super user can change the owner of an item
|
||||
return false;
|
||||
|
||||
@@ -548,7 +557,7 @@ bool System::CanChangeGroup(const Item & item, long new_group_id)
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.group_id != new_group_id )
|
||||
if( item.item_content.group_id != new_group_id )
|
||||
{
|
||||
// user is allowed to change the group only if he is an owner of the item
|
||||
// he can change only into a group in which he is a member of, or into a 'no_group'
|
||||
@@ -556,7 +565,7 @@ bool System::CanChangeGroup(const Item & item, long new_group_id)
|
||||
if( !cur->session->puser || cur->session->puser->id == -1 )
|
||||
return false;
|
||||
|
||||
if( item.user_id == -1 || cur->session->puser->id != item.user_id )
|
||||
if( item.item_content.user_id == -1 || cur->session->puser->id != item.item_content.user_id )
|
||||
return false;
|
||||
|
||||
if( new_group_id == -1 )
|
||||
@@ -582,14 +591,14 @@ bool System::CanChangePrivileges(const Item & item, int new_priv)
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( item.privileges != new_priv )
|
||||
if( item.item_content.privileges != new_priv )
|
||||
{
|
||||
// the owner of an item is allowed to change the privileges
|
||||
|
||||
if( !cur->session->puser || cur->session->puser->id == -1 )
|
||||
return false;
|
||||
|
||||
if( item.user_id == -1 || cur->session->puser->id != item.user_id )
|
||||
if( item.item_content.user_id == -1 || cur->session->puser->id != item.item_content.user_id )
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -608,27 +617,27 @@ bool System::HasAccess(const Item & item, int mask)
|
||||
// super user is allowed everything
|
||||
return true;
|
||||
|
||||
if( cur->session->puser && item.user_id != -1 && cur->session->puser->id == item.user_id )
|
||||
if( cur->session->puser && item.item_content.user_id != -1 && cur->session->puser->id == item.item_content.user_id )
|
||||
{
|
||||
// the owner
|
||||
return ((item.privileges >> 9) & mask) == mask;
|
||||
return ((item.item_content.privileges >> 9) & mask) == mask;
|
||||
}
|
||||
|
||||
if( cur->session->puser && item.group_id != -1 && cur->session->puser->IsMemberOf(item.group_id) )
|
||||
if( cur->session->puser && item.item_content.group_id != -1 && cur->session->puser->IsMemberOf(item.item_content.group_id) )
|
||||
{
|
||||
// group
|
||||
return ((item.privileges >> 6) & mask) == mask;
|
||||
return ((item.item_content.privileges >> 6) & mask) == mask;
|
||||
}
|
||||
|
||||
if( cur->session->puser )
|
||||
{
|
||||
// others -- others logged people
|
||||
return ((item.privileges >> 3) & mask) == mask;
|
||||
return ((item.item_content.privileges >> 3) & mask) == mask;
|
||||
}
|
||||
|
||||
// guests -- not logged people
|
||||
|
||||
return (item.privileges & mask) == mask;
|
||||
return (item.item_content.privileges & mask) == mask;
|
||||
}
|
||||
|
||||
|
||||
@@ -656,7 +665,7 @@ bool System::HasReadExecAccess(const Item & item)
|
||||
{
|
||||
// there must be at least one 'x' (for the root)
|
||||
// !! CHECK ME: is it applicable to directories too?
|
||||
return (item.privileges & 01111) != 0;
|
||||
return (item.item_content.privileges & 01111) != 0;
|
||||
}
|
||||
|
||||
return HasAccess(item, 5); // r+x
|
||||
@@ -774,7 +783,7 @@ bool System::CanRemoveRenameChild(const Item & dir, long child_item_user_id)
|
||||
if( !HasWriteAccess(dir) )
|
||||
return false;
|
||||
|
||||
if( (dir.privileges & 010000) == 0 )
|
||||
if( (dir.item_content.privileges & 010000) == 0 )
|
||||
// there is no a sticky bit set to this directory
|
||||
return true;
|
||||
|
||||
@@ -783,10 +792,10 @@ bool System::CanRemoveRenameChild(const Item & dir, long child_item_user_id)
|
||||
if( cur->session->puser->super_user )
|
||||
return true;
|
||||
|
||||
if( dir.user_id != -1 && cur->session->puser->id != -1 && child_item_user_id != -1 )
|
||||
if( dir.item_content.user_id != -1 && cur->session->puser->id != -1 && child_item_user_id != -1 )
|
||||
{
|
||||
if( cur->session->puser->id == child_item_user_id ||
|
||||
cur->session->puser->id == dir.user_id )
|
||||
cur->session->puser->id == dir.item_content.user_id )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -867,12 +876,12 @@ return puser->IsMemberOf(group);
|
||||
// the path depends on parent_id
|
||||
bool System::CreateNewFileSimpleFs(Item & item)
|
||||
{
|
||||
bool res = dirs.MakePath(item.parent_id, item.file_path);
|
||||
bool res = dirs.MakePath(item.parent_id, item.item_content.file_path);
|
||||
|
||||
if( res )
|
||||
{
|
||||
if( !item.file_path.empty() && item.file_path[0] == '/' )
|
||||
item.file_path.erase(0, 1);
|
||||
if( !item.item_content.file_path.empty() && item.item_content.file_path[0] == '/' )
|
||||
item.item_content.file_path.erase(0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -897,7 +906,7 @@ size_t buffer_len = sizeof(buffer)/sizeof(wchar_t);
|
||||
buffer[0] = '0';
|
||||
swprintf(buffer+1, buffer_len, L"%lx", (unsigned long)item.id);
|
||||
|
||||
item.file_path.clear();
|
||||
item.item_content.file_path.clear();
|
||||
|
||||
// make sure that the length is even
|
||||
if( (wcslen(hash) & 1) != 0 )
|
||||
@@ -905,16 +914,16 @@ size_t buffer_len = sizeof(buffer)/sizeof(wchar_t);
|
||||
|
||||
for(size_t i=0 ; hash[i] != 0 ; i+=2)
|
||||
{
|
||||
item.file_path += hash[i];
|
||||
item.file_path += hash[i+1];
|
||||
item.item_content.file_path += hash[i];
|
||||
item.item_content.file_path += hash[i+1];
|
||||
|
||||
if( hash[i+2] != 0 )
|
||||
item.file_path += '/';
|
||||
item.item_content.file_path += '/';
|
||||
}
|
||||
|
||||
// one character more to make sure the path is unique
|
||||
// (we can have a directory without the character)
|
||||
item.file_path += '_';
|
||||
item.item_content.file_path += '_';
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -939,18 +948,18 @@ bool res;
|
||||
if( !pmount || pmount->fs != mounts.MountFsHashfs() )
|
||||
{
|
||||
res = CreateNewFileSimpleFs(item);
|
||||
item.file_fs = mounts.MountFsSimplefs();
|
||||
item.item_content.file_fs = mounts.MountFsSimplefs();
|
||||
}
|
||||
else
|
||||
{
|
||||
res = CreateNewFileHashFs(item);
|
||||
item.file_fs = mounts.MountFsHashfs();
|
||||
item.item_content.file_fs = mounts.MountFsHashfs();
|
||||
}
|
||||
|
||||
if( res )
|
||||
item.file_path += item.url;
|
||||
item.item_content.file_path += item.url;
|
||||
else
|
||||
item.file_path.clear();
|
||||
item.item_content.file_path.clear();
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -968,7 +977,7 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
|
||||
return false;
|
||||
}
|
||||
|
||||
if( item.file_path.empty() || item.file_type == WINIX_ITEM_FILETYPE_NONE )
|
||||
if( item.item_content.file_path.empty() || item.item_content.file_type == WINIX_ITEM_FILETYPE_NONE )
|
||||
{
|
||||
log << log1 << "System: MakePath: this item has not a static file" << logend;
|
||||
return false;
|
||||
@@ -976,7 +985,7 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
|
||||
|
||||
path = config->upload_dir;
|
||||
|
||||
if( item.file_fs == mounts.MountFsHashfs() )
|
||||
if( item.item_content.file_fs == mounts.MountFsHashfs() )
|
||||
path += L"/hashfs";
|
||||
else
|
||||
path += L"/simplefs";
|
||||
@@ -988,11 +997,11 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
|
||||
path += L"/normal";
|
||||
|
||||
|
||||
if( create_dir && !CreateDirs(path, item.file_path, chmod, group, true) )
|
||||
if( create_dir && !CreateDirs(path, item.item_content.file_path, chmod, group, true) )
|
||||
return false;
|
||||
|
||||
path += '/';
|
||||
path += item.file_path;
|
||||
path += item.item_content.file_path;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1025,14 +1034,16 @@ return res;
|
||||
|
||||
|
||||
|
||||
Error System::AddFile(Item & item, int notify_code, bool call_plugins)
|
||||
bool System::AddFile(Item & item, int notify_code, bool call_plugins)
|
||||
{
|
||||
if( item.type != Item::file )
|
||||
return WINIX_ERR_FILE_EXPECTED;
|
||||
|
||||
Error status = db->AddItem(item);
|
||||
|
||||
//Error status = db->AddItem(item);
|
||||
bool status = item.insert();
|
||||
|
||||
if( status == WINIX_ERR_OK )
|
||||
if( status )
|
||||
{
|
||||
log << log2 << "System: added a new file, url: " << item.url << ", id: " << item.id
|
||||
<< ", parent_id: " << item.parent_id << logend;
|
||||
@@ -1050,20 +1061,22 @@ return status;
|
||||
|
||||
|
||||
|
||||
Error System::EditFile(Item & item, bool with_url, int notify_code, bool call_plugins)
|
||||
bool System::EditFile(Item & item, bool with_url, int notify_code, bool call_plugins)
|
||||
{
|
||||
if( item.type != Item::file )
|
||||
return WINIX_ERR_FILE_EXPECTED;
|
||||
|
||||
if( cur->session && cur->session->puser )
|
||||
cur->request->item.modification_user_id = cur->session->puser->id;
|
||||
cur->request->item.item_content.modification_user_id = cur->session->puser->id;
|
||||
else
|
||||
cur->request->item.modification_user_id = -1;
|
||||
cur->request->item.item_content.modification_user_id = -1;
|
||||
|
||||
item.SetDateModifyToNow();
|
||||
Error status = db->EditItemById(item, with_url);
|
||||
item.item_content.SetDateModifyToNow();
|
||||
|
||||
bool status = item.update(with_url, true);
|
||||
//Error status = db->EditItemById(item, with_url);
|
||||
|
||||
if( status == WINIX_ERR_OK )
|
||||
if( status )
|
||||
{
|
||||
TemplatesFunctions::pattern_cacher.UpdatePattern(item);
|
||||
|
||||
@@ -1184,7 +1197,17 @@ int System::FollowLink(const std::vector<Item*> & current_dir_tab, const std::ws
|
||||
|
||||
if( res == 1 )
|
||||
{
|
||||
if( db->GetItem(out_dir_tab.back()->id, name_temp, out_item) == WINIX_ERR_OK )
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
|
||||
bool status = finder.
|
||||
select().
|
||||
where().
|
||||
eq(L"parent_id", out_dir_tab.back()->id).
|
||||
eq(L"url", name_temp).
|
||||
get(out_item);
|
||||
|
||||
//if( db->GetItem(out_dir_tab.back()->id, name_temp, out_item) == WINIX_ERR_OK )
|
||||
if( status )
|
||||
return 1;
|
||||
else
|
||||
return 2;
|
||||
@@ -1213,12 +1236,12 @@ bool System::FollowAllLinksDirFound(std::vector<Item*> & out_dir_tab,
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !out_dir_tab.back()->link_to.empty() )
|
||||
if( !out_dir_tab.back()->item_content.link_to.empty() )
|
||||
{
|
||||
if( follow_dir_default )
|
||||
{
|
||||
if( !(stop_on_link_redirect && out_dir_tab.back()->link_redirect==1) )
|
||||
link_to_temp = out_dir_tab.back()->link_to;
|
||||
if( !(stop_on_link_redirect && out_dir_tab.back()->item_content.link_redirect==1) )
|
||||
link_to_temp = out_dir_tab.back()->item_content.link_to;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1252,15 +1275,15 @@ bool System::FollowAllLinksFileOrSymlinkFound(std::vector<Item*> & out_dir_tab,
|
||||
|
||||
if( out_item.type == Item::symlink )
|
||||
{
|
||||
if( out_item.link_to.empty() )
|
||||
if( out_item.item_content.link_to.empty() )
|
||||
{
|
||||
log << log1 << "System: symlink empty" << logend;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !(stop_on_link_redirect && out_item.link_redirect==1) )
|
||||
link_to_temp = out_item.link_to;
|
||||
if( !(stop_on_link_redirect && out_item.item_content.link_redirect==1) )
|
||||
link_to_temp = out_item.item_content.link_to;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1392,8 +1415,8 @@ bool System::FollowAllLinks(const std::wstring & link_to,
|
||||
cur->request->item.Clear();
|
||||
cur->request->last_item = cur->request->dir_tab.back();
|
||||
|
||||
if( !cur->request->dir_tab.back()->link_to.empty() )
|
||||
RedirectTo(cur->request->dir_tab.back()->link_to);
|
||||
if( !cur->request->dir_tab.back()->item_content.link_to.empty() )
|
||||
RedirectTo(cur->request->dir_tab.back()->item_content.link_to);
|
||||
|
||||
log << log3 << "System: current directory changed" << logend;
|
||||
}
|
||||
@@ -1404,7 +1427,7 @@ bool System::FollowAllLinks(const std::wstring & link_to,
|
||||
cur->request->last_item = &cur->request->item;
|
||||
|
||||
if( cur->request->item.type == Item::symlink )
|
||||
RedirectTo(cur->request->item.link_to); // cur->request->item.link_to is not empty
|
||||
RedirectTo(cur->request->item.item_content.link_to); // cur->request->item.item_content.link_to is not empty
|
||||
|
||||
log << log3 << "System: current directory changed and the new file loaded" << logend;
|
||||
}
|
||||
@@ -1459,25 +1482,35 @@ bool System::AddCommonFileToVar(const wchar_t * file_path, const wchar_t * url,
|
||||
return false;
|
||||
}
|
||||
|
||||
if( db->GetItem(var->id, url, file_content_item) == WINIX_ERR_OK )
|
||||
morm::Finder<Item> finder(model_connector);
|
||||
|
||||
bool status = finder.select().where().eq(L"parent_id", var->id).eq(L"url", url).get(file_content_item);
|
||||
|
||||
//if( db->GetItem(var->id, url, file_content_item) == WINIX_ERR_OK )
|
||||
if( status )
|
||||
{
|
||||
if( overwrite_existing )
|
||||
db->DelItem(file_content_item);
|
||||
{
|
||||
file_content_item.remove();
|
||||
//db->DelItem(file_content_item);
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
file_content_item.Clear();
|
||||
file_content_item.parent_id = var->id;
|
||||
file_content_item.user_id = var->user_id;
|
||||
file_content_item.group_id = var->group_id;
|
||||
file_content_item.privileges = 07555; // !! IMPROVE ME: may it should be added as a parameter to this function?
|
||||
file_content_item.item_content.user_id = var->item_content.user_id;
|
||||
file_content_item.item_content.group_id = var->item_content.group_id;
|
||||
file_content_item.item_content.privileges = 07555; // !! IMPROVE ME: may it should be added as a parameter to this function?
|
||||
file_content_item.subject = url;
|
||||
file_content_item.url = url;
|
||||
file_content_item.type = Item::file;
|
||||
file_content_item.html_template = config->templates_index_raw;
|
||||
file_content_item.content = file_content;
|
||||
file_content_item.content_type = Item::ct_other;
|
||||
file_content_item.item_content.content_raw = file_content;
|
||||
file_content_item.item_content.content_raw_type = ItemContent::ct_other;
|
||||
|
||||
return AddFile(file_content_item, false) == WINIX_ERR_OK;
|
||||
}
|
||||
|
||||
@@ -178,8 +178,8 @@ public:
|
||||
|
||||
bool MakePath(const Item & item, std::wstring & path, bool clear_path = true);
|
||||
|
||||
Error AddFile(Item & item, int notify_code = 0, bool call_plugins = true);
|
||||
Error EditFile(Item & item, bool with_url = true, int notify_code = 0, bool call_plugins = true);
|
||||
bool AddFile(Item & item, int notify_code = 0, bool call_plugins = true);
|
||||
bool EditFile(Item & item, bool with_url = true, int notify_code = 0, bool call_plugins = true);
|
||||
|
||||
|
||||
time_t ToLocal(time_t utc_time);
|
||||
|
||||
@@ -65,6 +65,12 @@ void WinixModel::set_model_connector(morm::ModelConnector * model_connector)
|
||||
}
|
||||
|
||||
|
||||
morm::ModelConnector * WinixModel::get_model_connector()
|
||||
{
|
||||
return model_connector;
|
||||
}
|
||||
|
||||
|
||||
void WinixModel::set_dependency(WinixBase * winix_base)
|
||||
{
|
||||
WinixBase::set_dependency(winix_base);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018, Tomasz Sowa
|
||||
* Copyright (c) 2018-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -52,6 +52,8 @@ public:
|
||||
virtual ~WinixModel();
|
||||
|
||||
void set_model_connector(morm::ModelConnector * model_connector);
|
||||
morm::ModelConnector * get_model_connector();
|
||||
|
||||
void set_plugin(Plugin * plugin);
|
||||
|
||||
void set_dependency(WinixBase * winix_base);
|
||||
|
||||
Reference in New Issue
Block a user