getOrderDataUpdatedSinceLastRun()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 33
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

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