function ARC_rdf_store_keeper::consolidate_resources_on_fp in Taxonomy import/export via XML 6
Same name and namespace in other branches
- 5.2 arc/ARC_rdf_store_keeper.php \ARC_rdf_store_keeper::consolidate_resources_on_fp()
- 5 arc/ARC_rdf_store_keeper.php \ARC_rdf_store_keeper::consolidate_resources_on_fp()
- 6.2 arc/ARC_rdf_store_keeper.php \ARC_rdf_store_keeper::consolidate_resources_on_fp()
1 call to ARC_rdf_store_keeper::consolidate_resources_on_fp()
File
- arc/
ARC_rdf_store_keeper.php, line 468
Class
Code
function consolidate_resources_on_fp($p = "") {
if (!$p) {
return array(
"error" => "empty fp",
);
}
$ps = is_array($p) ? $p : array(
$p,
);
$tbls = $this->api
->get_triple_tables();
$prefix = $this->config["prefix"];
$id_type = $this->config["id_type"];
$conv_p = $id_type == "hash_int" ? true : false;
$conv_id = in_array($id_type, array(
"hash_int",
"incr_int",
));
$o_count = 0;
$s_count = 0;
$t1 = $this->api
->get_mtime();
$this->api
->lock_tables();
$main_tbl = $this->config["store_type"] == "split" ? $prefix . "_triple_all" : $prefix . "_triple";
$empty_id_sql = $this->api
->get_id("", 1);
foreach ($ps as $p) {
$p_sql = $this->api
->get_id($p, 1);
do {
$proceed = false;
$cur_col_code = $conv_id ? "CONV(T1.o, 10, 16) AS o, T1.o_type, CONV(T1.s, 10, 16) AS s" : "T1.o, T1.o_type, T1.s";
$sql = "SELECT DISTINCT " . $cur_col_code . " FROM " . $main_tbl . " T1, " . $main_tbl . " T2 WHERE T1.p=" . $p_sql . " AND T2.p=" . $p_sql . " AND NOT (T1.s=" . $empty_id_sql . ") AND T1.s=T2.s AND NOT (T1.o=T2.o) ORDER BY T1.o_type ASC LIMIT 2";
if (($rs = mysql_query($sql)) && ($row_count = mysql_num_rows($rs)) && $row_count > 1) {
$proceed = true;
$row = mysql_fetch_array($rs);
$s_id = $row["s"];
$o_id = $row["o"];
/* use as canonical o */
$s_sql = $conv_id ? "CONV('" . $s_id . "', 16, 10)" : "'" . $s_id . "'";
$o_sql = $conv_id ? "CONV('" . $o_id . "', 16, 10)" : "'" . $o_id . "'";
$o_type = $row["o_type"];
@mysql_free_result($rs);
foreach ($tbls as $cur_tbl) {
$t_tbl = $prefix . "_" . $cur_tbl;
/* consolidate subject */
$sql = "UPDATE " . $t_tbl . " T2 LEFT JOIN " . $t_tbl . " T1 ON (T2.s=T1.o) SET T2.s=" . $o_sql . ", T2.s_type=" . $o_type . " WHERE T1.p=" . $p_sql . " AND T1.s=" . $s_sql;
$tmp = mysql_query($sql);
$s_count += mysql_affected_rows();
/* consolidate objects */
$sql = "UPDATE " . $t_tbl . " SET o=" . $o_sql . ", o_type=" . $o_type . " WHERE p=" . $p_sql . " AND s=" . $s_sql;
$tmp = mysql_query($sql);
$o_count += mysql_affected_rows();
}
}
} while ($proceed);
}
$t2 = $this->api
->get_mtime();
$this->api
->unlock_tables();
$t3 = $this->api
->get_mtime();
return array(
"subject_count" => $s_count,
"object_count" => $o_count,
"processing_time" => round($t2 - $t1, 4),
"index_update_time" => round($t3 - $t2, 4),
);
}