changed organization of static files

removed: item.auth item.auth_path
added:   item.file_path, item.file_fs, item.file_type
now the path to a static file is a relative path
added: thumbnails (not finished yet)
fixed: db didn't correctly return the number of deleted items /DelItem() method/




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@696 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-12-10 21:07:01 +00:00
parent 9b29cce1a4
commit 36c8822e6c
41 changed files with 435 additions and 364 deletions

View File

@@ -239,7 +239,7 @@ Error Db::AddItemIntoItem(Item & item)
{
query.Clear();
query << R("insert into core.item (user_id, modification_user_id, group_id, privileges, "
"date_creation, date_modification, type, parent_id, content_id, auth, auth_path, "
"date_creation, date_modification, type, parent_id, content_id, file_path, file_fs, file_type, "
"default_item, subject, guest_name, template, url) values (")
<< item.user_id
<< item.modification_user_id
@@ -250,8 +250,9 @@ Error Db::AddItemIntoItem(Item & item)
<< static_cast<int>(item.type)
<< item.parent_id
<< item.content_id
<< static_cast<int>(item.auth)
<< item.auth_path
<< item.file_path
<< item.file_fs
<< item.file_type
<< item.default_item
<< item.subject
<< item.guest_name
@@ -346,7 +347,7 @@ Error Db::EditItemInItem(Item & item, bool with_url)
query.Clear();
query << R("update core.item set (user_id, modification_user_id, group_id, privileges, "
"date_creation, date_modification, type, default_item, parent_id, subject, "
"guest_name, auth, auth_path, template");
"guest_name, file_path, file_fs, file_type, template");
if( with_url )
query << R(", url");
@@ -363,8 +364,9 @@ Error Db::EditItemInItem(Item & item, bool with_url)
<< item.parent_id
<< item.subject
<< item.guest_name
<< static_cast<int>(item.auth)
<< item.auth_path
<< item.file_path
<< item.file_fs
<< item.file_type
<< item.html_template;
if( with_url )
@@ -626,7 +628,7 @@ PGresult * Db::GetItemsQuery(const DbItemQuery & iq, bool skip_other_sel)
if( iq.sel_url ) query << R(" ,url");
if( iq.sel_type ) query << R(" ,type");
if( iq.sel_default_item ) query << R(" ,default_item");
if( iq.sel_auth ) query << R(" ,auth, auth_path");
if( iq.sel_file ) query << R(" ,file_path, file_fs, file_type");
if( iq.sel_html_template ) query << R(" ,template");
}
@@ -635,7 +637,7 @@ PGresult * Db::GetItemsQuery(const DbItemQuery & iq, bool skip_other_sel)
if( iq.sel_content )
query << R(" left join core.content on item.content_id = content.id");
if( iq.where_id || iq.where_parent_id || iq.where_type || iq.where_auth )
if( iq.where_id || iq.where_parent_id || iq.where_type || iq.where_file_type )
{
query << R(" where ");
const char * add_and = " and ";
@@ -645,16 +647,16 @@ PGresult * Db::GetItemsQuery(const DbItemQuery & iq, bool skip_other_sel)
if( iq.where_parent_id ){ query << R(if_and) << R("parent_id=") << iq.parent_id ; if_and = add_and; }
if( iq.where_type ) { query << R(if_and) << R("type=") << int(iq.type) ; if_and = add_and; }
if( iq.where_auth )
if( iq.where_file_type )
{
query << R(if_and) << R("auth");
query << R(if_and) << R("file_type");
if( iq.auth_equal )
if( iq.file_type_equal )
query << R("=");
else
query << R("!=");
query << static_cast<int>(iq.auth);
query << iq.file_type;
if_and = add_and;
}
}
@@ -1038,7 +1040,7 @@ return result;
Error Db::EditAuthById(Item & item, long id)
Error Db::EditFileById(Item & item, long id)
{
PGresult * r = 0;
Error result = WINIX_ERR_OK;
@@ -1046,12 +1048,11 @@ Error Db::EditAuthById(Item & item, long id)
try
{
query.Clear();
query << R("update core.item set (auth, auth_path) = (")
<< static_cast<int>(item.auth)
<< item.auth_path
<< R(") where id=")
<< id
<< R(";");
query << R("update core.item set (file_path, file_fs, file_type) = (")
<< item.file_path
<< item.file_fs
<< item.file_type
<< R(") where id=") << id << R(";");
r = AssertQuery(query);
AssertResult(r, PGRES_COMMAND_OK);
@@ -1142,8 +1143,8 @@ return result;
bool Db::DelItemDelItem(const Item & item)
{
long rows = 0;
PGresult * r = 0;
long affected = 0;
PGresult * r = 0;
try
{
@@ -1155,7 +1156,7 @@ bool Db::DelItemDelItem(const Item & item)
r = AssertQuery(query);
AssertResult(r, PGRES_COMMAND_OK);
long affected = AffectedRows(r);
affected = AffectedRows(r);
if( affected > 1 )
log << log1 << "Db: more than one item were deleted" << logend;
@@ -1169,7 +1170,7 @@ bool Db::DelItemDelItem(const Item & item)
ClearResult(r);
return rows != 0;
return affected != 0;
}
@@ -1240,9 +1241,9 @@ return result;
bool Db::DelItem(const Item & item)
{
long contents;
Error result = DelItemCountContents(item, contents);
if( result == WINIX_ERR_OK && contents == 1 )
DelItemDelContent(item);

View File

@@ -63,7 +63,7 @@ public:
bool GetPriv(Item & item, long id);
Error EditPrivById(Item & item, long id);
Error EditParentUrlById(Item & item, long id);
Error EditAuthById(Item & item, long id);
Error EditFileById(Item & item, long id); // file_path, file_fs, file_type
Error DelDirById(long id);
Error EditSubjectById(Item & item, long id);

View File

@@ -30,10 +30,11 @@ void DbItemColumns::SetColumns(PGresult * r)
content = PQfnumber(r, "content");
content_type = PQfnumber(r, "content_type");
guest_name = PQfnumber(r, "guest_name");
auth = PQfnumber(r, "auth");
auth_path = PQfnumber(r, "auth_path");
html_template = PQfnumber(r, "template");
modification_user_id = PQfnumber(r, "modification_user_id");
file_path = PQfnumber(r, "file_path");
file_fs = PQfnumber(r, "file_fs");
file_type = PQfnumber(r, "file_type");
}
@@ -55,10 +56,11 @@ void DbItemColumns::SetItem(PGresult * r, long row, Item & item)
if( content != -1 ) item.content = DbBase::AssertValueWide(r, row, content);
if( content_type != -1 ) item.content_type = static_cast<Item::ContentType>( DbBase::AssertValueInt(r, row, content_type) );
if( guest_name != -1 ) item.guest_name = DbBase::AssertValueWide(r, row, guest_name);
if( auth != -1 ) item.auth = static_cast<Item::Auth>( DbBase::AssertValueInt(r, row, auth) );
if( auth_path != -1 ) item.auth_path = DbBase::AssertValueWide(r, row, auth_path);
if( html_template != -1 ) item.html_template = DbBase::AssertValueWide(r, row, html_template);
if( modification_user_id != -1 ) item.modification_user_id = DbBase::AssertValueLong(r, row, modification_user_id);
if( file_path != -1 ) item.file_path = DbBase::AssertValueWide(r, row, file_path);
if( file_fs != -1 ) item.file_fs = DbBase::AssertValueInt(r, row, file_fs);
if( file_type != -1 ) item.file_type = DbBase::AssertValueInt(r, row, file_type);
}

View File

@@ -34,11 +34,12 @@ struct DbItemColumns
int content;
int content_type;
int guest_name;
int auth;
int auth_path;
int modification_user_id;
int html_template;
int file_path;
int file_fs;
int file_type;
void SetColumns(PGresult * r);
void SetItem(PGresult * r, long row, Item & item);
};

View File

@@ -14,15 +14,15 @@
DbItemQuery::DbItemQuery()
{
sort_asc = true;
auth_equal = true;
sort_asc = true;
file_type_equal = true;
SetAll(true, false);
id = -1;
parent_id = -1;
type = Item::none;
auth = Item::auth_none;
file_type = WINIX_ITEM_FILETYPE_NONE;
limit = 0; // limit and offset not used by default
offset = 0;
@@ -43,7 +43,7 @@ void DbItemQuery::SetAllSel(bool sel)
sel_url = sel;
sel_type = sel;
sel_default_item = sel;
sel_auth = sel;
sel_file = sel;
sel_html_template = sel;
}
@@ -54,7 +54,7 @@ void DbItemQuery::SetAllWhere(bool where_)
where_id = where_;
where_parent_id = where_;
where_type = where_;
where_auth = where_;
where_file_type = where_;
}
@@ -91,11 +91,11 @@ void DbItemQuery::WhereType(Item::Type type_)
void DbItemQuery::WhereAuth(Item::Auth st, bool equal)
void DbItemQuery::WhereFileType(int file_t, bool equal)
{
where_auth = true;
auth = st;
auth_equal = equal;
where_file_type = true;
file_type = file_t;
file_type_equal = equal;
}

View File

@@ -30,19 +30,19 @@ struct DbItemQuery
bool sel_url; // url
bool sel_type; // type (dir, file, none)
bool sel_default_item; // default_item
bool sel_auth; // auth, auth_path
bool sel_file; // file_path, file_fs, file_type
bool sel_html_template; // template
bool where_id; //
bool where_parent_id; //
bool where_type;
bool where_auth;
bool where_file_type;
long id; // if where_id is true
long parent_id; // if where_parent_id is true
Item::Type type;
Item::Auth auth;
bool auth_equal; // if true means auth should be equal
int file_type;
bool file_type_equal; // if true means file_type should be equal
bool sort_asc;
long limit;
@@ -57,7 +57,7 @@ struct DbItemQuery
void WhereId(long id_);
void WhereParentId(long parent_id_);
void WhereType(Item::Type type_);
void WhereAuth(Item::Auth st, bool equal = true);
void WhereFileType(int file_t, bool equal = true);
void Limit(long l); // setting 0 turns off
void Offset(long o); // setting 0 turns off