Skip to content

Commit eae1121

Browse files
committed
Added output for shell
1 parent 4fcf9e4 commit eae1121

2 files changed

Lines changed: 103 additions & 34 deletions

File tree

app/code/community/IntegerNet/Anonymizer/Model/Anonymizer.php

Lines changed: 97 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
class IntegerNet_Anonymizer_Model_Anonymizer
1010
{
1111
protected $_unusedCustomerData = array();
12+
protected $_anonymizedCustomerIds = array();
13+
protected $_anonymizedCustomerAddressIds = array();
1214
protected $_anonymizedOrderIds = array();
1315
protected $_anonymizedOrderAddressIds = array();
1416
protected $_anonymizedQuoteIds = array();
@@ -30,6 +32,22 @@ public function anonymizeAll()
3032

3133
$this->_anonymizeRemainingOrders();
3234
$this->_anonymizeRemainingQuotes();
35+
36+
$this->_anonymizeRemainingOrderAddresses();
37+
$this->_anonymizeRemainingQuoteAddresses();
38+
}
39+
40+
public function getResults()
41+
{
42+
return array(
43+
'Customers' => sizeof($this->_anonymizedCustomerIds),
44+
'Customers Addresses' => sizeof($this->_anonymizedCustomerAddressIds),
45+
'Orders' => sizeof($this->_anonymizedOrderIds),
46+
'Order Addresses' => sizeof($this->_anonymizedOrderAddressIds),
47+
'Quotes' => sizeof($this->_anonymizedQuoteIds),
48+
'Quote Addresses' => sizeof($this->_anonymizedQuoteAddressIds),
49+
'Newsletter Subscribers' => sizeof($this->_anonymizedNewsletterSubscriberIds),
50+
);
3351
}
3452

3553
/**
@@ -63,6 +81,7 @@ protected function _anonymizeCustomer($customer)
6381
}
6482

6583
$customer->getResource()->save($customer);
84+
$this->_anonymizedCustomerIds[] = $customer->getId();
6685

6786
$this->_anonymizeQuotes($customer, $randomData);
6887
$this->_anonymizeOrders($customer, $randomData);
@@ -128,37 +147,6 @@ protected function _anonymizeRemainingOrders()
128147
}
129148
}
130149

131-
/**
132-
*
133-
*/
134-
protected function _anonymizeRemainingQuotes()
135-
{
136-
$quotes = Mage::getModel('sales/quote')
137-
->getCollection()
138-
->addFieldToFilter('entity_id', array('nin' => $this->_anonymizedQuoteIds));
139-
140-
foreach($quotes as $quote) {
141-
142-
/** @var $quote Mage_Sales_Model_Quote */
143-
$randomData = $this->_getRandomData();
144-
$this->_anonymizeQuote($quote, $randomData);
145-
146-
foreach($quote->getAddressesCollection() as $quoteAddress) {
147-
148-
/** @var $quoteAddress Mage_Sales_Model_Quote_Address */
149-
if ($quoteAddress->getCustomerFirstname() == $quote->getOrigData('customer_firstname')
150-
&& $quoteAddress->getCustomerLastname() == $quote->getOrigData('customer_lastname')) {
151-
152-
$newRandomData = $randomData;
153-
} else {
154-
$newRandomData = $this->_getRandomData();
155-
}
156-
157-
$this->_anonymizeQuoteAddress($quoteAddress, $newRandomData);
158-
}
159-
}
160-
}
161-
162150
/**
163151
* @param Mage_Sales_Model_Order $order
164152
* @param array $randomData
@@ -179,8 +167,13 @@ protected function _anonymizeOrder($order, $randomData)
179167
}
180168

181169
$order->getResource()->save($order);
182-
183170
$this->_anonymizedOrderIds[] = $order->getId();
171+
172+
/* @var $quote Mage_Sales_Model_Quote */
173+
$quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
174+
if ($quote->getId()) {
175+
$this->_anonymizeQuote($quote, $randomData);
176+
}
184177
}
185178

