1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

User_wiki: Simplify creation of wiki database file and tables

This commit is contained in:
gnosygnu
2016-10-31 12:16:25 -04:00
parent ae0fb89745
commit 8016846cd9
35 changed files with 486 additions and 84 deletions

View File

@@ -29,7 +29,7 @@ public class Xobc_data_db {
this.tbl__host_regy = new Xobc_host_regy_tbl(conn);
this.tbl__version_regy = new Xobc_version_regy_tbl(conn);
this.tbl__lang_regy = new Xobc_lang_regy_tbl(conn);
conn.Meta_tbl_assert(tbl__task_regy, tbl__step_regy, tbl__step_map, tbl__import_step, tbl__host_regy, tbl__version_regy);
conn.Meta_tbl_assert(tbl__task_regy, tbl__step_regy, tbl__step_map, tbl__import_step, tbl__host_regy, tbl__version_regy, tbl__lang_regy);
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public Io_url Url() {return url;} private final Io_url url;

View File

@@ -30,9 +30,7 @@ public class Xobc_lang_regy_tbl implements Db_tbl {
conn.Rls_reg(this);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
}
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
public Xobc_lang_regy_itm[] Select_all() {
List_adp list = List_adp_.New();
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();

View File

@@ -38,7 +38,6 @@ public class Xobc_filter_mgr {
if ( Xow_domain_itm_.Match_lang(task_domain, lang_key_str)
&& Xow_domain_itm_.Match_type(task_domain, type_key_str)
)
tmp.Add(task);
}

View File

@@ -146,8 +146,8 @@ class Reindex_html_dbs_cmd {
// delete old dbs
wiki.Data__core_mgr().Rls();
String repack_suffix = Xoh_trg_tbl_mgr.Repack_suffix;
Db_stmt delete_stmt = core_conn.Stmt_delete(Xowd_xowa_db_tbl.Tbl_name, Xowd_xowa_db_tbl.Fld_id);
Db_rdr rdr = core_conn.Stmt_select(Xowd_xowa_db_tbl.Tbl_name, String_.Ary(Xowd_xowa_db_tbl.Fld_id, Xowd_xowa_db_tbl.Fld_type, Xowd_xowa_db_tbl.Fld_url)).Exec_select__rls_auto();
Db_stmt delete_stmt = core_conn.Stmt_delete(Xowd_xowa_db_tbl.TBL_NAME, Xowd_xowa_db_tbl.Fld_id);
Db_rdr rdr = core_conn.Stmt_select(Xowd_xowa_db_tbl.TBL_NAME, String_.Ary(Xowd_xowa_db_tbl.Fld_id, Xowd_xowa_db_tbl.Fld_type, Xowd_xowa_db_tbl.Fld_url)).Exec_select__rls_auto();
while (rdr.Move_next()) {
byte file_tid = rdr.Read_byte(Xowd_xowa_db_tbl.Fld_type);
if (file_tid != Xow_db_file_.Tid__html_data) continue;
@@ -160,8 +160,8 @@ class Reindex_html_dbs_cmd {
delete_stmt.Rls();
// update new dbs
Db_stmt update_stmt = core_conn.Stmt_update(Xowd_xowa_db_tbl.Tbl_name, String_.Ary(Xowd_xowa_db_tbl.Fld_id), Xowd_xowa_db_tbl.Fld_url);
rdr = core_conn.Stmt_select(Xowd_xowa_db_tbl.Tbl_name, String_.Ary(Xowd_xowa_db_tbl.Fld_id, Xowd_xowa_db_tbl.Fld_type, Xowd_xowa_db_tbl.Fld_url)).Exec_select__rls_auto();
Db_stmt update_stmt = core_conn.Stmt_update(Xowd_xowa_db_tbl.TBL_NAME, String_.Ary(Xowd_xowa_db_tbl.Fld_id), Xowd_xowa_db_tbl.Fld_url);
rdr = core_conn.Stmt_select(Xowd_xowa_db_tbl.TBL_NAME, String_.Ary(Xowd_xowa_db_tbl.Fld_id, Xowd_xowa_db_tbl.Fld_type, Xowd_xowa_db_tbl.Fld_url)).Exec_select__rls_auto();
while (rdr.Move_next()) {
byte file_tid = rdr.Read_byte(Xowd_xowa_db_tbl.Fld_type);
if (file_tid != Xow_db_file_.Tid__html_data) continue;

View File

@@ -31,7 +31,7 @@ class Split_meta_wkr__fil extends Split_meta_wkr_base {
@Override public void On_nth_new(Split_ctx ctx, Db_conn trg_conn) {
this.tbl = new Fsd_fil_tbl(trg_conn, Bool_.N, Fsm_mnt_mgr.Mnt_idx_main);
tbl.Create_tbl();
this.stmt = trg_conn.Stmt_insert(tbl.tbl_name, tbl.flds);
this.stmt = trg_conn.Stmt_insert(tbl.Tbl_name(), tbl.flds);
}
@Override public void On_nth_rls(Split_ctx ctx, Db_conn trg_conn) {this.stmt = Db_stmt_.Rls(stmt);}
@Override protected String Load_sql(Db_attach_mgr attach_mgr, int ns_id, int score_bgn, int score_end) {

View File

@@ -31,7 +31,7 @@ class Split_meta_wkr__org extends Split_meta_wkr_base {
@Override public void On_nth_new(Split_ctx ctx, Db_conn trg_conn) {
this.tbl = new Xof_orig_tbl(trg_conn, Bool_.N);
tbl.Create_tbl();
this.stmt = trg_conn.Stmt_insert(tbl.tbl_name, tbl.flds);
this.stmt = trg_conn.Stmt_insert(tbl.Tbl_name(), tbl.flds);
}
@Override public void On_nth_rls(Split_ctx ctx, Db_conn trg_conn) {this.stmt = Db_stmt_.Rls(stmt);}
@Override protected String Load_sql(Db_attach_mgr attach_mgr, int ns_id, int score_bgn, int score_end) {

View File

@@ -31,7 +31,7 @@ class Split_meta_wkr__thm extends Split_meta_wkr_base {
@Override public void On_nth_new(Split_ctx ctx, Db_conn trg_conn) {
this.tbl = new Fsd_thm_tbl(trg_conn, Bool_.N, Fsm_mnt_mgr.Mnt_idx_main, Bool_.Y);
tbl.Create_tbl();
this.stmt = trg_conn.Stmt_insert(tbl.tbl_name, tbl.flds);
this.stmt = trg_conn.Stmt_insert(tbl.Tbl_name(), tbl.flds);
}
@Override public void On_nth_rls(Split_ctx ctx, Db_conn trg_conn) {this.stmt = Db_stmt_.Rls(stmt);}
@Override protected String Load_sql(Db_attach_mgr attach_mgr, int ns_id, int score_bgn, int score_end) {

View File

@@ -0,0 +1,78 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.users.wikis.regys.specials.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.users.*; import gplx.xowa.addons.users.wikis.*; import gplx.xowa.addons.users.wikis.regys.*; import gplx.xowa.addons.users.wikis.regys.specials.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*;
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.addons.users.wikis.regys.dbs.*;
import gplx.xowa.addons.users.wikis.regys.specials.itms.bldrs.*;
public class Xopg_db_mgr {
private final Xodb_mgr_sql db_mgr;
public Xopg_db_mgr(Xowe_wiki wiki) {
this.db_mgr = wiki.Db_mgr_as_sql();
}
public int Create(int ns_id, byte[] ttl_page_db, byte[] text_raw) {
Xow_db_file core_db = db_mgr.Core_data_mgr().Db__core();
int page_id = core_db.Tbl__cfg().Select_int_or("db", "page.id_next", -1);
// get page_db, text_db and over variables
Xowd_page_tbl page_tbl = db_mgr.Core_data_mgr().Tbl__page();
Xow_db_file text_db = db_mgr.Core_data_mgr().Db__text();
if (text_db == null) text_db = db_mgr.Core_data_mgr().Db__core(); // HACK: needed for create new wiki DATE:2016-10-29
Xowd_text_tbl text_tbl = text_db.Tbl__text();
byte[] text_zip = text_tbl.Zip(text_raw);
boolean redirect = db_mgr.Wiki().Redirect_mgr().Is_redirect(text_raw, text_raw.length);
// do insert
page_tbl.Insert_bgn();
text_tbl.Insert_bgn();
int ns_count = core_db.Tbl__ns().Select_ns_count(ns_id) + 1;
try {
db_mgr.Core_data_mgr().Create_page(page_tbl, text_tbl, page_id, ns_id, ttl_page_db, redirect, Datetime_now.Get(), text_zip, text_raw.length, ns_count, text_db.Id(), -1);
core_db.Tbl__ns().Update_ns_count(ns_id, ns_count);
} finally {
page_tbl.Insert_end();
text_tbl.Insert_end();
}
return page_id;
}
public static int Create(Xodb_wiki_db core_db, int ns_id, byte[] ttl_page_db, byte[] text_raw) {
Db_cfg_tbl cfg_tbl = Db_cfg_tbl.Get_by_key(core_db, Xowd_cfg_tbl_.Tbl_name);
int page_id = cfg_tbl.Select_int_or("db", "page.id_next", -1);
Xowd_page_tbl page_tbl = Xowd_page_tbl.Get_by_key(core_db);
Xowd_text_tbl text_tbl = Xowd_text_tbl.Get_by_key(core_db);
byte[] text_zip = text_tbl.Zip(text_raw);
boolean redirect = Bool_.N;
// do insert
page_tbl.Insert_bgn();
text_tbl.Insert_bgn();
Xowd_site_ns_tbl ns_tbl = Xowd_site_ns_tbl.Get_by_key(core_db);
int ns_count = ns_tbl.Select_ns_count(ns_id) + 1;
try {
page_tbl.Insert_cmd_by_batch(page_id, ns_id, ttl_page_db, redirect, Datetime_now.Get(), text_raw.length, ns_count, 0, -1);
text_tbl.Insert_cmd_by_batch(page_id, text_zip);
Xowd_site_ns_tbl.Get_by_key(core_db).Update_ns_count(ns_id, ns_count);
} finally {
page_tbl.Insert_end();
text_tbl.Insert_end();
}
return page_id;
}
}

View File

@@ -16,42 +16,24 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.users.wikis.regys.specials.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.users.*; import gplx.xowa.addons.users.wikis.*; import gplx.xowa.addons.users.wikis.regys.*; import gplx.xowa.addons.users.wikis.regys.specials.*;
import gplx.dbs.sys.*;
import gplx.langs.jsons.*;
import gplx.xowa.addons.users.wikis.regys.dbs.*;
public class Xouw_itm_bridge implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
private Xoa_app app;
private Xouw_itm_mgr itm_mgr;
public void Init_by_app(Xoa_app app) {
this.app = app;
this.itm_mgr = new Xouw_itm_mgr(app);
}
public String Exec(Json_nde data) {
byte proc_id = proc_hash.Get_as_byte_or(data.Get_as_bry_or(Msg__proc, null), Byte_ascii.Max_7_bit);
Json_nde args = data.Get_kv(Msg__args).Val_as_nde();
switch (proc_id) {
case Proc__save: Save(args); break;
case Proc__save: itm_mgr.Save(args); break;
default: throw Err_.new_unhandled_default(proc_id);
}
return "";
}
private void Save(Json_nde args) {
Xouw_db_mgr db_mgr = new Xouw_db_mgr(app.User().User_db_mgr().Conn());
int id = args.Get_as_int("id");
if (id == -1) {
id = 2;
}
String domain = args.Get_as_str("key");
String url = args.Get_as_str("file");
if (db_mgr.Tbl__wiki().Upsert(id, domain, args.Get_as_str("name"), url)) {
gplx.xowa.wikis.nss.Xow_ns_mgr ns_mgr = gplx.xowa.wikis.nss.Xow_ns_mgr_.default_(gplx.xowa.langs.cases.Xol_case_mgr_.U8());
Xow_wiki_.Create(app, ns_mgr, domain, Io_url_.new_fil_(url).OwnerDir());
Xowe_wiki wiki = new Xowe_wiki((Xoae_app)app, app.Lang_mgr().Get_by_or_en(Bry_.Empty), ns_mgr, gplx.xowa.wikis.domains.Xow_domain_itm_.parse(Bry_.new_u8(domain)), Io_url_.new_fil_(url).OwnerDir());
gplx.fsdb.Fsdb_db_mgr__v2_bldr.Make_core_file_main(wiki, Io_url_.new_fil_(url), domain, gplx.xowa.wikis.data.Xow_db_layout.Itm_all);
wiki.Init_db_mgr();
wiki.Init_by_wiki__force_and_mark_inited();
wiki.Data__core_mgr().Dbs__make_by_id(1, gplx.xowa.wikis.data.Xow_db_file_.Tid__core, "", 0, ".xowa");
wiki.Data__core_mgr().Db__core().Tbl__db().Commit_all(wiki.Data__core_mgr());
wiki.Db_mgr().Save_mgr().Data_create(Xoa_ttl.Parse(wiki, Bry_.new_a7("Main_Page")), Bry_.new_a7("Main page created"));
}
}
private static final byte[] Msg__proc = Bry_.new_a7("proc"), Msg__args = Bry_.new_a7("args");
private static final byte Proc__save = 0;
private static final Hash_adp_bry proc_hash = Hash_adp_bry.cs()

View File

@@ -30,7 +30,7 @@ class Xouw_itm_html extends Xow_special_wtr__base {
Xouw_db_mgr db_mgr = new Xouw_db_mgr(conn);
Xou_wiki_itm itm = db_mgr.Tbl__wiki().Select_by_key_or_null(key);
if (itm == null)
itm = new Xou_wiki_itm(-1, 0, "", "", Io_url_.Empty, "");
itm = new Xou_wiki_itm(-1, 0, "test4", "test4", Io_url_.new_fil_("C:\\xowa\\test\\test4.xowa"), "");
return new Xouw_itm_doc(itm.Id(), itm.Domain(), itm.Name(), itm.Url().Xto_api());
}
@Override protected void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data page_data) {

View File

@@ -0,0 +1,46 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.users.wikis.regys.specials.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.users.*; import gplx.xowa.addons.users.wikis.*; import gplx.xowa.addons.users.wikis.regys.*; import gplx.xowa.addons.users.wikis.regys.specials.*;
import gplx.langs.jsons.*;
import gplx.dbs.sys.*; import gplx.xowa.addons.users.wikis.regys.dbs.*; import gplx.xowa.addons.users.wikis.regys.specials.itms.bldrs.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.*;
import gplx.xowa.langs.cases.*;
class Xouw_itm_mgr {
private final Xoa_app app;
public Xouw_itm_mgr(Xoa_app app) {
this.app = app;
}
public void Save(Json_nde args) {
Save(args.Get_as_int("id"), args.Get_as_str("domain"), args.Get_as_str("name"), args.Get_as_str("file"));
}
public void Save(int id, String domain, String name, String url_str) {
boolean itm_is_new = false;
// get next id if new
if (id == -1) {
itm_is_new = true;
Db_sys_mgr sys_mgr = new Db_sys_mgr(app.User().User_db_mgr().Conn());
id = sys_mgr.Autonum_next("user.wikis.id");
}
// insert into user_wiki
Xouw_db_mgr db_mgr = new Xouw_db_mgr(app.User().User_db_mgr().Conn());
db_mgr.Tbl__wiki().Upsert(id, domain, name, url_str);
// if (itm_is_new) Xow_db_mkr.Create_wiki(app, domain, url_str);
if (itm_is_new) Xow_db_mkr.Create_wiki2(new Xodb_wiki_data(domain, Io_url_.new_fil_(url_str)));
}
}

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.users.wikis.regys.specials.itms.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.users.*; import gplx.xowa.addons.users.wikis.*; import gplx.xowa.addons.users.wikis.regys.*; import gplx.xowa.addons.users.wikis.regys.specials.*; import gplx.xowa.addons.users.wikis.regys.specials.itms.*;
import gplx.core.ios.streams.*;
public class Xodb_wiki_data {
public Xodb_wiki_data(String domain, Io_url core_url) {
this.domain = domain;
this.core_url = core_url;
}
public String Domain() {return domain;} private final String domain;
public Io_url Core_url() {return core_url;} private final Io_url core_url;
public byte Text_zip_tid() {return text_zip_tid;} private byte text_zip_tid = Io_stream_tid_.Tid__raw;
}

View File

@@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.users.wikis.regys.specials.itms.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.users.*; import gplx.xowa.addons.users.wikis.*; import gplx.xowa.addons.users.wikis.regys.*; import gplx.xowa.addons.users.wikis.regys.specials.*; import gplx.xowa.addons.users.wikis.regys.specials.itms.*;
import gplx.dbs.*;
public class Xodb_wiki_db implements Db_tbl_owner {
private final Ordered_hash tbls = Ordered_hash_.New();
public Xodb_wiki_db(int tid, Io_url url, Db_conn conn) {
this.tid = tid;
this.url = url;
this.conn = conn;
}
public int Tid() {return tid;} private final int tid;
public Io_url Url() {return url;} private final Io_url url;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public Db_tbl Tbls__get_by_key(String key) {return (Db_tbl)tbls.Get_by(key);}
public void Tbls__add(boolean create, Db_tbl... ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Db_tbl tbl = ary[i];
tbls.Add(tbl.Tbl_name(), tbl);
if (create)
tbl.Create_tbl();
}
}
public static Xodb_wiki_db Make(int tid, Io_url url) {
Db_conn conn = Db_conn_bldr.Instance.Get_or_new(url).Conn();
return new Xodb_wiki_db(tid, url, conn);
}
}

View File

@@ -0,0 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.users.wikis.regys.specials.itms.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.users.*; import gplx.xowa.addons.users.wikis.*; import gplx.xowa.addons.users.wikis.regys.*; import gplx.xowa.addons.users.wikis.regys.specials.*; import gplx.xowa.addons.users.wikis.regys.specials.itms.*;
public class Xodb_wiki_db_tid {
public static final int Tid__core = 0;
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.users.wikis.regys.specials.itms.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.users.*; import gplx.xowa.addons.users.wikis.*; import gplx.xowa.addons.users.wikis.regys.*; import gplx.xowa.addons.users.wikis.regys.specials.*; import gplx.xowa.addons.users.wikis.regys.specials.itms.*;
import gplx.dbs.*;
public class Xodb_wiki_mgr {
public Xodb_wiki_mgr(String domain) {
this.domain = domain;
}
public String Domain() {return domain;} private final String domain;
public Xodb_wiki_db Dbs__get_core() {return dbs__core;} private Xodb_wiki_db dbs__core;
public void Dbs__add(Xodb_wiki_db file) {
if (file.Tid() == Xodb_wiki_db_tid.Tid__core)
dbs__core = file;
}
}

View File

@@ -0,0 +1,119 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.users.wikis.regys.specials.itms.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.users.*; import gplx.xowa.addons.users.wikis.*; import gplx.xowa.addons.users.wikis.regys.*; import gplx.xowa.addons.users.wikis.regys.specials.*; import gplx.xowa.addons.users.wikis.regys.specials.itms.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.dbs.sys.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.core.ios.streams.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.data.site_stats.*;
import gplx.xowa.langs.cases.*;
import gplx.fsdb.*; import gplx.fsdb.meta.*; import gplx.fsdb.data.*; import gplx.xowa.files.origs.*;
import gplx.xowa.addons.users.wikis.regys.dbs.*;
public class Xow_db_mkr {
public static Xodb_wiki_mgr Create_wiki2(Xodb_wiki_data data) {
// create db
Xodb_wiki_mgr wiki_mgr = new Xodb_wiki_mgr(data.Domain());
wiki_mgr.Dbs__add(Xodb_wiki_db.Make(Xodb_wiki_db_tid.Tid__core, data.Core_url()));
// create tbls: wiki
Xodb_wiki_db core_db = wiki_mgr.Dbs__get_core();
Db_conn core_conn = core_db.Conn();
core_db.Tbls__add(Bool_.Y
, Xowd_cfg_tbl_.New(core_conn)
, new Xowd_xowa_db_tbl(core_conn, Bool_.N)
, new Xowd_site_ns_tbl(core_conn, Bool_.N)
, new Xow_site_stats_tbl(core_conn, Bool_.N)
, new Xowd_page_tbl(core_conn, Bool_.N)
, new Xowd_text_tbl(core_conn, Bool_.N, data.Text_zip_tid())
// if (props.Layout_text().Tid_is_all_or_few()) { // create in advance else will fail for v2; import wiki -> wiki loads and tries to load categories; v2 category processes and builds tbl; DATE:2015-03-22
, new Xowd_cat_core_tbl(core_conn, Bool_.N)
, new Xowd_cat_link_tbl(core_conn, Bool_.N)
);
// insert data: wiki
Xowd_site_ns_tbl.Get_by_key(core_db).Insert(Xow_ns_mgr_.default_(Xol_case_mgr_.U8()));
Xow_site_stats_tbl.Get_by_key(core_db).Update(0, 0, 0);
Db_cfg_tbl cfg_tbl = Db_cfg_tbl.Get_by_key(core_db, Xowd_cfg_tbl_.Tbl_name);
cfg_tbl.Insert_str(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__main_page, "Main_Page");
cfg_tbl.Insert_str(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__modified_latest, Datetime_now.Get().XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
Xopg_db_mgr.Create(core_db, Xow_ns_.Tid__main, Bry_.new_a7("Main_Page"), Bry_.new_a7("Main page created"));
Xowd_core_db_props props = new Xowd_core_db_props(2, Xow_db_layout.Itm_all, Xow_db_layout.Itm_all, Xow_db_layout.Itm_all, Io_stream_tid_.Tid__raw, Io_stream_tid_.Tid__raw, Bool_.N, Bool_.N);
props.Cfg_save(cfg_tbl);
Xowd_xowa_db_tbl.Get_by_key(core_db).Upsert(0, Xow_db_file_.Tid__core, core_db.Url().NameAndExt(), "", -1, Guid_adp_.New_str());
// create tbls: fsdb
core_db.Tbls__add(Bool_.Y
, new Fsm_mnt_tbl(core_conn, Bool_.N)
, new Fsm_atr_tbl(core_conn, Bool_.N)
, new Fsm_bin_tbl(core_conn, Bool_.N, Fsm_mnt_mgr.Mnt_idx_main)
, new Fsd_dir_tbl(core_conn, Bool_.N)
, new Fsd_fil_tbl(core_conn, Bool_.N, Fsm_mnt_mgr.Mnt_idx_main)
, new Fsd_thm_tbl(core_conn, Bool_.N, Fsm_mnt_mgr.Mnt_idx_main, Bool_.Y)
, new Xof_orig_tbl(core_conn, Bool_.N)
);
// insert data: fsdb
Fsm_mnt_mgr.Patch_core(cfg_tbl);
Fsm_atr_tbl.Get_by_key(core_db).Insert(Fsm_mnt_mgr.Mnt_idx_main, core_db.Url().NameAndExt());
cfg_tbl.Insert_int("core", "mnt.insert_idx", Fsm_mnt_mgr.Mnt_idx_user);
return wiki_mgr;
}
public static void Create_wiki(Xoa_app app, String domain, String url_str) {
// create wiki
Io_url url = Io_url_.new_any_(url_str);
Xow_ns_mgr ns_mgr = Xow_ns_mgr_.default_(Xol_case_mgr_.U8());
Xow_wiki_.Create(app.User().Key(), ns_mgr, domain, url.OwnerDir());
// more create; need wiki-reference to create fsdb and create page
Xowe_wiki wiki = new Xowe_wiki((Xoae_app)app, app.Lang_mgr().Get_by_or_en(Bry_.Empty), ns_mgr, Xow_domain_itm_.parse(Bry_.new_u8(domain)), url.OwnerDir());
gplx.fsdb.Fsdb_db_mgr__v2_bldr.Make_core_file_main(wiki, url, domain, gplx.xowa.wikis.data.Xow_db_layout.Itm_all);
wiki.Init_db_mgr();
wiki.Init_by_wiki__force_and_mark_inited();
wiki.Data__core_mgr().Dbs__make_by_id(1, Xow_db_file_.Tid__core, "", 0, ".xowa");
wiki.Data__core_mgr().Db__core().Tbl__db().Commit_all(wiki.Data__core_mgr());
// create default Main_Page
new Xopg_db_mgr(wiki).Create(Xow_ns_.Tid__main, Bry_.new_a7("Main_Page"), Bry_.new_a7("Main page created"));
}
}
/*
xowa_cfg
xowa_db
site_ns
site_stats
page
text
cat_core
cat_link
fsdb_mnt
fsdb_dba
fsdb_dbb
fsdb_dir
fsdb_fil
fsdb_thm
orig_reg
search_link
search_link_reg
search_word
css_core
css_file
*/