Skip to content

Commit 6c44dd5

Browse files
committed
Added step execution warning supports
Dropped support for (reader|filter|writer) specific warning.
1 parent d028017 commit 6c44dd5

File tree

4 files changed

+102
-87
lines changed

4 files changed

+102
-87
lines changed

Entity/StepExecution.php

Lines changed: 30 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,17 @@ class StepExecution
126126
/**
127127
* @var array
128128
*
129-
* @ORM\Column(name="errors", type="array", nullable=true)
129+
* @ORM\Column(name="errors", type="array")
130130
*/
131-
private $errors = null;
131+
private $errors = array();
132132

133133
/**
134134
* @var array
135135
*
136-
* @ORM\Column(name="reader_warnings", type="array", nullable=true)
136+
* @ORM\Column(name="warnings", type="array")
137137
*/
138-
private $readerWarnings = array();
138+
private $warnings = array();
139139

140-
/**
141-
* @var array
142-
*
143-
* @ORM\Column(name="filter_warnings", type="array", nullable=true)
144-
*/
145-
private $filterWarnings = array();
146-
147-
/**
148-
* @var array
149-
*
150-
* @ORM\Column(name="writer_warnings", type="array", nullable=true)
151-
*/
152-
private $writerWarnings = array();
153140

154141
/**
155142
* Constructor with mandatory properties.
@@ -266,32 +253,6 @@ public function incrementReadCount()
266253
$this->readCount++;
267254
}
268255

269-
/**
270-
* Add a reader warning
271-
*
272-
* @param string $reader
273-
* @param string $message
274-
* @param mixed $data
275-
*/
276-
public function addReaderWarning($reader, $message, $data)
277-
{
278-
$this->readerWarnings[] = array(
279-
'reader' => $reader,
280-
'reason' => $message,
281-
'data' => $data,
282-
);
283-
}
284-
285-
/**
286-
* Get the reader warnings
287-
*
288-
* @return array[]
289-
*/
290-
public function getReaderWarnings()
291-
{
292-
return $this->readerWarnings;
293-
}
294-
295256
/**
296257
* Returns the current number of items written for this execution
297258
*
@@ -324,32 +285,6 @@ public function incrementWriteCount()
324285
$this->writeCount++;
325286
}
326287

327-
/**
328-
* Add a writer warning
329-
*
330-
* @param string $writer
331-
* @param string $message
332-
* @param mixed $data
333-
*/
334-
public function addWriterWarning($writer, $message, $data)
335-
{
336-
$this->writerWarnings[] = array(
337-
'writer' => $writer,
338-
'reason' => $message,
339-
'data' => $data,
340-
);
341-
}
342-
343-
/**
344-
* Get the writer warnings
345-
*
346-
* @return array[]
347-
*/
348-
public function getWriterWarnings()
349-
{
350-
return $this->writerWarnings;
351-
}
352-
353288
/**
354289
* Returns the current number of items filtered out of this execution
355290
*
@@ -376,16 +311,6 @@ public function addFilterWarning($filter, $message, $data)
376311
);
377312
}
378313

379-
/**
380-
* Get the filter warnings
381-
*
382-
* @return array[]
383-
*/
384-
public function getFilterWarnings()
385-
{
386-
return $this->filterWarnings;
387-
}
388-
389314
/**
390315
* @return flag to indicate that an execution should halt
391316
*/
@@ -566,6 +491,32 @@ public function getErrors()
566491
return $this->errors;
567492
}
568493

