@@ -31,7 +31,12 @@ class JobExecution
31
31
/**
32
32
* @var array
33
33
*
34
- * @ORM\OneToMany(targetEntity="StepExecution", mappedBy="jobExecution")
34
+ * @ORM\OneToMany(
35
+ * targetEntity="StepExecution",
36
+ * mappedBy="jobExecution",
37
+ * cascade={"persist", "remove"},
38
+ * orphanRemoval=true
39
+ * )
35
40
*/
36
41
private $ stepExecutions ;
37
42
@@ -51,28 +56,28 @@ class JobExecution
51
56
private $ status ;
52
57
53
58
/**
54
- * @var DateTime
59
+ * @var \ DateTime
55
60
*
56
61
* @ORM\Column(name="start_time", type="datetime", nullable=true)
57
62
*/
58
63
private $ startTime ;
59
64
60
65
/**
61
- * @var DateTime
66
+ * @var \ DateTime
62
67
*
63
68
* @ORM\Column(name="end_time", type="datetime", nullable=true)
64
69
*/
65
70
private $ endTime ;
66
71
67
72
/**
68
- * @var DateTime
73
+ * @var \ DateTime
69
74
*
70
75
* @ORM\Column(name="create_time", type="datetime", nullable=true)
71
76
*/
72
77
private $ createTime ;
73
78
74
79
/**
75
- * @var DateTime
80
+ * @var \ DateTime
76
81
*
77
82
* @ORM\Column(name="updated_time", type="datetime", nullable=true)
78
83
*/
@@ -119,11 +124,25 @@ public function __construct()
119
124
{
120
125
$ this ->setStatus (new BatchStatus (BatchStatus::STARTING ));
121
126
$ this ->setExitStatus (new ExitStatus (ExitStatus::UNKNOWN ));
127
+ $ this ->executionContext = new ExecutionContext ();
122
128
$ this ->stepExecutions = new ArrayCollection ();
123
129
$ this ->createTime = new \DateTime ();
124
130
$ this ->failureExceptions = array ();
125
131
}
126
132
133
+ public function __clone ()
134
+ {
135
+ $ this ->id = null ;
136
+
137
+ if ($ this ->stepExecutions ) {
138
+ $ this ->stepExecutions = clone $ this ->stepExecutions ;
139
+ }
140
+
141
+ if ($ this ->executionContext ) {
142
+ $ this ->executionContext = clone $ this ->executionContext ;
143
+ }
144
+ }
145
+
127
146
/**
128
147
* Get Id
129
148
* @return integer
@@ -160,7 +179,7 @@ public function setExecutionContext(ExecutionContext $executionContext)
160
179
/**
161
180
* Returns the time that this execution ended
162
181
*
163
- * @return the time that this execution ended
182
+ * @return \DateTime the time that this execution ended
164
183
*/
165
184
public function getEndTime ()
166
185
{
@@ -184,7 +203,7 @@ public function setEndTime(\DateTime $endTime)
184
203
/**
185
204
* Gets the time this execution started
186
205
*
187
- * @return the time this execution started
206
+ * @return \DateTime the time this execution started
188
207
*/
189
208
public function getStartTime ()
190
209
{
@@ -207,7 +226,7 @@ public function setStartTime(\DateTime $startTime)
207
226
/**
208
227
* Gets the time this execution has been created
209
228
*
210
- * @return the time this execution has been created
229
+ * @return \DateTime the time this execution has been created
211
230
*/
212
231
public function getCreateTime ()
213
232
{
@@ -231,7 +250,7 @@ public function setCreateTime(\DateTime $createTime)
231
250
/**
232
251
* Gets the time this execution has been updated
233
252
*
234
- * @return the time this execution has been updated
253
+ * @return \DateTime time this execution has been updated
235
254
*/
236
255
public function getUpdatedTime ()
237
256
{
@@ -309,11 +328,11 @@ public function setExitStatus(ExitStatus $exitStatus)
309
328
}
310
329
311
330
/**
312
- * @return the exitCode
331
+ * @return ExitStatus exitCode
313
332
*/
314
333
public function getExitStatus ()
315
334
{
316
- if ($ this ->exitStatus === null and $ this ->exitCode !== null ) {
335
+ if ($ this ->exitStatus === null && $ this ->exitCode !== null ) {
317
336
$ this ->exitStatus = new ExitStatus ($ this ->exitCode );
318
337
}
319
338
@@ -323,7 +342,7 @@ public function getExitStatus()
323
342
/**
324
343
* Accessor for the step executions.
325
344
*
326
- * @return ArrayCollection the step executions that were registered
345
+ * @return ArrayCollection|StepExecution[] the step executions that were registered
327
346
*/
328
347
public function getStepExecutions ()
329
348
{
@@ -363,7 +382,7 @@ public function addStepExecution(StepExecution $stepExecution)
363
382
* be noted that this does not necessarily mean that it has been persisted
364
383
* as such yet.
365
384
*
366
- * @return true if the end time is null
385
+ * @return bool if the end time is null
367
386
*/
368
387
public function isRunning ()
369
388
{
@@ -373,7 +392,7 @@ public function isRunning()
373
392
/**
374
393
* Test if this JobExecution indicates that it has been signalled to
375
394
* stop.
376
- * @return true if the status is BatchStatus::STOPPING
395
+ * @return bool if the status is BatchStatus::STOPPING
377
396
*/
378
397
public function isStopping ()
379
398
{
@@ -387,6 +406,7 @@ public function isStopping()
387
406
*/
388
407
public function stop ()
389
408
{
409
+ /** @var StepExecution $stepExecution */
390
410
foreach ($ this ->stepExecutions as $ stepExecution ) {
391
411
$ stepExecution ->setTerminateOnly ();
392
412
}
@@ -406,7 +426,7 @@ public function getFailureExceptions()
406
426
407
427
/**
408
428
* Add a failure exception
409
- * @param Exception $e
429
+ * @param \ Exception $e
410
430
*
411
431
* @return JobExecution
412
432
*/
@@ -433,6 +453,7 @@ public function getAllFailureExceptions()
433
453
{
434
454
$ allExceptions = $ this ->failureExceptions ;
435
455
456
+ /** @var StepExecution $stepExecution */
436
457
foreach ($ this ->stepExecutions as $ stepExecution ) {
437
458
$ allExceptions = array_merge ($ allExceptions , $ stepExecution ->getFailureExceptions ());
438
459
}
@@ -443,21 +464,22 @@ public function getAllFailureExceptions()
443
464
/**
444
465
* Set the associated job
445
466
*
446
- * @param Job $job The job instance to associate the JobExecution to
467
+ * @param JobInstance $jobInstance The job instance to associate the JobExecution to
447
468
*
448
469
* @return JobExecution
449
470
*/
450
471
public function setJobInstance (JobInstance $ jobInstance )
451
472
{
452
473
$ this ->jobInstance = $ jobInstance ;
474
+ $ this ->jobInstance ->addJobExecution ($ this );
453
475
454
476
return $ this ;
455
477
}
456
478
457
479
/**
458
480
* Get the associated jobInstance
459
481
*
460
- * @return $job The job to which the JobExecution is associated
482
+ * @return JobInstance The job to which the JobExecution is associated
461
483
*/
462
484
public function getJobInstance ()
463
485
{
@@ -494,14 +516,13 @@ public function getLogFile()
494
516
*/
495
517
public function __toString ()
496
518
{
497
- $ string = "" ;
498
519
$ startTime = self ::formatDate ($ this ->startTime );
499
520
$ endTime = self ::formatDate ($ this ->endTime );
500
521
$ updatedTime = self ::formatDate ($ this ->updatedTime );
501
522
$ jobInstanceCode = $ this ->jobInstance != null ? $ this ->jobInstance ->getCode () : '' ;
502
523
503
524
$ message = "startTime=%s, endTime=%s, updatedTime=%s, status=%d, exitStatus=%s, exitDescription=[%s], job=[%s] " ;
504
- $ string = sprintf (
525
+ return sprintf (
505
526
$ message ,
506
527
$ startTime ,
507
528
$ endTime ,
@@ -511,15 +532,13 @@ public function __toString()
511
532
$ this ->exitDescription ,
512
533
$ jobInstanceCode
513
534
);
514
-
515
- return $ string ;
516
535
}
517
536
518
537
/**
519
538
* Format a date or return empty string if null
520
539
*
521
- * @param Datetime date
522
- * @param string dateformat
540
+ * @param \DateTime date
541
+ * @param string $format date format
523
542
*
524
543
* @return string Date formatted
525
544
*/
0 commit comments