1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of YaEtl |
5
|
|
|
* (c) Fabrice de Stefanis / https://github.com/fab2s/YaEtl |
6
|
|
|
* This source file is licensed under the MIT license which you will |
7
|
|
|
* find in the LICENSE file or at https://opensource.org/licenses/MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace fab2s\YaEtl\Loaders; |
11
|
|
|
|
12
|
|
|
use fab2s\NodalFlow\Flows\FlowStatusInterface; |
13
|
|
|
use fab2s\NodalFlow\Nodes\NodeAbstract; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class LoaderAbstract |
17
|
|
|
*/ |
18
|
|
|
abstract class LoaderAbstract extends NodeAbstract implements LoaderInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* This is not a traversable |
22
|
|
|
* |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
protected $isATraversable = false; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Loader can return a value, though it is set |
29
|
|
|
* to false by default. If you need return values |
30
|
|
|
* from a loader, set this to true, and next nodes |
31
|
|
|
* will get the returned value as param. |
32
|
|
|
* |
33
|
|
|
* @var bool |
34
|
|
|
*/ |
35
|
|
|
protected $isAReturningVal = false; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* This is not a Flow |
39
|
|
|
* |
40
|
|
|
* @var bool |
41
|
|
|
*/ |
42
|
|
|
protected $isAFlow = false; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
protected $nodeIncrements = [ |
48
|
|
|
'num_load' => 'num_exec', |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Implement flush as noOp since it's not always |
53
|
|
|
* required. Besides, if you do implement it |
54
|
|
|
* while not performing any type of multi insert, |
55
|
|
|
* you will take the risk to insert the last record |
56
|
|
|
* twice if you do not pay attention. Because chances |
57
|
|
|
* are that flush() will be called each time load() |
58
|
|
|
* is called, and YaEtl does call flush() after the |
59
|
|
|
* extract loop ended. |
60
|
|
|
* |
61
|
|
|
* @param FlowStatusInterface|null $flowStatus the flush status, should only be set by |
62
|
|
|
* YaEtl to indicate last flush() call status |
63
|
|
|
* either : |
64
|
|
|
* - clean (`isClean()`): everything went well |
65
|
|
|
* - dirty (`isDirty()`): one extractor broke the flow |
66
|
|
|
* - exception (`isException()`): an exception was raised during the flow |
67
|
|
|
**/ |
68
|
|
|
public function flush(?FlowStatusInterface $flowStatus = null) |
69
|
|
|
{ |
70
|
|
|
/* |
71
|
|
|
* `if ($flowStatus !== null) { |
72
|
|
|
* // YaEtl's call to flush() |
73
|
|
|
* if ($flowStatus->isRunning()) { |
74
|
|
|
* // flow is running |
75
|
|
|
* } elseif ($flowStatus->isClean()) { |
76
|
|
|
* // everything went well |
77
|
|
|
* } elseif ($flowStatus->isDirty()) { |
78
|
|
|
* // a node broke the flow |
79
|
|
|
* } elseif ($flowStatus->isException()) { |
80
|
|
|
* // an exception was raised during the flow execution |
81
|
|
|
* } |
82
|
|
|
* } else { |
83
|
|
|
* // it should be you calling this method |
84
|
|
|
* // during the flow execution (multi insert) |
85
|
|
|
* }` |
86
|
|
|
*/ |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|