function ARC_rdf_store_keeper::consolidate_resources_on_ifp 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_ifp()
- 5 arc/ARC_rdf_store_keeper.php \ARC_rdf_store_keeper::consolidate_resources_on_ifp()
- 6.2 arc/ARC_rdf_store_keeper.php \ARC_rdf_store_keeper::consolidate_resources_on_ifp()
1 call to ARC_rdf_store_keeper::consolidate_resources_on_ifp()
File
- arc/
ARC_rdf_store_keeper.php, line 415
Class
Code
function consolidate_resources_on_ifp($p = "") {
if (!$p) {
return array(
"error" => "empty ifp",
);
}
$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.s, 10, 16) AS s, T1.s_type, CONV(T1.o, 10, 16) AS o" : "T1.s, T1.s_type, T1.o";
$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.o=" . $empty_id_sql . ") AND T1.o=T2.o AND NOT (T1.s=T2.s) ORDER BY T1.s_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);
$o_id = $row["o"];
$s_id = $row["s"];
/* use as canonical s */
$o_sql = $conv_id ? "CONV('" . $o_id . "', 16, 10)" : "'" . $o_id . "'";
$s_sql = $conv_id ? "CONV('" . $s_id . "', 16, 10)" : "'" . $s_id . "'";
$s_type = $row["s_type"];
@mysql_free_result($rs);
foreach ($tbls as $cur_tbl) {
$t_tbl = $prefix . "_" . $cur_tbl;
/* consolidate objects */
$sql = "UPDATE " . $t_tbl . " T2 LEFT JOIN " . $t_tbl . " T1 ON (T2.o=T1.s) SET T2.o=" . $s_sql . ", T2.o_type=" . $s_type . " WHERE T1.p=" . $p_sql . " AND T1.o=" . $o_sql;
$tmp = mysql_query($sql);
$o_count += mysql_affected_rows();
/* consolidate subjects */
$sql = "UPDATE " . $t_tbl . " SET s=" . $s_sql . ", s_type=" . $s_type . " WHERE p=" . $p_sql . " AND o=" . $o_sql;
$tmp = mysql_query($sql);
$s_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),
);
}