dbXapp
2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Toggle main menu visibility
Loading...
Searching...
No Matches
dbxProcess.class.php
Go to the documentation of this file.
1
<?php
2
3
class
dbxProcess
extends
dbxObj
{
4
5
protected
$_process_remember_modul
=
'dbxProcess'
;
6
7
public
function
clear
($section=
''
) {
8
if
(!$section) $section=
$this->_section
;
9
if
( $section) {
10
$this->
del_property
(
'*'
,$section);
11
}
else
{
12
$this->_properties=array();
13
}
14
}
15
16
17
public
function
add_norep
($content) {
18
$oTPL =
dbx
()->get_system_obj(
'dbxTPL'
);
19
if
(is_object($oTPL) && method_exists($oTPL,
'cleanup_optional_placeholders'
)) {
20
$content = $oTPL->cleanup_optional_placeholders((
string
)$content);
21
}
22
23
if
(isset($_SESSION[
'dbx'
][
'norep'
])) {
24
$xnorep=$_SESSION[
'dbx'
][
'norep'
];
25
if
(is_array($xnorep)) {
26
for
($i=0; $i < 2; $i++) {
// noreps can include noraps
27
foreach
($xnorep as $id => $norep) {
28
$xid=
'['
.$id.
']'
;
29
$content = str_replace($xid,$norep,$content);
30
}
31
}
32
}
33
}
34
return
$content;
35
}
36
37
protected
function
job_key
($key) {
38
$key = preg_replace(
'/[^A-Za-z0-9_.:-]+/'
,
'_'
, (
string
)$key);
39
$key = trim($key,
'_'
);
40
return
(strpos($key,
'dbxprocess_'
) === 0) ? $key :
'dbxprocess_'
. $key;
41
}
42
43
public
function
init_job
($key, $title =
''
, $tasks = array(), $meta = array()) {
44
$jobKey = $this->
job_key
($key);
45
$state = is_array($meta) ? $meta : array();
46
47
$state[
'proc_key'
] = $jobKey;
48
$state[
'title'
] = $title;
49
$state[
'tasks'
] = is_array($tasks) ? array_values($tasks) : array();
50
$state[
'status'
] = $state[
'status'
] ??
'running'
;
51
$state[
'percent'
] = $state[
'percent'
] ?? 0;
52
$state[
'step_percent'
] = $state[
'step_percent'
] ?? 0;
53
$state[
'task_pos'
] = $state[
'task_pos'
] ?? 0;
54
$state[
'step_pos'
] = $state[
'step_pos'
] ?? 0;
55
$state[
'message'
] = $state[
'message'
] ??
''
;
56
$state[
'started_at'
] = $state[
'started_at'
] ?? date(
'Y-m-d H:i:s'
);
57
$state[
'updated_at'
] = date(
'Y-m-d H:i:s'
);
58
59
$this->
set_job
($jobKey, $state);
60
return
$state;
61
}
62
63
public
function
get_job
($key) {
64
$state =
dbx
()->get_remember_var($this->
job_key
($key), array(), $this->_process_remember_modul);
65
return
is_array($state) ? $state : array();
66
}
67
68
public
function
set_job
($key, $state) {
69
if
(!is_array($state)) {
70
$state = array();
71
}
72
73
$jobKey = $this->
job_key
($key);
74
$state[
'proc_key'
] = $state[
'proc_key'
] ?? $jobKey;
75
$state[
'updated_at'
] = date(
'Y-m-d H:i:s'
);
76
dbx
()->set_remember_var($jobKey, $state, $this->_process_remember_modul);
77
return
$state;
78
}
79
80
public
function
clear_job
($key) {
81
dbx
()->set_remember_var($this->
job_key
($key), array(), $this->_process_remember_modul);
82
}
83
84
public
function
control_job
($key, $cmd) {
85
$jobKey = $this->
job_key
($key);
86
$cmd = strtolower(trim((
string
)$cmd));
87
88
if
($cmd ==
'restart'
) {
89
$this->
clear_job
($jobKey);
90
return
array(
91
'proc_key'
=> $jobKey,
92
'status'
=>
'reset'
,
93
'message'
=>
'process restarted'
,
94
'percent'
=> 0,
95
'step_percent'
=> 0,
96
'updated_at'
=> date(
'Y-m-d H:i:s'
),
97
);
98
}
99
100
$state = $this->
get_job
($jobKey);
101
if
(!$state) {
102
$state = array(
103
'proc_key'
=> $jobKey,
104
'status'
=>
'new'
,
105
'message'
=>
'no active state'
,
106
'percent'
=> 0,
107
'step_percent'
=> 0,
108
);
109
}
110
111
$status = $state[
'status'
] ??
'new'
;
112
113
if
($cmd ==
'pause'
&& !in_array($status, array(
'finished'
,
'error'
,
'canceled'
),
true
)) {
114
$state[
'status'
] =
'paused'
;
115
$state[
'paused_at'
] = date(
'Y-m-d H:i:s'
);
116
$state[
'message'
] =
'process paused'
;
117
} elseif (($cmd ==
'resume'
|| $cmd ==
'continue'
) && in_array($status, array(
'paused'
,
'canceled'
,
'new'
),
true
)) {
118
$state[
'status'
] =
'running'
;
119
$state[
'resumed_at'
] = date(
'Y-m-d H:i:s'
);
120
$state[
'message'
] = ($cmd ==
'continue'
) ?
'process continued'
:
'process resumed'
;
121
} elseif ($cmd ==
'cancel'
&& !in_array($status, array(
'finished'
,
'error'
),
true
)) {
122
$state[
'status'
] =
'canceled'
;
123
$state[
'canceled_at'
] = date(
'Y-m-d H:i:s'
);
124
$state[
'message'
] =
'process canceled'
;
125
}
126
127
return
$this->
set_job
($jobKey, $state);
128
}
129
130
131
public
function
fast_response
(
$response
,$interpreter=1) {
132
if
($interpreter) {
133
$oInterpreter=
dbx
()->get_system_obj(
"dbxInterpreter"
);
134
$response
=$oInterpreter->run(
$response
);
135
$response
=$this->
add_norep
(
$response
);
136
}
137
echo
'<br><br><br>'
.$response;
138
exit
;
139
}
140
141
142
143
public
function
process
() {
144
$empty=array();
145
$process =
$this->_section
;
146
$status =$this->
get_property
(
'status'
,
'next'
);
147
$processes=$this->
get_property
(
'processes'
,$empty);
148
$stepp =$this->
get_property
(
'stepp'
,-1);
149
$count
=count($processes);
150
151
152
153
154
if
($status==
'next'
) {
155
$stepp++;
156
$this->
set_property
(
'stepp'
,$stepp);
157
}
158
if
($stepp >
$count
) {
159
$status=
'end'
;
160
$stepp=
$count
;
161
}
162
163
//$content= "A-Count=($count) stepp=($stepp) status=($status) Process=($process)-B<br>";
164
$content=
'End'
;
165
if
(isset($processes[$stepp])) $content=$processes[$stepp];
166
167
if
($status==
'end'
) {
168
//dbx_debug("ENDE-Process");
169
$this->
clear
($this->_section);
170
}
171
dbx
()->debug(
"process ($process) return=($content)"
);
172
173
return
$content;
174
}
//
175
176
177
178
179
180
181
public
function
add
($process) {
182
$empty=array();
183
$processes=$this->
get_property
(
'processes'
,$empty);
184
$processes[]=$process;
185
$this->
set_property
(
'processes'
,$processes);
186
}
187
188
189
190
191
public
function
get_status
() {
192
return
$this->
get_property
(
'status'
,
'next'
);
193
}
194
195
196
public
function
init
($section) {
197
$this->_section=$section;
198
$this->
clear
($section);
199
}
200
201
public
function
run
($process=
''
,$content=1,$fast_response=1) {
202
if
(!$process) $process=
$this->_section
;
203
$this->_section=($process);
204
if
($content) {
205
$content =$this->
process
();
206
$processes=$this->
get_property
(
'processes'
);
207
$status =$this->
get_status
();
208
dbx
()->debug(
"#Prozess Prozess=($process) Status=($status) content=($content) status=($status)"
,$processes);
209
if
($fast_response) $this->
fast_response
($content);
210
return
$content;
211
}
else
{
212
$ok=$this->
get_status
();
213
return
$ok;
214
}
215
}
216
}
dbxObj
Gemeinsame Basisklasse fuer dbXapp-System-, Modul- und Include-Objekte.
Definition
dbxKernel.php:63
dbxObj\get_property
get_property($name, $default='', $section='', $modul='modul')
Liest eine Objekt- oder Session-Property.
Definition
dbxKernel.php:266
dbxObj\set_property
set_property($name, $value, $section='', $modul='modul')
Speichert eine Objekt- oder Session-Property.
Definition
dbxKernel.php:246
dbxObj\$_section
Public $_section
Definition
dbxKernel.php:66
dbxObj\del_property
del_property($name, $section='', $modul='modul')
Loescht eine Objekt- oder Session-Property.
Definition
dbxKernel.php:293
dbxProcess
Definition
dbxProcess.class.php:3
dbxProcess\set_job
set_job($key, $state)
Definition
dbxProcess.class.php:68
dbxProcess\clear
clear($section='')
Definition
dbxProcess.class.php:7
dbxProcess\add_norep
add_norep($content)
Definition
dbxProcess.class.php:17
dbxProcess\add
add($process)
Definition
dbxProcess.class.php:181
dbxProcess\job_key
job_key($key)
Definition
dbxProcess.class.php:37
dbxProcess\fast_response
fast_response($response, $interpreter=1)
Definition
dbxProcess.class.php:131
dbxProcess\run
run($process='', $content=1, $fast_response=1)
Definition
dbxProcess.class.php:201
dbxProcess\process
process()
Definition
dbxProcess.class.php:143
dbxProcess\init_job
init_job($key, $title='', $tasks=array(), $meta=array())
Definition
dbxProcess.class.php:43
dbxProcess\$_process_remember_modul
$_process_remember_modul
Definition
dbxProcess.class.php:5
dbxProcess\get_job
get_job($key)
Definition
dbxProcess.class.php:63
dbxProcess\init
init($section)
Definition
dbxProcess.class.php:196
dbxProcess\control_job
control_job($key, $cmd)
Definition
dbxProcess.class.php:84
dbxProcess\get_status
get_status()
Definition
dbxProcess.class.php:191
dbxProcess\clear_job
clear_job($key)
Definition
dbxProcess.class.php:80
$count
$count
Definition
generate_dbxapp_merch_mockups.php:270
exit
exit
Definition
index.php:532
$response
$response
Definition
index.php:518
dbx
DBX schema administration.
dbx
include
dbxProcess.class.php
Generated by
1.17.0