Passed
Pull Request — master (#1)
by Grebenikov
04:34
created

getOrderDataUpdatedSinceLastRun()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 33
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 27
nc 2
nop 0
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Minubo\Persistence;
9
10
use Orm\Zed\Customer\Persistence\Map\SpyCustomerAddressTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Customer\Persist...CustomerAddressTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Orm\Zed\Customer\Persistence\Map\SpyCustomerTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Customer\Persist...Map\SpyCustomerTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Orm\Zed\Oms\Persistence\Map\SpyOmsOrderProcessTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Oms\Persistence\...OmsOrderProcessTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Orm\Zed\Oms\Persistence\Map\SpyOmsTransitionLogTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Oms\Persistence\...msTransitionLogTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Orm\Zed\ProductBundle\Persistence\Map\SpySalesOrderItemBundleTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\ProductBundle\Pe...OrderItemBundleTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Orm\Zed\Sales\Persistence\Map\SpySalesOrderAddressTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistenc...lesOrderAddressTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Orm\Zed\Sales\Persistence\Map\SpySalesOrderItemTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistenc...ySalesOrderItemTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Orm\Zed\Sales\Persistence\Map\SpySalesOrderTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistenc...p\SpySalesOrderTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Orm\Zed\Sales\Persistence\Map\SpySalesOrderTotalsTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistenc...alesOrderTotalsTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Orm\Zed\Sales\Persistence\Map\SpySalesShipmentTableMap;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistenc...pySalesShipmentTableMap was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Propel\Runtime\ActiveQuery\Criteria;
21
use Propel\Runtime\Formatter\ArrayFormatter;
22
use Spryker\Zed\Kernel\Persistence\AbstractRepository;
23
24
/**
25
 * @method \SprykerEco\Zed\Minubo\Persistence\MinuboPersistenceFactory getFactory()
26
 */
27
class MinuboRepository extends AbstractRepository implements MinuboRepositoryInterface
28
{
29
    const LAST_RUN_DATETIME_FORMAT = 'Y-m-d H:i:s.u';
30
31
    /**
32
     * @return null|string
33
     */
34
    public function getLastMinuboRunTime(): ?string
35
    {
36
        $lastRun = $this->getFactory()
37
            ->createMinuboRunQuery()
38
            ->orderByRanAt(Criteria::DESC)
39
            ->findOne();
40
41
        if ($lastRun) {
42
            return $lastRun->getRanAt(static::LAST_RUN_DATETIME_FORMAT);
43
        }
44
45
        return null;
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function getOrderDataUpdatedSinceLastRun(): array
52
    {
53
        $lastRunTime = $this->getLastMinuboRunTime();
54
55
        $query = $this->getFactory()
56
            ->getSalesOrderQuery()
57
            ->leftJoinWithOrderTotal()
58
            ->leftJoinWithLocale()
59
            ->leftJoinWithSpySalesShipment()
60
            ->leftJoinWithItem()
61
            ->useItemQuery(null, Criteria::LEFT_JOIN)
62
                ->leftJoinWithSalesOrderItemBundle()
63
                ->leftJoinWithProcess()
64
                ->leftJoinWithState()
65
                ->leftJoinWithTransitionLog()
66
            ->endUse()
67
            ->leftJoinBillingAddress('BillingAddress')
68
            ->with('BillingAddress')
69
            ->leftJoinShippingAddress('ShippingAddress')
70
            ->with('ShippingAddress')
71
            ->setFormatter(ArrayFormatter::class);
72
73
        if ($lastRunTime) {
74
            $query->addAnd(SpySalesOrderTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
75
            $query->addOr(SpySalesOrderTotalsTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
76
            $query->addOr(SpySalesOrderItemTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
77
            $query->addOr(SpySalesOrderItemBundleTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
78
            $query->addOr(SpyOmsOrderProcessTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
79
            $query->addOr(SpySalesShipmentTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
80
            $query->addOr(SpyOmsTransitionLogTableMap::COL_CREATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
81
        }
82
83
        return $query->find()->toArray();
84
    }
85
86
    /**
87
     * @return array
88
     */
89
    public function getCustomerDataUpdatedSinceLastRun(): array
90
    {
91
        $lastRunTime = $this->getLastMinuboRunTime();
92
93
        $query = $this->getFactory()
94
            ->getCustomerQuery()
95
            ->leftJoinWithLocale()
96
            ->leftJoinWithAddress()
97
            ->useAddressQuery(null, Criteria::LEFT_JOIN)
98
                ->leftJoinWithRegion()
99
                ->leftJoinWithCountry()
100
            ->endUse()
101
            ->setFormatter(ArrayFormatter::class);
102
103
        if ($lastRunTime) {
104
            $query->addAnd(SpyCustomerTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL)
105
                ->addOr(SpyCustomerAddressTableMap::COL_UPDATED_AT, $lastRunTime, Criteria::GREATER_EQUAL);
106
        }
107
        return $query->find()->toArray();
108
    }
109
}
110