Completed
Push — master ( 5bcafe...c5dea9 )
by Tim
13s
created

SqlStatements::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\UrlRewrite\Utils\SqlStatements
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-product-url-rewrite
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\UrlRewrite\Utils;
22
23
/**
24
 * Utility class with the SQL statements to use.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2016 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/techdivision/import-product-url-rewrite
30
 * @link      http://www.techdivision.com
31
 */
32
class SqlStatements extends \TechDivision\Import\Product\Utils\SqlStatements
33
{
34
35
    /**
36
     * The SQL statement to create new URL rewrites.
37
     *
38
     * @var string
39
     */
40
    const CREATE_URL_REWRITE = 'create.url_rewrite';
41
42
    /**
43
     * The SQL statement to update an existing URL rewrite.
44
     *
45
     * @var string
46
     */
47
    const UPDATE_URL_REWRITE = 'update.url_rewrite';
48
49
    /**
50
     * The SQL statement to create new URL rewrite product category relations.
51
     *
52
     * @var string
53
     */
54
    const CREATE_URL_REWRITE_PRODUCT_CATEGORY = 'create.url_rewrite_product_category';
55
56
    /**
57
     * The SQL statement to update an existing URL rewrite product category relation.
58
     *
59
     * @var string
60
     */
61
    const UPDATE_URL_REWRITE_PRODUCT_CATEGORY = 'update.url_rewrite_product_category';
62
63
    /**
64
     * The SQL statement to remove a existing URL rewrite product category relation.
65
     *
66
     * @var string
67
     */
68
    const DELETE_URL_REWRITE_PRODUCT_CATEGORY = 'delete.url_rewrite_product_category';
69
70
    /**
71
     * The SQL statement to load the URL rewrite product category relation with the passed ID.
72
     *
73
     * @var string
74
     */
75
    const URL_REWRITE_PRODUCT_CATEGORY = 'ur_rewrite_product_category';
76
77
    /**
78
     * The SQL statement to load the URL rewrites by a SKU.
79
     *
80
     * @var string
81
     */
82
    const URL_REWRITES_BY_SKU = 'ur_rewrites.by.sku';
83
84
    /**
85
     * The SQL statement to load the URL rewrite product category relations for the passed SKU.
86
     *
87
     * @var string
88
     */
89
    const URL_REWRITE_PRODUCT_CATEGORIES_BY_SKU = 'ur_rewrite_product_categories.by.sku';
90
91
    /**
92
     * The SQL statements.
93
     *
94
     * @var array
95
     */
96
    private $statements = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
97
        SqlStatements::CREATE_URL_REWRITE =>
98
            'INSERT
99
               INTO url_rewrite
100
                    (entity_type,
101
                     entity_id,
102
                     request_path,
103
                     target_path,
104
                     redirect_type,
105
                     store_id,
106
                     description,
107
                     is_autogenerated,
108
                     metadata)
109
            VALUES (:entity_type,
110
                    :entity_id,
111
                    :request_path,
112
                    :target_path,
113
                    :redirect_type,
114
                    :store_id,
115
                    :description,
116
                    :is_autogenerated,
117
                    :metadata)',
118
        SqlStatements::UPDATE_URL_REWRITE =>
119
            'UPDATE url_rewrite
120
                SET entity_type = :entity_type,
121
                    entity_id = :entity_id,
122
                    request_path = :request_path,
123
                    target_path = :target_path,
124
                    redirect_type = :redirect_type,
125
                    store_id = :store_id,
126
                    description = :description,
127
                    is_autogenerated = :is_autogenerated,
128
                    metadata = :metadata
129
              WHERE url_rewrite_id = :url_rewrite_id',
130
        SqlStatements::CREATE_URL_REWRITE_PRODUCT_CATEGORY =>
131
            'INSERT
132
               INTO catalog_url_rewrite_product_category
133
                    (url_rewrite_id,
134
                     category_id,
135
                     product_id)
136
             VALUES (:url_rewrite_id,
137
                     :category_id,
138
                     :product_id)',
139
        SqlStatements::UPDATE_URL_REWRITE_PRODUCT_CATEGORY =>
140
            'UPDATE catalog_url_rewrite_product_category
141
                SET category_id = :category_id,
142
                    product_id = :product_id
143
              WHERE url_rewrite_id = :url_rewrite_id',
144
        SqlStatements::DELETE_URL_REWRITE_PRODUCT_CATEGORY =>
145
            'DELETE
146
               FROM catalog_url_rewrite_product_category
147
              WHERE url_rewrite_id = :url_rewrite_id',
148
        SqlStatements::URL_REWRITE_PRODUCT_CATEGORY =>
149
            'SELECT *
150
               FROM catalog_url_rewrite_product_category
151
              WHERE url_rewrite_id = :url_rewrite_id',
152
        SqlStatements::URL_REWRITES_BY_SKU =>
153
            'SELECT t2.*
154
               FROM catalog_product_entity t1,
155
                    url_rewrite t2
156
              WHERE t1.sku = :sku
157
                AND t2.entity_id = t1.entity_id
158
                AND t2.entity_type = \'product\'',
159
        SqlStatements::URL_REWRITE_PRODUCT_CATEGORIES_BY_SKU =>
160
            'SELECT t3.*
161
               FROM catalog_product_entity t1,
162
                    url_rewrite t2,
163
                    catalog_url_rewrite_product_category t3
164
              WHERE t1.sku = :sku
165
                AND t2.entity_id = t1.entity_id
166
                AND t2.entity_type = \'product\'
167
                AND t3.url_rewrite_id = t2.url_rewrite_id'
168
    );
169
170
    /**
171
     * Initialize the the SQL statements.
172
     */
173
    public function __construct()
174
    {
175
176
        // call the parent constructor
177
        parent::__construct();
178
179
        // merge the class statements
180
        foreach ($this->statements as $key => $statement) {
181
            $this->preparedStatements[$key] = $statement;
182
        }
183
    }
184
}
185