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