/
MaintRlm.xxm
70 lines (66 loc) · 1.92 KB
/
MaintRlm.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
[[@txDefs,txSession,Classes,DataLank,txFilter,txFilterSql,Variants,]][[!var
sl:TStringList;
qr:TQueryResult;
i,j,l,c,RlmID:integer;
f:TtxFilter;
fq:TtxSqlQueryFragments;
fx:string;
fs1:UTF8String;
]][[
Context.ContentType:='text/plain';
Context.BufferSize:=0;
CheckMaintProtect(Context);
sl:=TStringList.Create;
try
fx:=Context['f'].Value;
if fx='' then sl.LoadFromFile(ModulePath+'MaintRlm.txt');
for i:=0 to sl.Count-1 do if (sl[i]<>'') and not(AnsiChar(sl[i][1]) in [';','#']) then
begin
fx:=sl[i];
Context.SendHTML(' '+fx+#13#10);
l:=Length(fx);
j:=l;
while (j<>0) and (fx[j]<>':') do dec(j);
RlmID:=StrToInt(Trim(Copy(fx,j+1,l-j)));
c:=0;
f:=TtxFilter.Create;
fq:=TtxSqlQueryFragments.Create(itObj);
try
Context.SendHTML('Parse filter...'#13#10);
f.FilterExpression:=UTF8Encode(Trim(Copy(fx,1,j-1)));
if f.ParseError<>'' then
Context.SendHTML('PARSE_ERROR!!!'#13#10+f.ParseError+#13#10#13#10);
fq.AddFilter(f);
fq.Fields:='Obj.id';
fq.OrderBy:='';
fq.Where:='Obj.rlm_id<>'+IntToStrU(RlmID)+' AND ('+fq.Where+')';
//fq.GroupBy
fs1:=fq.SQL;
finally
f.Free;
fq.Free;
end;
Context.SendHTML('Run query...'#13#10);
try
qr:=TQueryResult.Create(Session.DbCon,fs1,[VarFromDateTime(Now-7.0)]);//TODO: from settings file!
try
Context.SendHTML('List objects...'#13#10);
while qr.Read and Context.Connected do
begin
Session.DbCon.Execute('UPDATE Obj SET rlm_id=? WHERE id=?',[RlmID,qr.GetInt('id')]);
inc(c);
end;
finally
qr.Free;
end;
except
on e:Exception do
Context.SendHTML('EXCEPTION!!!'#13#10+e.Message+#13#10#13#10);
end;
//TODO: to done realm: projects that only has done (or deleted) items
Context.SendHTML('('+IntToStr(c)+')---'#13#10#13#10);
end;
finally
sl.Free;
end;
Context.SendHTML('---'#13#10);