@@ -18,101 +18,101 @@ |
||
18 | 18 | |
19 | 19 | protected function setUp() |
20 | 20 | { |
21 | - \Aimeos\MShop\Factory::setCache( true ); |
|
21 | + \Aimeos\MShop\Factory::setCache(true); |
|
22 | 22 | |
23 | 23 | $this->context = \TestHelperJobs::getContext(); |
24 | 24 | $this->aimeos = \TestHelperJobs::getAimeos(); |
25 | 25 | $config = $this->context->getConfig(); |
26 | 26 | |
27 | - $config->set( 'controller/jobs/product/import/csv/skip-lines', 1 ); |
|
27 | + $config->set('controller/jobs/product/import/csv/skip-lines', 1); |
|
28 | 28 | |
29 | - $this->object = new \Aimeos\Controller\Jobs\Coupon\Import\Csv\Code\Standard( $this->context, $this->aimeos ); |
|
29 | + $this->object = new \Aimeos\Controller\Jobs\Coupon\Import\Csv\Code\Standard($this->context, $this->aimeos); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | |
33 | 33 | protected function tearDown() |
34 | 34 | { |
35 | - \Aimeos\MShop\Factory::setCache( false ); |
|
35 | + \Aimeos\MShop\Factory::setCache(false); |
|
36 | 36 | \Aimeos\MShop\Factory::clear(); |
37 | 37 | |
38 | - unset( $this->object ); |
|
38 | + unset($this->object); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | |
42 | 42 | public function testGetName() |
43 | 43 | { |
44 | - $this->assertEquals( 'Coupon code import CSV', $this->object->getName() ); |
|
44 | + $this->assertEquals('Coupon code import CSV', $this->object->getName()); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | |
48 | 48 | public function testGetDescription() |
49 | 49 | { |
50 | 50 | $text = 'Imports new and updates existing coupon code from CSV files'; |
51 | - $this->assertEquals( $text, $this->object->getDescription() ); |
|
51 | + $this->assertEquals($text, $this->object->getDescription()); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | |
55 | 55 | public function testRun() |
56 | 56 | { |
57 | - $manager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon' ); |
|
58 | - $coupon = $manager->saveItem( $manager->createItem()->setProvider( 'Example' ) ); |
|
57 | + $manager = \Aimeos\MShop\Factory::createManager($this->context, 'coupon'); |
|
58 | + $coupon = $manager->saveItem($manager->createItem()->setProvider('Example')); |
|
59 | 59 | |
60 | 60 | $dir = 'tmp/import/couponcode/unittest'; |
61 | 61 | $filepath = $dir . '/' . $coupon->getId() . '.csv'; |
62 | 62 | |
63 | - if( !is_dir( $dir ) && mkdir( 'tmp/import/couponcode/unittest', 0775, true ) === false ) { |
|
64 | - throw new \Exception( sprintf( 'Unable to create directory "%1$s"', $dir ) ); |
|
63 | + if (!is_dir($dir) && mkdir('tmp/import/couponcode/unittest', 0775, true) === false) { |
|
64 | + throw new \Exception(sprintf('Unable to create directory "%1$s"', $dir)); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | $content = 'code,count,start,end |
68 | 68 | jobccimport1,3,2000-01-01 00:00:00, |
69 | 69 | jobccimport2,5,,'; |
70 | 70 | |
71 | - if( file_put_contents( $filepath, $content ) === false ) { |
|
72 | - throw new \Exception( sprintf( 'Unable to create file "%1$s"', $file ) ); |
|
71 | + if (file_put_contents($filepath, $content) === false) { |
|
72 | + throw new \Exception(sprintf('Unable to create file "%1$s"', $file)); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->object->run(); |
76 | 76 | |
77 | 77 | |
78 | - unlink( $filepath ); |
|
78 | + unlink($filepath); |
|
79 | 79 | |
80 | - $codeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon/code' ); |
|
81 | - $code1 = $codeManager->findItem( 'jobccimport1' ); |
|
82 | - $code2 = $codeManager->findItem( 'jobccimport2' ); |
|
80 | + $codeManager = \Aimeos\MShop\Factory::createManager($this->context, 'coupon/code'); |
|
81 | + $code1 = $codeManager->findItem('jobccimport1'); |
|
82 | + $code2 = $codeManager->findItem('jobccimport2'); |
|
83 | 83 | |
84 | - $manager->deleteItem( $coupon->getId() ); |
|
84 | + $manager->deleteItem($coupon->getId()); |
|
85 | 85 | |
86 | - $this->assertEquals( 3, $code1->getCount() ); |
|
87 | - $this->assertEquals( '2000-01-01 00:00:00', $code1->getDateStart() ); |
|
88 | - $this->assertEquals( null, $code1->getDateEnd() ); |
|
86 | + $this->assertEquals(3, $code1->getCount()); |
|
87 | + $this->assertEquals('2000-01-01 00:00:00', $code1->getDateStart()); |
|
88 | + $this->assertEquals(null, $code1->getDateEnd()); |
|
89 | 89 | |
90 | - $this->assertEquals( 5, $code2->getCount() ); |
|
91 | - $this->assertEquals( null, $code2->getDateStart() ); |
|
92 | - $this->assertEquals( null, $code2->getDateEnd() ); |
|
90 | + $this->assertEquals(5, $code2->getCount()); |
|
91 | + $this->assertEquals(null, $code2->getDateStart()); |
|
92 | + $this->assertEquals(null, $code2->getDateEnd()); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
96 | 96 | public function testRunException() |
97 | 97 | { |
98 | - $manager = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon' ); |
|
98 | + $manager = \Aimeos\MShop\Factory::createManager($this->context, 'coupon'); |
|
99 | 99 | |
100 | 100 | $dir = 'tmp/import/couponcode/unittest'; |
101 | 101 | $filepath = $dir . '/0.csv'; |
102 | 102 | |
103 | - if( !is_dir( $dir ) && mkdir( 'tmp/import/couponcode/unittest', 0775, true ) === false ) { |
|
104 | - throw new \Exception( sprintf( 'Unable to create directory "%1$s"', $dir ) ); |
|
103 | + if (!is_dir($dir) && mkdir('tmp/import/couponcode/unittest', 0775, true) === false) { |
|
104 | + throw new \Exception(sprintf('Unable to create directory "%1$s"', $dir)); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | $content = 'code,count,start,end |
108 | 108 | jobccimport1,,,'; |
109 | 109 | |
110 | - if( file_put_contents( $filepath, $content ) === false ) { |
|
111 | - throw new \Exception( sprintf( 'Unable to create file "%1$s"', $file ) ); |
|
110 | + if (file_put_contents($filepath, $content) === false) { |
|
111 | + throw new \Exception(sprintf('Unable to create file "%1$s"', $file)); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | $this->object->run(); |
115 | 115 | |
116 | - unlink( $filepath ); |
|
116 | + unlink($filepath); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | \ No newline at end of file |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getName() |
30 | 30 | { |
31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Coupon code import CSV' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Coupon code import CSV'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function getDescription() |
41 | 41 | { |
42 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Imports new and updates existing coupon code from CSV files' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Imports new and updates existing coupon code from CSV files'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @see controller/jobs/coupon/import/csv/code/skip-lines |
72 | 72 | * @see controller/jobs/coupon/import/csv/code/max-size |
73 | 73 | */ |
74 | - $mappings = $config->get( 'controller/jobs/coupon/import/csv/code/mapping', $mappings ); |
|
74 | + $mappings = $config->get('controller/jobs/coupon/import/csv/code/mapping', $mappings); |
|
75 | 75 | |
76 | 76 | |
77 | 77 | /** controller/jobs/coupon/import/csv/code/max-size |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @see controller/jobs/coupon/import/csv/code/skip-lines |
91 | 91 | * @see controller/jobs/coupon/import/csv/code/mapping |
92 | 92 | */ |
93 | - $maxcnt = (int) $config->get( 'controller/jobs/coupon/import/csv/code/max-size', 1000 ); |
|
93 | + $maxcnt = (int) $config->get('controller/jobs/coupon/import/csv/code/max-size', 1000); |
|
94 | 94 | |
95 | 95 | |
96 | 96 | /** controller/jobs/coupon/import/csv/code/skip-lines |
@@ -108,63 +108,63 @@ discard block |
||
108 | 108 | * @see controller/jobs/coupon/import/csv/code/mapping |
109 | 109 | * @see controller/jobs/coupon/import/csv/code/max-size |
110 | 110 | */ |
111 | - $skiplines = (int) $config->get( 'controller/jobs/coupon/import/csv/code/skip-lines', 0 ); |
|
111 | + $skiplines = (int) $config->get('controller/jobs/coupon/import/csv/code/skip-lines', 0); |
|
112 | 112 | |
113 | 113 | |
114 | 114 | try |
115 | 115 | { |
116 | - $processor = $this->getProcessors( $mappings ); |
|
117 | - $codePos = $this->getCodePosition( $mappings['code'] ); |
|
118 | - $fs = $context->getFileSystemManager()->get( 'fs-import' ); |
|
116 | + $processor = $this->getProcessors($mappings); |
|
117 | + $codePos = $this->getCodePosition($mappings['code']); |
|
118 | + $fs = $context->getFileSystemManager()->get('fs-import'); |
|
119 | 119 | $dir = 'couponcode/' . $context->getLocale()->getSite()->getCode(); |
120 | 120 | |
121 | - if( $fs->isDir( $dir ) === false ) { |
|
121 | + if ($fs->isDir($dir) === false) { |
|
122 | 122 | return; |
123 | 123 | } |
124 | 124 | |
125 | - foreach( $fs->scan( $dir ) as $filename ) |
|
125 | + foreach ($fs->scan($dir) as $filename) |
|
126 | 126 | { |
127 | - if( $filename == '.' || $filename == '..' ) { |
|
127 | + if ($filename == '.' || $filename == '..') { |
|
128 | 128 | continue; |
129 | 129 | } |
130 | 130 | |
131 | - list( $couponId, ) = explode( '.', $filename ); |
|
132 | - $container = $this->getContainer( $fs->readf( $dir . '/' . $filename ) ); |
|
131 | + list($couponId,) = explode('.', $filename); |
|
132 | + $container = $this->getContainer($fs->readf($dir . '/' . $filename)); |
|
133 | 133 | |
134 | - $msg = sprintf( 'Started coupon import from "%1$s" (%2$s)', $filename, __CLASS__ ); |
|
135 | - $logger->log( $msg, \Aimeos\MW\Logger\Base::NOTICE ); |
|
134 | + $msg = sprintf('Started coupon import from "%1$s" (%2$s)', $filename, __CLASS__); |
|
135 | + $logger->log($msg, \Aimeos\MW\Logger\Base::NOTICE); |
|
136 | 136 | |
137 | - foreach( $container as $content ) |
|
137 | + foreach ($container as $content) |
|
138 | 138 | { |
139 | - for( $i = 0; $i < $skiplines; $i++ ) { |
|
139 | + for ($i = 0; $i < $skiplines; $i++) { |
|
140 | 140 | $content->next(); |
141 | 141 | } |
142 | 142 | |
143 | - while( ( $data = $this->getData( $content, $maxcnt, $codePos ) ) !== [] ) |
|
143 | + while (($data = $this->getData($content, $maxcnt, $codePos)) !== []) |
|
144 | 144 | { |
145 | - $items = $this->getCouponCodeItems( array_keys( $data ) ); |
|
146 | - $errcnt = $this->import( $items, $data, $couponId, $processor ); |
|
147 | - $chunkcnt = count( $data ); |
|
145 | + $items = $this->getCouponCodeItems(array_keys($data)); |
|
146 | + $errcnt = $this->import($items, $data, $couponId, $processor); |
|
147 | + $chunkcnt = count($data); |
|
148 | 148 | |
149 | 149 | $msg = 'Imported coupon lines from "%1$s": %2$d/%3$d (%4$s)'; |
150 | - $logger->log( sprintf( $msg, $filename, $chunkcnt - $errcnt, $chunkcnt, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
150 | + $logger->log(sprintf($msg, $filename, $chunkcnt - $errcnt, $chunkcnt, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
151 | 151 | |
152 | 152 | $errors += $errcnt; |
153 | 153 | $total += $chunkcnt; |
154 | - unset( $items, $data ); |
|
154 | + unset($items, $data); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
158 | - $this->closeContainer( $container ); |
|
158 | + $this->closeContainer($container); |
|
159 | 159 | |
160 | 160 | $msg = 'Finished coupon import: %1$d successful, %2$s errors, %3$s total (%4$s)'; |
161 | - $logger->log( sprintf( $msg, $total - $errors, $errors, $total, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
161 | + $logger->log(sprintf($msg, $total - $errors, $errors, $total, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
162 | 162 | } |
163 | 163 | } |
164 | - catch( \Exception $e ) |
|
164 | + catch (\Exception $e) |
|
165 | 165 | { |
166 | - $logger->log( 'Coupon import error: ' . $e->getMessage() ); |
|
167 | - $logger->log( $e->getTraceAsString() ); |
|
166 | + $logger->log('Coupon import error: ' . $e->getMessage()); |
|
167 | + $logger->log($e->getTraceAsString()); |
|
168 | 168 | |
169 | 169 | throw $e; |
170 | 170 | } |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @param \Aimeos\MW\Container\Iface $container Container object |
178 | 178 | */ |
179 | - protected function closeContainer( \Aimeos\MW\Container\Iface $container ) |
|
179 | + protected function closeContainer(\Aimeos\MW\Container\Iface $container) |
|
180 | 180 | { |
181 | 181 | $container->close(); |
182 | - unlink( $container->getName() ); |
|
182 | + unlink($container->getName()); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | |
@@ -190,16 +190,16 @@ discard block |
||
190 | 190 | * @return integer Position of the "coupon.code" column |
191 | 191 | * @throws \Aimeos\Controller\Jobs\Exception If no mapping for "coupon.code.code" is found |
192 | 192 | */ |
193 | - protected function getCodePosition( array $mapping ) |
|
193 | + protected function getCodePosition(array $mapping) |
|
194 | 194 | { |
195 | - foreach( $mapping as $pos => $key ) |
|
195 | + foreach ($mapping as $pos => $key) |
|
196 | 196 | { |
197 | - if( $key === 'coupon.code.code' ) { |
|
197 | + if ($key === 'coupon.code.code') { |
|
198 | 198 | return $pos; |
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "coupon.code.code" column in CSV mapping found' ) ); |
|
202 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('No "coupon.code.code" column in CSV mapping found')); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @param string $filepath Path to the container file |
210 | 210 | * @return \Aimeos\MW\Container\Iface Container object |
211 | 211 | */ |
212 | - protected function getContainer( $filepath ) |
|
212 | + protected function getContainer($filepath) |
|
213 | 213 | { |
214 | 214 | $config = $this->getContext()->getConfig(); |
215 | 215 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * @see controller/jobs/coupon/import/csv/code/container/content |
234 | 234 | * @see controller/jobs/coupon/import/csv/code/container/options |
235 | 235 | */ |
236 | - $container = $config->get( 'controller/jobs/coupon/import/csv/code/container/type', 'File' ); |
|
236 | + $container = $config->get('controller/jobs/coupon/import/csv/code/container/type', 'File'); |
|
237 | 237 | |
238 | 238 | /** controller/jobs/coupon/import/csv/code/container/content |
239 | 239 | * Name of the content type inside the container to read the data from |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @see controller/jobs/coupon/import/csv/code/container/type |
254 | 254 | * @see controller/jobs/coupon/import/csv/code/container/options |
255 | 255 | */ |
256 | - $content = $config->get( 'controller/jobs/coupon/import/csv/code/container/content', 'CSV' ); |
|
256 | + $content = $config->get('controller/jobs/coupon/import/csv/code/container/content', 'CSV'); |
|
257 | 257 | |
258 | 258 | /** controller/jobs/coupon/import/csv/code/container/options |
259 | 259 | * List of file container options for the coupon import files |
@@ -270,9 +270,9 @@ discard block |
||
270 | 270 | * @see controller/jobs/coupon/import/csv/code/container/content |
271 | 271 | * @see controller/jobs/coupon/import/csv/code/container/type |
272 | 272 | */ |
273 | - $options = $config->get( 'controller/jobs/coupon/import/csv/code/container/options', [] ); |
|
273 | + $options = $config->get('controller/jobs/coupon/import/csv/code/container/options', []); |
|
274 | 274 | |
275 | - return \Aimeos\MW\Container\Factory::getContainer( $filepath, $container, $content, $options ); |
|
275 | + return \Aimeos\MW\Container\Factory::getContainer($filepath, $container, $content, $options); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | |
@@ -286,36 +286,36 @@ discard block |
||
286 | 286 | * @return integer Number of coupons that couldn't be imported |
287 | 287 | * @throws \Aimeos\Controller\Jobs\Exception |
288 | 288 | */ |
289 | - protected function import( array $items, array $data, $couponId, |
|
290 | - \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Iface $processor ) |
|
289 | + protected function import(array $items, array $data, $couponId, |
|
290 | + \Aimeos\Controller\Common\Coupon\Import\Csv\Processor\Iface $processor) |
|
291 | 291 | { |
292 | 292 | $errors = 0; |
293 | 293 | $context = $this->getContext(); |
294 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'coupon/code' ); |
|
294 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'coupon/code'); |
|
295 | 295 | |
296 | - foreach( $data as $code => $list ) |
|
296 | + foreach ($data as $code => $list) |
|
297 | 297 | { |
298 | 298 | $manager->begin(); |
299 | 299 | |
300 | 300 | try |
301 | 301 | { |
302 | - if( isset( $items[$code] ) ) { |
|
302 | + if (isset($items[$code])) { |
|
303 | 303 | $item = $items[$code]; |
304 | 304 | } else { |
305 | 305 | $item = $manager->createItem(); |
306 | 306 | } |
307 | 307 | |
308 | - $item->setParentId( $couponId ); |
|
309 | - $list = $processor->process( $item, $list ); |
|
308 | + $item->setParentId($couponId); |
|
309 | + $list = $processor->process($item, $list); |
|
310 | 310 | |
311 | 311 | $manager->commit(); |
312 | 312 | } |
313 | - catch( \Exception $e ) |
|
313 | + catch (\Exception $e) |
|
314 | 314 | { |
315 | 315 | $manager->rollback(); |
316 | 316 | |
317 | - $msg = sprintf( 'Unable to import coupon with code "%1$s": %2$s', $code, $e->getMessage() ); |
|
318 | - $context->getLogger()->log( $msg ); |
|
317 | + $msg = sprintf('Unable to import coupon with code "%1$s": %2$s', $code, $e->getMessage()); |
|
318 | + $context->getLogger()->log($msg); |
|
319 | 319 | |
320 | 320 | $errors++; |
321 | 321 | } |