494+
/**
495+
* Add a warning
496+
*
497+
* @param string $class
498+
* @param string $reason
499+
* @param mixed $item
500+
*/
501+
public function addWarning($class, $reason, $item)
502+
{
503+
$this->warnings[] = array(
504+
'class' => $class,
505+
'reason' => $reason,
506+
'item' => $item,
507+
);
508+
}
509+
510+
/**
511+
* Get the warnings
512+
*
513+
* @return array[]
514+
*/
515+
public function getWarnings()
516+
{
517+
return $this->warnings;
518+
}
519+
569520
/**
570521
* To string
571522
* @return string

Step/ItemStep.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ public function doExecute(StepExecution $stepExecution)
176176
continue;
177177
}
178178
} catch (InvalidItemException $e) {
179+
$stepExecution->addError(
180+
get_class($this->reader),
181+
$e->getMessage(),
182+
$e->getItem()
183+
);
184+
179185
$this->dispatchInvalidItemEvent(
180186
get_class($this->reader),
181187
$e->getMessage(),
@@ -197,6 +203,12 @@ public function doExecute(StepExecution $stepExecution)
197203
);
198204
}
199205
} catch (InvalidItemException $e) {
206+
$stepExecution->addError(
207+
get_class($this->processor),
208+
$e->getMessage(),
209+
$e->getItem()
210+
);
211+
200212
$this->dispatchInvalidItemEvent(
201213
get_class($this->processor),
202214
$e->getMessage(),
@@ -213,6 +225,12 @@ public function doExecute(StepExecution $stepExecution)
213225
$this->writer->write($itemsToWrite);
214226
$itemsToWrite = array();
215227
} catch (InvalidItemException $e) {
228+
$stepExecution->addError(
229+
get_class($this->writer),
230+
$e->getMessage(),
231+
$e->getItem()
232+
);
233+
216234
$this->dispatchInvalidItemEvent(
217235
get_class($this->processor),
218236
$e->getMessage(),
@@ -229,6 +247,12 @@ public function doExecute(StepExecution $stepExecution)
229247
$this->writer->write($itemsToWrite);
230248
$itemsToWrite = array();
231249
} catch (InvalidItemException $e) {
250+
$stepExecution->addError(
251+
get_class($this->writer),
252+
$e->getMessage(),
253+
$e->getItem()
254+
);
255+
232256
$this->dispatchInvalidItemEvent(
233257
get_class($this->processor),
234258
$e->getMessage(),

Tests/Unit/Entity/StepExecutionTest.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,33 @@ public function testToString()
168168
$this->assertEquals($expectedString, (string) $this->stepExecution);
169169
}
170170

171-
public function testAddReaderWarning()
171+
public function testAddWarning()
172172
{
173-
$reader = $this->getMock('Oro\Bundle\BatchBundle\Item\ItemReaderInterface');
174-
$reason = 'something is wrong';
175-
$data = array('foo' => 'bar');
176-
177-
$this->stepExecution->addReaderWarning($reader, $reason, $data);
173+
$this->stepExecution->addWarning(
174+
'Oro\Bundle\BatchBundle\Item\ItemReaderInterface',
175+
'something is wrong on line 1',
176+
array('foo' => 'bar')
177+
);
178+
$this->stepExecution->addWarning(
179+
'Oro\Bundle\BatchBundle\Item\ItemReaderInterface',
180+
'something is wrong on line 2',
181+
array('baz' => false)
182+
);
178183

179184
$this->assertEquals(
180-
array(array('reader' => $reader, 'reason' => $reason, 'data' => $data)),
181-
$this->stepExecution->getReaderWarnings()
185+
array(
186+
array(
187+
'class' => 'Oro\Bundle\BatchBundle\Item\ItemReaderInterface',
188+
'reason' => 'something is wrong on line 1',
189+
'item' => array('foo' => 'bar')
190+
),
191+
array(
192+
'class' => 'Oro\Bundle\BatchBundle\Item\ItemReaderInterface',
193+
'reason' => 'something is wrong on line 2',
194+
'item' => array('baz' => false)
195+
)
196+
),
197+
$this->stepExecution->getWarnings()
182198
);
183199
}
184200

Tests/Unit/Step/ItemStepTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ public function testDispatchReaderInvalidItemException()
192192
$this->itemStep->setProcessor($processor);
193193
$this->itemStep->setWriter($writer);
194194

195+
$stepExecution->expects($this->once())
196+
->method('addError')
197+
->with(
198+
get_class($reader),
199+
'The read item is invalid',
200+
array('foo' => 'bar')
201+
);
202+
195203
$this->itemStep->setBatchSize(5);
196204
$this->itemStep->execute($stepExecution);
197205
}
@@ -242,6 +250,14 @@ public function testDispatchProcessInvalidItemException()
242250
$this->itemStep->setProcessor($processor);
243251
$this->itemStep->setWriter($writer);
244252

253+
$stepExecution->expects($this->once())
254+
->method('addError')
255+
->with(
256+
get_class($processor),
257+
'The processed item is invalid',
258+
array('foo' => 'bar')
259+
);
260+
245261
$this->itemStep->setBatchSize(5);
246262
$this->itemStep->execute($stepExecution);
247263
}
@@ -295,6 +311,14 @@ public function testDispatchWriteInvalidItemException()
295311
$this->itemStep->setProcessor($processor);
296312
$this->itemStep->setWriter($writer);
297313

314+
$stepExecution->expects($this->once())
315+
->method('addError')
316+
->with(
317+
get_class($writer),
318+
'The written item is invalid',
319+
array('foo' => 'bar')
320+
);
321+
298322
$this->itemStep->setBatchSize(5);
299323
$this->itemStep->execute($stepExecution);
300324
}

0 commit comments

Comments
 (0)