Completed
Pull Request — master (#10)
by
unknown
02:49
created
Classes/Service/Targets/InsertUpdateTable.php 5 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -136,6 +136,7 @@
 block discarded – undo
136 136
      *
137 137
      * Fetch all records from the target table, where the PID equals the PID specified in the target section of the strategy 
138 138
      *
139
+     * @param string $selectFields
139 140
      * @return void
140 141
      */
141 142
     public function getRecords($selectFields)
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,6 @@
 block discarded – undo
2 2
 namespace HDNET\Importr\Service\Targets;
3 3
 
4 4
 use HDNET\Importr\Domain\Model\Strategy;
5
-use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
6
-use HDNET\Importr\Utility;
7 5
 
8 6
   /**
9 7
   * Imports records from a .CSV file into the target table which you can specify on the target section in your strategy.
Please login to merge, or discard this patch.
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -5,49 +5,49 @@  discard block
 block discarded – undo
5 5
 use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
6 6
 use HDNET\Importr\Utility;
7 7
 
8
-  /**
9
-  * Imports records from a .CSV file into the target table which you 
10
-	* can specify on the target section in your strategy.
11
-  * If a record does not exist in the table, it will be inserted, 
12
-	* otherwise it will be just updated. No duplicates are created.
13
-  *
14
-  * complete example (strategy target):
15
-  *
16
-  * HDNET\Importr\Service\Targets\InsertUpdateTable:
17
-  *   model: TYPO3\CMS\Extbase\Domain\Model\FrontendUser
18
-  *   repository: TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
19
-  *   target_table: fe_users
20
-  *   exclude_from_update:
21
-  *     0: password
22
-  *     1: first_name
23
-  *     2: zip
24
-  *   pid: 324
25
-  *   mapping:
26
-  *     0: username
27
-  *     1: password
28
-  *     2: usergroup
29
-  *     3: name
30
-  *     4: first_name
31
-  *     5: address
32
-  *     6: telephone
33
-  *     7: email
34
-  *     8: zip
35
-  *     9: city
36
-  *     10: company
37
-  *     
38
-  * Example CSV:
39
-  *
40
-  * username;password;usergroup;name;first_name;address;telephone;email;zip;city;company
41
-  * EduardFekete;BestPwEU1234;3;Fekete;Eduard; Mystreet 21; +049123456789;[email protected];91550;Feuchtwangen;MB Connect Line GmbH
42
-  * HansVader;SecondBestPwEU1234;3;Vader;Hans; Hisstreet 22; +049123456710;[email protected];99900;Universe;Hollywood Studios
43
-  *
44
-  * ------------------------------------------------------------------------------------------------
45
-  *
46
-  *   exclude_from_update:    the elements specified in this array, are never being updated
47
-  *
48
-  * ------------------------------------------------------------------------------------------------
49
-  * @author Eduard Fekete
50
-  */
8
+    /**
9
+     * Imports records from a .CSV file into the target table which you 
10
+     * can specify on the target section in your strategy.
11
+     * If a record does not exist in the table, it will be inserted, 
12
+     * otherwise it will be just updated. No duplicates are created.
13
+     *
14
+     * complete example (strategy target):
15
+     *
16
+     * HDNET\Importr\Service\Targets\InsertUpdateTable:
17
+     *   model: TYPO3\CMS\Extbase\Domain\Model\FrontendUser
18
+     *   repository: TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
19
+     *   target_table: fe_users
20
+     *   exclude_from_update:
21
+     *     0: password
22
+     *     1: first_name
23
+     *     2: zip
24
+     *   pid: 324
25
+     *   mapping:
26
+     *     0: username
27
+     *     1: password
28
+     *     2: usergroup
29
+     *     3: name
30
+     *     4: first_name
31
+     *     5: address
32
+     *     6: telephone
33
+     *     7: email
34
+     *     8: zip
35
+     *     9: city
36
+     *     10: company
37
+     *     
38
+     * Example CSV:
39
+     *
40
+     * username;password;usergroup;name;first_name;address;telephone;email;zip;city;company
41
+     * EduardFekete;BestPwEU1234;3;Fekete;Eduard; Mystreet 21; +049123456789;[email protected];91550;Feuchtwangen;MB Connect Line GmbH
42
+     * HansVader;SecondBestPwEU1234;3;Vader;Hans; Hisstreet 22; +049123456710;[email protected];99900;Universe;Hollywood Studios
43
+     *
44
+     * ------------------------------------------------------------------------------------------------
45
+     *
46
+     *   exclude_from_update:    the elements specified in this array, are never being updated
47
+     *
48
+     * ------------------------------------------------------------------------------------------------
49
+     * @author Eduard Fekete
50
+     */
51 51
 
52 52
 class InsertUpdateTable extends AbstractTarget implements TargetInterface
53 53
 {
@@ -180,13 +180,13 @@  discard block
 block discarded – undo
180 180
         $GLOBALS['TYPO3_DB']->sql_insert_id();
181 181
     }
182 182
 
183
-     /**
184
-     * Update a record in the target table which you have specified in the target section of the strategy (don't update the password)
185
-     *
186
-     * @param array $entry
187
-     *
188
-     * @return void
189
-     */
183
+        /**
184
+         * Update a record in the target table which you have specified in the target section of the strategy (don't update the password)
185
+         *
186
+         * @param array $entry
187
+         *
188
+         * @return void
189
+         */
190 190
     public function updateRecord(array $entry)
191 191
     {
192 192
         $into_table       = $this->configuration['target_table'];
@@ -207,14 +207,14 @@  discard block
 block discarded – undo
207 207
     }
208 208
 
209 209
     /**
210
-    * This function creates a duplicate of a associative array and optionally removes
211
-    * any entries which are also elements of a second array
212
-    *
213
-    * @param array $arr
214
-    * @param array $exclude_arr
215
-    *
216
-    * @return array
217
-    */
210
+     * This function creates a duplicate of a associative array and optionally removes
211
+     * any entries which are also elements of a second array
212
+     *
213
+     * @param array $arr
214
+     * @param array $exclude_arr
215
+     *
216
+     * @return array
217
+     */
218 218
     public function duplicateArray(array $arr, array $exclude_arr = null)
219 219
     {
220 220
         $exclude = false;
Please login to merge, or discard this patch.
Spacing   +15 added lines, -16 removed lines patch added patch discarded remove patch
@@ -106,16 +106,16 @@  discard block
 block discarded – undo
106 106
         $record_exists    = false;
107 107
         $entry_username   = $entry['0'];
108 108
 
109
-        $this->configuration    = $this->getConfiguration();
109
+        $this->configuration = $this->getConfiguration();
110 110
 
111 111
         if ($this->firstTime == "1") {
112 112
             $this->firstTime = 0;
113 113
             $this->getRecords("*");
114 114
         }
115 115
 
116
-        foreach ($this->table_records as $record){
117
-            if ($record['deleted'] == 0){
118
-                if ($record['username'] == $entry_username){
116
+        foreach ($this->table_records as $record) {
117
+            if ($record['deleted'] == 0) {
118
+                if ($record['username'] == $entry_username) {
119 119
                     $record_exists = true;
120 120
                     break;
121 121
                 }
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
             }
126 126
         }
127 127
 
128
-        if ($record_exists){
128
+        if ($record_exists) {
129 129
             $this->updateRecord($entry);
130 130
             return TargetInterface::RESULT_UPDATE;
131 131
         }
@@ -144,12 +144,11 @@  discard block
 block discarded – undo
144 144
     public function getRecords($selectFields)
145 145
     {
146 146
         $fromTable        = $this->configuration['target_table'];
147
-        $whereStatement   = "pid = '".$this->configuration['pid']."'";
147
+        $whereStatement   = "pid = '" . $this->configuration['pid'] . "'";
148 148
 
149 149
         $GLOBALS['TYPO3_DB']->store_lastBuiltQuery = 1;
150 150
 
151
-        $this->table_records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows
152
-        (
151
+        $this->table_records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
153 152
             $selectFields,
154 153
             $fromTable,
155 154
             $whereStatement
@@ -168,7 +167,7 @@  discard block
 block discarded – undo
168 167
         $field_values       = array();
169 168
         $into_table         = $this->configuration['target_table'];
170 169
 
171
-        foreach ($this->configuration["mapping"] as $key => $value){
170
+        foreach ($this->configuration["mapping"] as $key => $value) {
172 171
             $field_values[$value] = $entry[$key];
173 172
         }
174 173
 
@@ -176,7 +175,7 @@  discard block
 block discarded – undo
176 175
         $field_values['tstamp']   = time();
177 176
         $field_values['crdate']   = time();
178 177
               
179
-        $GLOBALS['TYPO3_DB']->exec_INSERTquery( $into_table, $field_values);
178
+        $GLOBALS['TYPO3_DB']->exec_INSERTquery($into_table, $field_values);
180 179
         $GLOBALS['TYPO3_DB']->sql_insert_id();
181 180
     }
182 181
 
@@ -190,19 +189,19 @@  discard block
 block discarded – undo
190 189
     public function updateRecord(array $entry)
191 190
     {
192 191
         $into_table       = $this->configuration['target_table'];
193
-        $whereStatement   = "pid = '".$this->configuration['pid']."' AND username = '".$entry[0]."'";
192
+        $whereStatement   = "pid = '" . $this->configuration['pid'] . "' AND username = '" . $entry[0] . "'";
194 193
                            
195 194
         $field_values     = array();
196 195
         $tmp_arr          = array();
197 196
 
198
-        foreach ($this->configuration["mapping"] as $key => $value){
197
+        foreach ($this->configuration["mapping"] as $key => $value) {
199 198
             $tmp_arr[$value] = $entry[$key];
200 199
         }
201 200
 
202
-        $field_values = $this->duplicateArray($tmp_arr,$this->configuration['exclude_from_update']);
201
+        $field_values = $this->duplicateArray($tmp_arr, $this->configuration['exclude_from_update']);
203 202
         $field_values['tstamp'] = time();
204 203
         
205
-        $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery( $into_table , $whereStatement , $field_values );
204
+        $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($into_table, $whereStatement, $field_values);
206 205
         $cnt = $GLOBALS['TYPO3_DB']->sql_affected_rows();
207 206
     }
208 207
 
@@ -221,7 +220,7 @@  discard block
 block discarded – undo
221 220
 
222 221
         if ($exclude_arr != null) {
223 222
             $exclude_max = count($exclude_arr);
224
-            if (count($exclude_arr) > 0){
223
+            if (count($exclude_arr) > 0) {
225 224
                 $exclude = true;
226 225
             }
227 226
 
@@ -231,7 +230,7 @@  discard block
 block discarded – undo
231 230
 
232 231
                 if ($exclude) {
233 232
                     foreach ($exclude_arr as $key => $value) {
234
-                        if ($value == $parentkey){
233
+                        if ($value == $parentkey) {
235 234
                             unset($arr[$parentkey]);
236 235
                         }
237 236
                     }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -119,8 +119,7 @@  discard block
 block discarded – undo
119 119
                     $record_exists = true;
120 120
                     break;
121 121
                 }
122
-            }
123
-            else {
122
+            } else {
124 123
                 continue;
125 124
             }
126 125
         }
@@ -128,8 +127,7 @@  discard block
 block discarded – undo
128 127
         if ($record_exists){
129 128
             $this->updateRecord($entry);
130 129
             return TargetInterface::RESULT_UPDATE;
131
-        }
132
-        else { 
130
+        } else { 
133 131
             $this->insertRecord($entry);
134 132
             return TargetInterface::RESULT_INSERT;
135 133
         }
Please login to merge, or discard this patch.