12 include_once (
'FDL/Class.Doc.php');
13 include_once (
'FDL/Class.DocFam.php');
14 include_once (
'FDL/Class.DocVaultIndex.php');
15 include_once (
'VAULT/Class.VaultFile.php');
21 $action->exitError(
"Database not found : action->dbaccess");
25 $action->exitError(sprintf(
"Could not get DbObj with dbaccess='%s'",
$dbaccess));
32 $usage->setDefinitionText(
"Re-initialize docrel table");
34 $parms[
'dryrun'] =
$usage->addEmptyParameter(
"dryrun",
"Only output SQL queries that would be executed");
35 if (
$parms[
'dryrun'] ==
'yes' ||
$parms[
'dryrun'] ===
true) {
41 $parms[
'famid'] =
$usage->addOptionalParameter(
"famid",
"Process all families (keyword 'all') or only a specific family (family name or family id)", array() ,
"all");
42 if (
$parms[
'famid'] !=
'all') {
43 if (!is_numeric(
$parms[
'famid'])) {
46 $action->exitError(sprintf(
"Could not find family '%s'",
$parms[
'famid']));
51 if (!is_object($fam) || !$fam->isAlive()) {
52 $action->exitError(sprintf(
"Family with id '%s' is not alive or not a valid family.",
$parms[
'famid']));
56 $parms[
'transaction'] =
$usage->addEmptyParameter(
"transaction",
"Execute whole operation in a single transaction");
57 if (
$parms[
'transaction'] ==
'yes' ||
$parms[
'transaction'] ===
true) {
58 $parms[
'transaction'] =
true;
60 $parms[
'transaction'] =
false;
63 $parms[
'realclean'] =
$usage->addHiddenParameter(
"realclean",
"Delete everything in docrel at the beginning of the operation - old yes/no");
64 $parms[
'softclean'] =
$usage->addEmptyParameter(
"softclean",
"Don't delete everything in decrel before begin operation");
66 if (
$parms[
'realclean'] ==
'yes' &&
$parms[
'famid'] ==
'all') {
67 $parms[
'realclean'] =
true;
69 if (
$parms[
'realclean'] ==
'no') {
70 $parms[
'realclean'] =
false;
80 $q->order_by =
'(docid, id)';
81 $q->AddQuery(
"type ~ '^docid'");
82 $q->AddQuery(
"usefor != 'Q'");
83 $q->AddQuery(
"id !~ '^:'");
84 if (is_numeric(
$parms[
'famid'])) {
85 $q->AddQuery(sprintf(
"docid = %s", pg_escape_string(
$parms[
'famid'])));
91 if (
$parms[
'transaction']) {
101 if (!
$parms[
'transaction']) {
111 $attrid = $attr[
"id"];
113 if (!
$parms[
'realclean']) {
117 print sprintf(
"-- Deleting relations for family '%s', attribute '%s'...\n",
$docid, $attrid);
118 $sql = sprintf(
"DELETE FROM docrel WHERE EXISTS (SELECT id FROM doc%s WHERE id = sinitid) AND type = '%s'", pg_escape_string(
$docid) , pg_escape_string($attrid));
122 print sprintf(
"-- Indexing family '%s', attribute '%s'...\n",
$docid, $attrid);
123 $sql = sprintf(
"SELECT docrelreindex(initid, %s, '%s') FROM doc%s WHERE %s IS NOT NULL AND locked != -1", pg_escape_string($attrid) , pg_escape_string($attrid) , pg_escape_string(
$docid) , pg_escape_string($attrid));
129 print sprintf(
"-- Deleting broken relations...\n");
130 sqlexec(
$o,
$parms,
"DELETE FROM docrel WHERE NOT EXISTS (SELECT id FROM docread WHERE id = cinitid)");
131 if (!
$parms[
'transaction']) {
135 print sprintf(
"-- Dropping docrel indexes...\n");
140 print sprintf(
"-- Recomputing cinitid...\n");
141 sqlexec(
$o,
$parms,
"UPDATE docrel SET cinitid = docread.initid FROM docread WHERE cinitid IS NOT NULL AND cinitid > 0 AND cinitid = docread.id AND docread.id != docread.initid");
143 print sprintf(
"-- Recomputing {stitle, ctitle, sicon, cicon}...\n");
145 UPDATE docrel SET stitle = s.title, ctitle = c.title, sicon = s.icon, cicon = c.icon, cinitid = c.initid
146 FROM docread AS s, docread AS c
149 sinitid = s.initid AND s.locked != -1
151 cinitid = c.initid AND c.locked != -1
155 docrel.stitle IS NULL
157 docrel.ctitle IS NULL
165 print sprintf(
"-- Re-creating docrel indexes...\n");
166 sqlexec(
$o,
$parms,
"CREATE INDEX docrel_u ON docrel (sinitid, cinitid, type)");
172 if (
$parms[
'transaction']) {
184 if (!preg_match(
'/;\s*$/',
$sql)) {
187 str_replace(
$sql,
'\\',
'\\\\');
193 error_log(sprintf(
"Error executing query [%s]: %s",
$sql,
$err));
if($parms['transaction']) sqlexec(&$dbobj, &$parms, $sql)
if(!is_object($o)) $parms
if(is_numeric($parms['famid'])) $attrList
new_Doc($dbaccess, $id= '', $latest=false)
getIdFromName($dbaccess, $name)
if($file) if($subject==""&&$file) if($subject=="") $err
Verify arguments for wsh programs.