Add builder command to create customized deletion_db for dansguardian wikis

v3.3.4
gnosygnu 8 years ago
parent 3e21b4e4db
commit b7f089a3ab

@ -131,9 +131,9 @@ public class Xobldr__page_file_map__create extends Xob_cmd__base {
);
}
private void Create__page_file_map() {
Xob_db_file map_db = Xob_db_file.New(wiki.Fsys_mgr().Root_dir(), wiki.Domain_str() + "-file-page_map.xowa");
Xob_db_file map_db = Xob_db_file.New__page_file_map(wiki);
Db_conn map_conn = map_db.Conn();
Page_file_map_tbl map_tbl = new Page_file_map_tbl(map_conn);
Page_file_map_tbl map_tbl = new Page_file_map_tbl(map_conn, "page_file_map");
map_conn.Meta_tbl_remake(map_tbl.Meta());
map_conn.Env_db_attach("make_db", conn);
map_conn.Exec_sql_concat_w_msg

@ -17,13 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.bldrs.files.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.files.*;
import gplx.dbs.*;
public class Page_file_map_tbl {
public final String tbl_name = "page_file_map";
public class Page_file_map_tbl implements Db_tbl {
public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public final String fld_page_id, fld_fil_id, fld_thm_id, fld_sort_id, fld_count_of;
public final Db_conn conn;
public Page_file_map_tbl(Db_conn conn) {
public Page_file_map_tbl(Db_conn conn, String tbl_name) {
this.conn = conn;
this.tbl_name = tbl_name;
this.fld_page_id = flds.Add_int("page_id");
this.fld_fil_id = flds.Add_int("fil_id");
this.fld_thm_id = flds.Add_int("thm_id");
@ -31,5 +31,8 @@ public class Page_file_map_tbl {
this.fld_count_of = flds.Add_int("count_of");
this.meta = Dbmeta_tbl_itm.New(tbl_name, flds);
}
public String Tbl_name() {return tbl_name;} private final String tbl_name;
public void Create_tbl() {conn.Meta_tbl_create(meta);}
public Dbmeta_tbl_itm Meta() {return meta;} private final Dbmeta_tbl_itm meta;
public void Rls() {}
}

@ -0,0 +1,33 @@
/*
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.bldrs.updates.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.updates.*;
import gplx.dbs.*;
public class Xob_delete_regy_tbl {
public final String tbl_name = "delete_regy";
public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public final String fld_fil_id, fld_thm_id, fld_reason;
public final Db_conn conn;
public Xob_delete_regy_tbl(Db_conn conn) {
this.conn = conn;
this.fld_fil_id = flds.Add_int("fil_id");
this.fld_thm_id = flds.Add_int("thm_id");
this.fld_reason = flds.Add_str("reason", 255);
this.meta = Dbmeta_tbl_itm.New(tbl_name, flds);
}
public Dbmeta_tbl_itm Meta() {return meta;} private final Dbmeta_tbl_itm meta;
}

@ -18,12 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.addons.bldrs.updates.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.updates.*;
import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.addons.bldrs.utils_rankings.bldrs.*;
import gplx.xowa.addons.bldrs.updates.files.find_missings.*;
public class Xodel_addon implements Xoax_addon_itm, Xoax_addon_itm__bldr {
public Xob_cmd[] Bldr_cmds() {
return new Xob_cmd[]
{ Xodel_make_cmd.Prototype
, Xodel_exec_cmd.Prototype
, Xodel_small_cmd.Prototype
, Xodel_find_missing_cmd.Prototype
};
}

@ -61,17 +61,3 @@ class Xodel_make_mgr {
deletion_conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(delete_regy_tbl.tbl_name, "main", delete_regy_tbl.fld_fil_id, delete_regy_tbl.fld_thm_id));
}
}
class Xob_delete_regy_tbl {
public final String tbl_name = "delete_regy";
public final Dbmeta_fld_list flds = new Dbmeta_fld_list();
public final String fld_fil_id, fld_thm_id, fld_reason;
public final Db_conn conn;
public Xob_delete_regy_tbl(Db_conn conn) {
this.conn = conn;
this.fld_fil_id = flds.Add_int("fil_id");
this.fld_thm_id = flds.Add_int("thm_id");
this.fld_reason = flds.Add_str("reason", 255);
this.meta = Dbmeta_tbl_itm.New(tbl_name, flds);
}
public Dbmeta_tbl_itm Meta() {return meta;} private final Dbmeta_tbl_itm meta;
}

@ -0,0 +1,31 @@
/*
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.bldrs.updates.files.find_missings; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.updates.*; import gplx.xowa.addons.bldrs.updates.files.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xodel_find_missing_cmd extends Xob_cmd__base implements Xob_cmd {
public Xodel_find_missing_cmd(Xob_bldr bldr, Xowe_wiki wiki) {super(bldr, wiki);}
@Override public void Cmd_run() {
wiki.Init_assert();
new Xodel_find_missing_mgr().Exec(wiki);
}
public static final String BLDR_CMD_KEY = "file.deletion_db.find_missing";
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
public static final Xob_cmd Prototype = new Xodel_find_missing_cmd(null, null);
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xodel_find_missing_cmd(bldr, wiki);}
}

@ -0,0 +1,96 @@
/*
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.bldrs.updates.files.find_missings; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.updates.*; import gplx.xowa.addons.bldrs.updates.files.*;
import gplx.dbs.*;
import gplx.xowa.bldrs.*; import gplx.xowa.addons.bldrs.files.dbs.*;
class Xodel_find_missing_mgr {
public void Exec(Xow_wiki wiki) {
// get page_file_map; note that it must have fsdb_deleted
Db_conn pfm_conn = Xob_db_file.New__page_file_map(wiki).Conn();
// attach page_db
Db_attach_mgr attach_mgr = new Db_attach_mgr(pfm_conn, new Db_attach_itm("page_db", wiki.Data__core_mgr().Tbl__page().Conn()));
Page_file_map_tbl pfm_tbl = new Page_file_map_tbl(pfm_conn, "page_file_map_found");
pfm_conn.Meta_tbl_remake(pfm_tbl);
attach_mgr.Exec_sql_w_msg("generating page_file_map_found", Db_sql_.Make_by_fmt(String_.Ary
( "INSERT INTO page_file_map_found (page_id, fil_id, thm_id, sort_id, count_of)"
, "SELECT pfm.page_id, pfm.fil_id, pfm.thm_id, pfm.sort_id, pfm.count_of"
, "FROM page_file_map pfm"
, " JOIN <page_db>page p ON pfm.page_id = p.page_id"
)));
pfm_conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl("page_file_map_found", "fil_id__thm_id", "fil_id", "thm_id"));
// update fsdb_deleted
pfm_conn.Exec_sql("", Db_sql_.Make_by_fmt(String_.Ary
( "UPDATE fsdb_regy"
, "SET fsdb_deleted = 1"
, "WHERE NOT EXISTS "
, "("
, "SELECT 1"
, "FROM page_file_map_found pfm"
, "WHERE pfm.fil_id = fsdb_regy.fsdb_fil_id"
, "AND pfm.thm_id = fsdb_regy.fsdb_thm_id"
, ")"
)));
// create deletion db
Xob_db_file deletion_db = Xob_db_file.New__deletion_db(wiki);
Db_conn deletion_conn = deletion_db.Conn();
deletion_db.Tbl__cfg().Upsert_str("", Xodel_exec_mgr.Cfg__deletion_db__domain, wiki.Domain_str());
// copy records over to it
Xob_delete_regy_tbl delete_regy_tbl = new Xob_delete_regy_tbl(deletion_conn);
deletion_conn.Meta_tbl_remake(delete_regy_tbl.Meta());
deletion_conn.Env_db_attach("make_db", pfm_conn);
deletion_conn.Exec_sql_concat_w_msg
( "inserting into delete_regy"
, "INSERT INTO delete_regy (fil_id, thm_id, reason)"
, "SELECT fsdb_fil_id"
, ", fsdb_thm_id"
, ", ''"
, "FROM make_db.fsdb_regy"
, "WHERE fsdb_deleted = 1"
, ";"
);
deletion_conn.Env_db_detach("make_db");
deletion_conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(delete_regy_tbl.tbl_name, "main", delete_regy_tbl.fld_fil_id, delete_regy_tbl.fld_thm_id));
}
/*
--create in pfm_db
CREATE TABLE fsdb_regy
( fsdb_id integer NOT NULL PRIMARY KEY AUTOINCREMENT
, fsdb_name varchar(255) NOT NULL
, fsdb_is_orig tinyint NOT NULL
, fsdb_repo tinyint NOT NULL
, fsdb_w integer NOT NULL
, fsdb_time double NOT NULL
, fsdb_page integer NOT NULL
, fsdb_db_id integer NOT NULL
, fsdb_size bigint NOT NULL
, fsdb_status tinyint NOT NULL
, fsdb_fil_id integer NOT NULL
, fsdb_thm_id integer NOT NULL
, fsdb_deleted tinyint NOT NULL
);
--run in file.make
ATTACH 'simple.wikipedia.org-file-page_map.xowa' AS pfm_db;
INSERT INTO pfm_db.fsdb_regy SELECT * FROM fsdb_regy;
CREATE INDEX fsdb_regy__main ON fsdb_regy (fsdb_fil_id, fsdb_thm_id);
*/
}

@ -32,8 +32,8 @@ public class Xob_db_file {
public static Xob_db_file New__temp_log(Io_url dir) {return New(dir, Name__temp_log);}
public static Xob_db_file New__redlink(Io_url dir) {return New(dir, Name__redlink);}
public static Xob_db_file New__page_link(Xow_wiki wiki) {return New(wiki.Fsys_mgr().Root_dir(), Name__page_link);}
public static Xob_db_file New__img_link(Xow_wiki wiki) {return New(wiki.Fsys_mgr().Root_dir(), "xowa.wiki.imglinks.sqlite3");}
public static Xob_db_file New__page_file_map(Xow_wiki wiki) {return New(wiki.Fsys_mgr().Root_dir(), wiki.Domain_str() + "-file-page_map.xowa");}
public static Xob_db_file New__img_link(Xow_wiki wiki) {return New(wiki.Fsys_mgr().Root_dir(), "xowa.wiki.imglinks.sqlite3");}
public static Xob_db_file New__deletion_db(Xow_wiki wiki) {
String name = String_.Format("{0}-file-deletion-{1}.xowa", wiki.Domain_str(), Datetime_now.Get().XtoStr_fmt("yyyy.MM"));
return New(wiki.Fsys_mgr().Root_dir(), name);

Loading…
Cancel
Save