Completed
Pull Request — master (#13)
by
unknown
10:24
created

Anonymizer.php ➔ sortEntityModels()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 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
            if (Mage::getModel($entityModelsConfig['class'])) {
34
                $entityModels[] = $entityModelsConfig['class'];
35
            }
36
        }
37
38
        return $entityModels;
39
    }
40
    protected function _sortEntityModelsConfig($entityModelsConfig)
41
    {
42
        function sortEntityModels($entityModel1, $entityModel2)
43
        {
44
            return strcmp($entityModel1['sort'], $entityModel2['sort']);
45
        }
46
47
        usort($entityModelsConfig, 'sortEntityModels');
48
        return $entityModelsConfig;
49
    }
50
    /**
51
     * @param resource $stream stream resource used for output (for example opened file pointer or STDOUT)
52
     */
53
    public function setOutputStream($stream)
54
    {
55
        $this->_updater->setOutputStream($stream);
56
    }
57
    /**
58
     * @param boolean $showProgress True if progress should be output (default is true)
59
     */
60
    public function setShowProgress($showProgress)
61
    {
62
        $this->_updater->setShowProgress($showProgress);
63
    }
64
    /**
65
     * @param $steps How often progress output should be refreshed (default is 1 = after every entity update; example: 10 = every 10 entity updates)
66
     */
67
    public function setProgressSteps($steps)
68
    {
69
        $this->_updater->setProgressSteps($steps);
70
    }
71
72
    public function anonymizeAll()
73
    {
74
        /** @var Varien_Db_Adapter_Interface $connection */
75
        $connection = Mage::getSingleton('core/resource')->getConnection('core_write');
76
        $connection->beginTransaction();
77
        try {
78
            foreach ($this->_getEntityModels() as $entityModelAlias) {
79
                /** @var IntegerNet_Anonymizer_Model_Bridge_Entity_Abstract $entityModel */
80
                $entityModel = Mage::getModel($entityModelAlias);
81
                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...
82
                    $this->_updater->update($collectionIterator, $entityModel);
83
                }
84
            }
85
            $connection->commit();
86
        } catch (\Exception $e) {
87
            $connection->rollBack();
88
            throw $e;
89
        }
90
    }
91
    public function anonymizeStore()
92
    {
93
        //TODO different locales per store
94
    }
95
    protected function _clearPaymentData()
96
    {
97
        //TODO UPDATE sales_flat_order_payment SET additional_data=NULL, additional_information=NULL
98
    }
99
}