Skip to content

Commit 356e457

Browse files
committed
Merge branch 'maintenance/pim_beta1' into override-job-configuration
Conflicts: src/Oro/Bundle/BatchBundle/Entity/StepExecution.php src/Oro/Bundle/BatchBundle/Step/ItemStep.php
2 parents cfde784 + f122083 commit 356e457

32 files changed

+1010
-170
lines changed

Command/BatchCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
8282
$jobExecution = new JobExecution();
8383
}
8484
$jobExecution->setJobInstance($jobInstance);
85+
8586
$job->execute($jobExecution);
8687

88+
$this->getEntityManager()->persist($jobInstance);
89+
$this->getEntityManager()->flush($jobInstance);
90+
8791
if (ExitStatus::COMPLETED === $jobExecution->getExitStatus()->getExitCode()) {
8892
$output->writeln(
8993
sprintf(

Connector/Connector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/**
88
* Connector bundle base class
99
*
10+
* @todo Refactor all related classes to remove manual extension from this class, then remove it
1011
*/
1112
class Connector extends Bundle
1213
{

Connector/ConnectorRegistry.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
use Oro\Bundle\BatchBundle\Entity\JobInstance;
77
use Oro\Bundle\BatchBundle\Job\JobFactory;
88
use Oro\Bundle\BatchBundle\Step\StepFactory;
9+
use Oro\Bundle\BatchBundle\Item\ItemReaderInterface;
10+
use Oro\Bundle\BatchBundle\Item\ItemProcessorInterface;
11+
use Oro\Bundle\BatchBundle\Item\ItemWriterInterface;
12+
use Oro\Bundle\BatchBundle\Job\Job;
913

1014
/**
1115
* Aims to register all connectors
@@ -31,9 +35,9 @@ public function __construct(JobFactory $jobFactory, StepFactory $stepFactory)
3135
/**
3236
* Get a registered job definition from a JobInstance
3337
*
34-
* @param Oro\Bundle\BatchBundle\Entity\JobInstance $jobInstance
35-
*
36-
* @return Oro\Bundle\BatchBundle\Job\JobInterface
38+
* @param JobInstance $jobInstance
39+
* @return JobInterface
40+
* @throws \LogicException
3741
*/
3842
public function getJob(JobInstance $jobInstance)
3943
{
@@ -45,13 +49,15 @@ public function getJob(JobInstance $jobInstance)
4549
return $job;
4650
}
4751
}
52+
53+
return null;
4854
}
4955

5056
/**
5157
* Get the list of jobs
5258
* @param string $type
5359
*
54-
* @return multitype:JobInterface
60+
* @return JobInterface[]
5561
*
5662
* TODO : Rather return an array of array of JobInterface ?
5763
*/
@@ -67,11 +73,11 @@ public function getJobs($type)
6773
* @param string $jobType
6874
* @param string $jobAlias
6975
* @param string $jobTitle
76+
* @param string $stepName
7077
* @param string $stepTitle
7178
* @param ItemReaderInterface $stepReader
7279
* @param ItemProcessorInterface $stepProcessor
7380
* @param ItemWriterInterface $stepWriter
74-
*
7581
* @return null
7682
*/
7783
public function addStepToJob(
@@ -88,9 +94,11 @@ public function addStepToJob(
8894
$this->jobs[$jobType][$jobConnector][$jobAlias] = $this->jobFactory->createJob($jobTitle);
8995
}
9096

91-
$this->jobs[$jobType][$jobConnector][$jobAlias]->addStep(
92-
$this->stepFactory->createStep($stepTitle, $stepReader, $stepProcessor, $stepWriter)
93-
);
97+
/** @var Job $job */
98+
$job = $this->jobs[$jobType][$jobConnector][$jobAlias];
99+
100+
$step = $this->stepFactory->createStep($stepTitle, $stepReader, $stepProcessor, $stepWriter);
101+
$job->addStep($stepTitle, $step);
94102
}
95103

96104
/**

DependencyInjection/Compiler/RegisterJobsPass.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@
99
use Symfony\Component\Yaml\Parser as YamlParser;
1010
use Symfony\Component\Config\Definition\Processor;
1111
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
12+
use Symfony\Component\Config\Definition\NodeInterface;
1213

1314
/**
1415
* Read the jobs.yml file of the connectors to register the jobs
1516
*
1617
*/
1718
class RegisterJobsPass implements CompilerPassInterface
1819
{
20+
/**
21+
* @var YamlParser
22+
*/
1923
protected $yamlParser;
2024

25+
/**
26+
* @var NodeInterface
27+
*/
2128
protected $jobsConfig;
2229

2330
public function __construct($yamlParser = null)
@@ -31,13 +38,15 @@ public function process(ContainerBuilder $container)
3138

3239
foreach ($container->getParameter('kernel.bundles') as $bundle) {
3340
$reflClass = new \ReflectionClass($bundle);
34-
if ($reflClass->isSubclassOf('Oro\\Bundle\\BatchBundle\\Connector\\Connector')) {
35-
if (false === $bundleDir = dirname($reflClass->getFileName())) {
36-
continue;
37-
}
38-
if (is_file($configFile = $bundleDir.'/Resources/config/jobs.yml')) {
39-
$this->registerJobs($registry, $configFile);
40-
}
41+
if (false === $bundleDir = dirname($reflClass->getFileName())) {
42+
continue;
43+
}
44+
// TODO: discuss using of only one file format
45+
if (is_file($configFile = $bundleDir.'/Resources/config/jobs.yml')) {
46+
$this->registerJobs($registry, $configFile);
47+
}
48+
if (is_file($configFile = $bundleDir.'/Resources/config/batch_jobs.yml')) {
49+
$this->registerJobs($registry, $configFile);
4150
}
4251
}
4352
}

Entity/JobExecution.php

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ class JobExecution
3131
/**
3232
* @var array
3333
*
34-
* @ORM\OneToMany(targetEntity="StepExecution", mappedBy="jobExecution")
34+
* @ORM\OneToMany(
35+
* targetEntity="StepExecution",
36+
* mappedBy="jobExecution",
37+
* cascade={"persist", "remove"},
38+
* orphanRemoval=true
39+
* )
3540
*/
3641
private $stepExecutions;
3742

@@ -51,28 +56,28 @@ class JobExecution
5156
private $status;
5257

5358
/**
54-
* @var DateTime
59+
* @var \DateTime
5560
*
5661
* @ORM\Column(name="start_time", type="datetime", nullable=true)
5762
*/
5863
private $startTime;
5964

6065
/**
61-
* @var DateTime
66+
* @var \DateTime
6267
*
6368
* @ORM\Column(name="end_time", type="datetime", nullable=true)
6469
*/
6570
private $endTime;
6671

6772
/**
68-
* @var DateTime
73+
* @var \DateTime
6974
*
7075
* @ORM\Column(name="create_time", type="datetime", nullable=true)
7176
*/
7277
private $createTime;
7378

7479
/**
75-
* @var DateTime
80+
* @var \DateTime
7681
*
7782
* @ORM\Column(name="updated_time", type="datetime", nullable=true)
7883
*/
@@ -119,11 +124,25 @@ public function __construct()
119124
{
120125
$this->setStatus(new BatchStatus(BatchStatus::STARTING));
121126
$this->setExitStatus(new ExitStatus(ExitStatus::UNKNOWN));
127+
$this->executionContext = new ExecutionContext();
122128
$this->stepExecutions = new ArrayCollection();
123129
$this->createTime = new \DateTime();
124130
$this->failureExceptions = array();
125131
}
126132

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+
127146
/**
128147
* Get Id
129148
* @return integer
@@ -160,7 +179,7 @@ public function setExecutionContext(ExecutionContext $executionContext)
160179
/**
161180
* Returns the time that this execution ended
162181
*
163-
* @return the time that this execution ended
182+
* @return \DateTime the time that this execution ended
164183
*/
165184
public function getEndTime()
166185
{
@@ -184,7 +203,7 @@ public function setEndTime(\DateTime $endTime)
184203
/**
185204
* Gets the time this execution started
186205
*
187-
* @return the time this execution started
206+
* @return \DateTime the time this execution started
188207
*/
189208
public function getStartTime()
190209
{
@@ -207,7 +226,7 @@ public function setStartTime(\DateTime $startTime)
207226
/**
208227
* Gets the time this execution has been created
209228
*
210-
* @return the time this execution has been created
229+
* @return \DateTime the time this execution has been created
211230
*/
212231
public function getCreateTime()
213232
{
@@ -231,7 +250,7 @@ public function setCreateTime(\DateTime $createTime)
231250
/**
232251
* Gets the time this execution has been updated
233252
*
234-
* @return the time this execution has been updated
253+
* @return \DateTime time this execution has been updated
235254
*/
236255
public function getUpdatedTime()
237256
{
@@ -309,11 +328,11 @@ public function setExitStatus(ExitStatus $exitStatus)
309328
}
310329

311330
/**
312-
* @return the exitCode
331+
* @return ExitStatus exitCode
313332
*/
314333
public function getExitStatus()
315334
{
316-
if ($this->exitStatus === null and $this->exitCode !== null) {
335+
if ($this->exitStatus === null && $this->exitCode !== null) {
317336
$this->exitStatus = new ExitStatus($this->exitCode);
318337
}
319338

@@ -323,7 +342,7 @@ public function getExitStatus()
323342
/**
324343
* Accessor for the step executions.
325344
*
326-
* @return ArrayCollection the step executions that were registered
345+
* @return ArrayCollection|StepExecution[] the step executions that were registered
327346
*/
328347
public function getStepExecutions()
329348
{
@@ -363,7 +382,7 @@ public function addStepExecution(StepExecution $stepExecution)
363382
* be noted that this does not necessarily mean that it has been persisted
364383
* as such yet.
365384
*
366-
* @return true if the end time is null
385+
* @return bool if the end time is null
367386
*/
368387
public function isRunning()
369388
{
@@ -373,7 +392,7 @@ public function isRunning()
373392
/**
374393
* Test if this JobExecution indicates that it has been signalled to
375394
* stop.
376-
* @return true if the status is BatchStatus::STOPPING
395+
* @return bool if the status is BatchStatus::STOPPING
377396
*/
378397
public function isStopping()
379398
{
@@ -387,6 +406,7 @@ public function isStopping()
387406
*/
388407
public function stop()
389408
{
409+
/** @var StepExecution $stepExecution */
390410
foreach ($this->stepExecutions as $stepExecution) {
391411
$stepExecution->setTerminateOnly();
392412
}
@@ -406,7 +426,7 @@ public function getFailureExceptions()
406426

407427
/**
408428
* Add a failure exception
409-
* @param Exception $e
429+
* @param \Exception $e
410430
*
411431
* @return JobExecution
412432
*/
@@ -433,6 +453,7 @@ public function getAllFailureExceptions()
433453
{
434454
$allExceptions = $this->failureExceptions;
435455

456+
/** @var StepExecution $stepExecution */
436457
foreach ($this->stepExecutions as $stepExecution) {
437458
$allExceptions = array_merge($allExceptions, $stepExecution->getFailureExceptions());
438459
}
@@ -443,21 +464,22 @@ public function getAllFailureExceptions()
443464
/**
444465
* Set the associated job
445466
*
446-
* @param Job $job The job instance to associate the JobExecution to
467+
* @param JobInstance $jobInstance The job instance to associate the JobExecution to
447468
*
448469
* @return JobExecution
449470
*/
450471
public function setJobInstance(JobInstance $jobInstance)
451472
{
452473
$this->jobInstance = $jobInstance;
474+
$this->jobInstance->addJobExecution($this);
453475

454476
return $this;
455477
}
456478

457479
/**
458480
* Get the associated jobInstance
459481
*
460-
* @return $job The job to which the JobExecution is associated
482+
* @return JobInstance The job to which the JobExecution is associated
461483
*/
462484
public function getJobInstance()
463485
{
@@ -494,14 +516,13 @@ public function getLogFile()
494516
*/
495517
public function __toString()
496518
{
497-
$string = "";
498519
$startTime = self::formatDate($this ->startTime);
499520
$endTime = self::formatDate($this ->endTime);
500521
$updatedTime = self::formatDate($this->updatedTime);
501522
$jobInstanceCode = $this->jobInstance != null ? $this->jobInstance->getCode() : '';
502523

503524
$message = "startTime=%s, endTime=%s, updatedTime=%s, status=%d, exitStatus=%s, exitDescription=[%s], job=[%s]";
504-
$string = sprintf(
525+
return sprintf(
505526
$message,
506527
$startTime,
507528
$endTime,
@@ -511,15 +532,13 @@ public function __toString()
511532
$this->exitDescription,
512533
$jobInstanceCode
513534
);
514-
515-
return $string;
516535
}
517536

518537
/**
519538
* Format a date or return empty string if null
520539
*
521-
* @param Datetime date
522-
* @param string dateformat
540+
* @param \DateTime date
541+
* @param string $format date format
523542
*
524543
* @return string Date formatted
525544
*/

0 commit comments

Comments
 (0)