anonymizeAll()   A
last analyzed

Complexity

Conditions 4
Paths 14

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
nc 14
nop 0
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
11
class IntegerNet_Anonymizer_Model_Anonymizer
12
{
13
    /**
14
     * @var \IntegerNet\Anonymizer\Updater
15
     */
16
    protected $_updater;
17
18
    public function __construct()
19
    {
20
        $anonymizer = new \IntegerNet\Anonymizer\Anonymizer();
21
        $this->_updater = new \IntegerNet\Anonymizer\Updater($anonymizer);
22
    }
23
    protected function _getEntityModels()
24
    {
25
        $entityModelsConfigXml = Mage::getConfig()->getNode('global/integernet_anonymizer/entity_models');
26
27
        $entityModelsConfigArray = $entityModelsConfigXml->asArray();
28
        $entityModelsConfigArray = $this->_sortEntityModelsConfig($entityModelsConfigArray);
29
30
        $entityModels = [];
31
32
        foreach ($entityModelsConfigArray as $entityModelsConfig) {
33
            $entityModel = Mage::getModel($entityModelsConfig['class']);
34
            if ($entityModel instanceof IntegerNet_Anonymizer_Model_Bridge_Entity_Abstract
35
                && $entityModel->entityExists()) {
36
                $entityModels[] = $entityModelsConfig['class'];
37
            }
38
        }
39
40
        return $entityModels;
41
    }
42
    protected function _sortEntityModelsConfig($entityModelsConfig)
43
    {
44
        usort(
45
            $entityModelsConfig,
46
            function ($entityModel1, $entityModel2) {
47
                return strcmp($entityModel1['sort'], $entityModel2['sort']);
48
            }
49
        );
50
        return $entityModelsConfig;
51
    }
52
    /**
53
     * @param resource $stream stream resource used for output (for example opened file pointer or STDOUT)
54
     */
55
    public function setOutputStream($stream)
56
    {
57
        $this->_updater->setOutputStream($stream);
58
    }
59
    /**
60
     * @param boolean $showProgress True if progress should be output (default is true)
61
     */
62
    public function setShowProgress($showProgress)
63
    {
64
        $this->_updater->setShowProgress($showProgress);
65
    }
66
    /**
67
     * @param $steps How often progress output should be refreshed (default is 1 = after every entity update; example: 10 = every 10 entity updates)
68
     */
69
    public function setProgressSteps($steps)
70
    {
71
        $this->_updater->setProgressSteps($steps);
72
    }
73
74
    public function anonymizeAll()
75
    {
76
        /** @var Varien_Db_Adapter_Interface $connection */
77
        $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
78
        $connection->beginTransaction();
79
        try {
80
            foreach ($this->_getEntityModels() as $entityModelAlias) {
81
                /** @var IntegerNet_Anonymizer_Model_Bridge_Entity_Abstract $entityModel */
82
                $entityModel = Mage::getModel($entityModelAlias);
83
                while ($collectionIterator = $entityModel->getCollectionIterator()) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $collectionIterator is correct as $entityModel->getCollectionIterator() (which targets IntegerNet_Anonymizer_Mo...getCollectionIterator()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
84
                    $this->_updater->update($collectionIterator, $entityModel);
85
                }
86
            }
87
            $connection->commit();
88
        } catch (\Exception $e) {
89
            $connection->rollBack();
90
            throw $e;
91
        }
92
    }
93
    public function anonymizeStore()
94
    {
95
        //TODO different locales per store
96
    }
97
    protected function _clearPaymentData()
98
    {
99
        //TODO UPDATE sales_flat_order_payment SET additional_data=NULL, additional_information=NULL
100
    }
101
}