/
MaintTrl.xxm
81 lines (71 loc) · 2.05 KB
/
MaintTrl.xxm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
[[/
########## ATTENTION ##########
Run this script selectivly (preferably not scheduled),
e.g. when the 'term pattern' has changed
]][[@txDefs,DataLank,txSession,txTerms,txFilterSql,]][[!
procedure FillTrl(const tbl,qry,objid:UTF8String;itype:TtxItemType);
var
qr:TQueryResult;
i,id:integer;
ids:TIdList;
desc:string;
begin
if Context.Connected then
begin
Context.Send(#13#10+string(tbl)+'('+txItemTypeName[itype]+')'#13#10);
ids:=TIdList.Create;
try
qr:=TQueryResult.Create(Session.DbCon,'SELECT id FROM '+tbl+qry,[]);
try
while qr.Read and Context.Connected do ids.Add(qr.GetInt('id'));
finally
qr.Free;
end;
for i:=0 to ids.Count-1 do
begin
qr:=TQueryResult.Create(Session.DbCon,'SELECT '+sqlDesc+', '+objid+' AS oid FROM '+tbl+' WHERE id='+IntToStrU(ids[i]),[]);
try
desc:=qr.GetStr('desc');
id:=qr.GetInt('oid');
finally
qr.Free;
end;
try
if desc<>'' then TermStore.StoreTerms(itype,ids[i],id,desc);
Context.Send(IntToStr(ids[i])+' ');
except
on e:Exception do
begin
Context.SendHTML('<br /><span style="color:red;">');
Context.Send(IntToStr(ids[i])+'['+e.ClassName+']"'+e.Message+'"');
Context.SendHTML('</span><br /> ');
end;
end;
end;
finally
ids.Free;
end;
end;
end;
<<div style="font-family:monospace;">>
CheckMaintProtect(Context);
if not Use_Terms then raise Exception.Create('Use_Terms not enabled');
Session.DbCon.BeginTrans;
try
Context.BufferSize:=0;
Context.Send('Clearing...');
Session.DbCon.Execute('DELETE FROM Trl',[]);
FillTrl('Obj','','id',itObj);
FillTrl('Tok','','obj_id',itTok);
FillTrl('Ref','','obj1_id',itRef);
FillTrl('Flt','','obj_id',itFilter);
FillTrl('Rpt',' WHERE toktype_id is null and reftype_id is null','obj_id',itReport);
FillTrl('Rlm','','0',itRealm);
Session.DbCon.CommitTrans;
except
Session.DbCon.RollbackTrans;
raise;
end;
<<br />
-- done
</div>