|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* integer_net Magento Module |
|
4
|
|
|
* |
|
5
|
|
|
* @category IntegerNet |
|
6
|
|
|
* @package IntegerNet_Anonymizer |
|
7
|
|
|
* @copyright Copyright (c) 2015 integer_net GmbH (http://www.integer-net.de/) |
|
8
|
|
|
* @author Fabian Schmengler <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
class IntegerNet_Anonymizer_Model_Bridge_Iterator implements \IntegerNet\Anonymizer\Implementor\CollectionIterator |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Mage_Eav_Model_Entity_Collection_Abstract|Mage_Core_Model_Resource_Db_Collection_Abstract |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $_collection; |
|
16
|
|
|
/** |
|
17
|
|
|
* @var Mage_Core_Model_Resource_Iterator |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $_iterator; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string[] |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $_data; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var int Iteration counter |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $_iteration; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var int Iteration counter offset for chunking |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $_iterationOffset = 0; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct(Varien_Data_Collection_Db $collection) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->_collection = $collection; |
|
|
|
|
|
|
36
|
|
|
$this->_iterator = Mage::getResourceModel('core/iterator'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return Mage_Core_Model_Resource_Db_Collection_Abstract|Mage_Eav_Model_Entity_Collection_Abstract |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getCollection() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->_collection; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param callable $callable |
|
49
|
|
|
* @return mixed |
|
50
|
|
|
*/ |
|
51
|
|
|
function walk(/*callable*/ $callable) // PHP 5.3 |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$self = $this; // PHP 5.3 |
|
54
|
|
|
$this->_iterator->walk($this->_collection->getSelect(), array( |
|
55
|
|
|
function($args) use ($callable, $self) { |
|
56
|
|
|
$self->_setIteration($args['idx']); |
|
57
|
|
|
$self->_setRawData($args['row']); |
|
58
|
|
|
$callable($self); |
|
59
|
|
|
} |
|
60
|
|
|
)); |
|
61
|
|
|
$this->_afterWalk(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function _setRawData($data) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->_data = $data; |
|
67
|
|
|
} |
|
68
|
|
|
public function _setIteration($iteration) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->_iteration = $iteration; |
|
71
|
|
|
} |
|
72
|
|
|
public function setIterationOffset($offset) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->_iterationOffset = $offset; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Returns raw data from database |
|
79
|
|
|
* |
|
80
|
|
|
* @return mixed |
|
81
|
|
|
*/ |
|
82
|
|
|
function getRawData() |
|
|
|
|
|
|
83
|
|
|
{ |
|
84
|
|
|
return $this->_data; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Returns number of iteration |
|
89
|
|
|
* |
|
90
|
|
|
* @return int |
|
91
|
|
|
*/ |
|
92
|
|
|
function getIteration() |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
return $this->_iterationOffset + $this->_iteration; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Returns total size of collection |
|
99
|
|
|
* |
|
100
|
|
|
* @return mixed |
|
101
|
|
|
*/ |
|
102
|
|
|
function getSize() |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
|
|
return $this->_collection->getSize(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Additional processing at the end: |
|
109
|
|
|
* - update grid tables |
|
110
|
|
|
* |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function _afterWalk() |
|
114
|
|
|
{ |
|
115
|
|
|
$entityResource = $this->_collection->getResource(); |
|
116
|
|
|
if ($entityResource instanceof Mage_Sales_Model_Resource_Order_Abstract) { |
|
|
|
|
|
|
117
|
|
|
$entityResource->updateGridRecords($this->_collection->getAllIds()); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..