186179
/**
@@ -198,6 +191,37 @@ protected function _anonymizeQuotes($customer, $randomData)
198191
}
199192
}
200193

194+
/**
195+
*
196+
*/
197+
protected function _anonymizeRemainingQuotes()
198+
{
199+
$quotes = Mage::getModel('sales/quote')
200+
->getCollection()
201+
->addFieldToFilter('entity_id', array('nin' => $this->_anonymizedQuoteIds));
202+
203+
foreach($quotes as $quote) {
204+
205+
/** @var $quote Mage_Sales_Model_Quote */
206+
$randomData = $this->_getRandomData();
207+
$this->_anonymizeQuote($quote, $randomData);
208+
209+
foreach($quote->getAddressesCollection() as $quoteAddress) {
210+
211+
/** @var $quoteAddress Mage_Sales_Model_Quote_Address */
212+
if ($quoteAddress->getCustomerFirstname() == $quote->getOrigData('customer_firstname')
213+
&& $quoteAddress->getCustomerLastname() == $quote->getOrigData('customer_lastname')) {
214+
215+
$newRandomData = $randomData;
216+
} else {
217+
$newRandomData = $this->_getRandomData();
218+
}
219+
220+
$this->_anonymizeQuoteAddress($quoteAddress, $newRandomData);
221+
}
222+
}
223+
}
224+
201225
/**
202226
* @param Mage_Sales_Model_Quote $quote
203227
* @param array $randomData
@@ -218,7 +242,6 @@ protected function _anonymizeQuote($quote, $randomData)
218242
}
219243

220244
$quote->getResource()->save($quote);
221-
222245
$this->_anonymizedQuoteIds[] = $quote->getId();
223246
}
224247

@@ -265,6 +288,7 @@ protected function _anonymizeCustomerAddress($customerAddress, $randomData)
265288
}
266289

267290
$customerAddress->getResource()->save($customerAddress);
291+
$this->_anonymizedCustomerAddressIds[] = $customerAddress->getId();
268292

269293
$this->_anonymizeQuoteAddresses($customerAddress, $randomData);
270294
$this->_anonymizeOrderAddresses($customerAddress, $randomData);
@@ -285,6 +309,23 @@ protected function _anonymizeQuoteAddresses($customerAddress, $randomData)
285309
}
286310
}
287311

312+
/**
313+
*
314+
*/
315+
protected function _anonymizeRemainingQuoteAddresses()
316+
{
317+
$quoteAddresses = Mage::getModel('sales/quote_address')
318+
->getCollection()
319+
->addFieldToFilter('address_id', array('nin' => $this->_anonymizedOrderAddressIds));
320+
321+
foreach($quoteAddresses as $quoteAddress) {
322+
323+
/** @var $quoteAddress Mage_Sales_Model_Quote_Address */
324+
$randomData = $this->_getRandomData();
325+
$this->_anonymizeQuoteAddress($quoteAddress, $randomData);
326+
}
327+
}
328+
288329
/**
289330
* @param Mage_Sales_Model_Quote_Address $quoteAddress
290331
* @param array $randomData
@@ -323,6 +364,23 @@ protected function _anonymizeOrderAddresses($customerAddress, $randomData)
323364
}
324365
}
325366

367+
/**
368+
*
369+
*/
370+
protected function _anonymizeRemainingOrderAddresses()
371+
{
372+
$orderAddresses = Mage::getModel('sales/order_address')
373+
->getCollection()
374+
->addFieldToFilter('entity_id', array('nin' => $this->_anonymizedOrderAddressIds));
375+
376+
foreach($orderAddresses as $orderAddress) {
377+
378+
/** @var $orderAddress Mage_Sales_Model_Order_Address */
379+
$randomData = $this->_getRandomData();
380+
$this->_anonymizeOrderAddress($orderAddress, $randomData);
381+
}
382+
}
383+
326384
/**
327385
* @param Mage_Sales_Model_Order_Address $orderAddress
328386
* @param array $randomData
@@ -343,6 +401,12 @@ protected function _anonymizeOrderAddress($orderAddress, $randomData)
343401

344402
$orderAddress->getResource()->save($orderAddress);
345403
$this->_anonymizedOrderAddressIds[] = $orderAddress->getId();
404+
405+
/* @var $quoteAddress Mage_Sales_Model_Quote_Address */
406+
$quoteAddress = Mage::getModel('sales/quote_address')->load($orderAddress->getQuoteAddressId());
407+
if ($quoteAddress->getId()) {
408+
$this->_anonymizeQuoteAddress($quoteAddress, $randomData);
409+
}
346410
}
347411

348412
/**

shell/anonymizer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ class Mage_Shell_Anonymizer extends Mage_Shell_Abstract
4141
*/
4242
public function run()
4343
{
44-
Mage::getModel('anonymizer/anonymizer')->anonymizeAll();
44+
/** @var $anonymizer IntegerNet_Anonymizer_Model_Anonymizer */
45+
$anonymizer = Mage::getModel('anonymizer/anonymizer');
46+
$anonymizer->anonymizeAll();
47+
foreach($anonymizer->getResults() as $resultLabel => $resultCount) {
48+
echo 'Anonymized ' . $resultCount . ' ' . $resultLabel . ".\n";
49+
}
4550
}
4651

4752
/**

0 commit comments

Comments
 (0)