@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function getName() |
| 31 | 31 | { |
| 32 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Index optimization' ); |
|
| 32 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Index optimization'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function getDescription() |
| 42 | 42 | { |
| 43 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Optimizes the index for searching products faster' ); |
|
| 43 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Optimizes the index for searching products faster'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -51,6 +51,6 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function run() |
| 53 | 53 | { |
| 54 | - \Aimeos\MShop\Index\Manager\Factory::createManager( $this->getContext() )->optimize(); |
|
| 54 | + \Aimeos\MShop\Index\Manager\Factory::createManager($this->getContext())->optimize(); |
|
| 55 | 55 | } |
| 56 | 56 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function getName() |
| 31 | 31 | { |
| 32 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Index rebuild' ); |
|
| 32 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Index rebuild'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function getDescription() |
| 42 | 42 | { |
| 43 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Rebuilds the index for searching products' ); |
|
| 43 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Rebuilds the index for searching products'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -51,15 +51,15 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function run() |
| 53 | 53 | { |
| 54 | - $timestamp = date( 'Y-m-d H:i:s' ); |
|
| 54 | + $timestamp = date('Y-m-d H:i:s'); |
|
| 55 | 55 | $context = clone $this->getContext(); |
| 56 | 56 | |
| 57 | - $context->getLocale()->setLanguageId( null ); |
|
| 58 | - $context->getLocale()->setCurrencyId( null ); |
|
| 57 | + $context->getLocale()->setLanguageId(null); |
|
| 58 | + $context->getLocale()->setCurrencyId(null); |
|
| 59 | 59 | |
| 60 | - $manager = \Aimeos\MShop\Index\Manager\Factory::createManager( $context ); |
|
| 60 | + $manager = \Aimeos\MShop\Index\Manager\Factory::createManager($context); |
|
| 61 | 61 | |
| 62 | 62 | $manager->rebuildIndex(); |
| 63 | - $manager->cleanupIndex( $timestamp ); |
|
| 63 | + $manager->cleanupIndex($timestamp); |
|
| 64 | 64 | } |
| 65 | 65 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | $context = \TestHelperJobs::getContext(); |
| 25 | 25 | $aimeos = \TestHelperJobs::getAimeos(); |
| 26 | 26 | |
| 27 | - $this->object = new \Aimeos\Controller\Jobs\Index\Optimize\Standard( $context, $aimeos ); |
|
| 27 | + $this->object = new \Aimeos\Controller\Jobs\Index\Optimize\Standard($context, $aimeos); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function testGetName() |
| 44 | 44 | { |
| 45 | - $this->assertEquals( 'Index optimization', $this->object->getName() ); |
|
| 45 | + $this->assertEquals('Index optimization', $this->object->getName()); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | public function testGetDescription() |
| 50 | 50 | { |
| 51 | 51 | $text = 'Optimizes the index for searching products faster'; |
| 52 | - $this->assertEquals( $text, $this->object->getDescription() ); |
|
| 52 | + $this->assertEquals($text, $this->object->getDescription()); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | |
@@ -60,21 +60,21 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | $name = 'ControllerJobsCatalogIndexOptimizeDefaultRun'; |
| 63 | - $context->getConfig()->set( 'mshop/index/manager/name', $name ); |
|
| 63 | + $context->getConfig()->set('mshop/index/manager/name', $name); |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - $indexManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Index\\Manager\\Standard' ) |
|
| 67 | - ->setMethods( array( 'optimize' ) ) |
|
| 68 | - ->setConstructorArgs( array( $context ) ) |
|
| 66 | + $indexManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Index\\Manager\\Standard') |
|
| 67 | + ->setMethods(array('optimize')) |
|
| 68 | + ->setConstructorArgs(array($context)) |
|
| 69 | 69 | ->getMock(); |
| 70 | 70 | |
| 71 | - \Aimeos\MShop\Catalog\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Index\\Manager\\' . $name, $indexManagerStub ); |
|
| 71 | + \Aimeos\MShop\Catalog\Manager\Factory::injectManager('\\Aimeos\\MShop\\Index\\Manager\\' . $name, $indexManagerStub); |
|
| 72 | 72 | |
| 73 | 73 | |
| 74 | - $indexManagerStub->expects( $this->once() )->method( 'optimize' ); |
|
| 74 | + $indexManagerStub->expects($this->once())->method('optimize'); |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | - $object = new \Aimeos\Controller\Jobs\Index\Optimize\Standard( $context, $aimeos ); |
|
| 77 | + $object = new \Aimeos\Controller\Jobs\Index\Optimize\Standard($context, $aimeos); |
|
| 78 | 78 | $object->run(); |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | $context = \TestHelperJobs::getContext(); |
| 25 | 25 | $aimeos = \TestHelperJobs::getAimeos(); |
| 26 | 26 | |
| 27 | - $this->object = new \Aimeos\Controller\Jobs\Index\Rebuild\Standard( $context, $aimeos ); |
|
| 27 | + $this->object = new \Aimeos\Controller\Jobs\Index\Rebuild\Standard($context, $aimeos); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function testGetName() |
| 44 | 44 | { |
| 45 | - $this->assertEquals( 'Index rebuild', $this->object->getName() ); |
|
| 45 | + $this->assertEquals('Index rebuild', $this->object->getName()); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | public function testGetDescription() |
| 50 | 50 | { |
| 51 | 51 | $text = 'Rebuilds the index for searching products'; |
| 52 | - $this->assertEquals( $text, $this->object->getDescription() ); |
|
| 52 | + $this->assertEquals($text, $this->object->getDescription()); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | |
@@ -60,22 +60,22 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | $name = 'ControllerJobsCatalogIndexRebuildDefaultRun'; |
| 63 | - $context->getConfig()->set( 'mshop/index/manager/name', $name ); |
|
| 63 | + $context->getConfig()->set('mshop/index/manager/name', $name); |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - $indexManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Index\\Manager\\Standard' ) |
|
| 67 | - ->setMethods( array( 'rebuildIndex', 'cleanupIndex' ) ) |
|
| 68 | - ->setConstructorArgs( array( $context ) ) |
|
| 66 | + $indexManagerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Index\\Manager\\Standard') |
|
| 67 | + ->setMethods(array('rebuildIndex', 'cleanupIndex')) |
|
| 68 | + ->setConstructorArgs(array($context)) |
|
| 69 | 69 | ->getMock(); |
| 70 | 70 | |
| 71 | - \Aimeos\MShop\Catalog\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Index\\Manager\\' . $name, $indexManagerStub ); |
|
| 71 | + \Aimeos\MShop\Catalog\Manager\Factory::injectManager('\\Aimeos\\MShop\\Index\\Manager\\' . $name, $indexManagerStub); |
|
| 72 | 72 | |
| 73 | 73 | |
| 74 | - $indexManagerStub->expects( $this->once() )->method( 'rebuildIndex' ); |
|
| 75 | - $indexManagerStub->expects( $this->once() )->method( 'cleanupIndex' ); |
|
| 74 | + $indexManagerStub->expects($this->once())->method('rebuildIndex'); |
|
| 75 | + $indexManagerStub->expects($this->once())->method('cleanupIndex'); |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - $object = new \Aimeos\Controller\Jobs\Index\Rebuild\Standard( $context, $aimeos ); |
|
| 78 | + $object = new \Aimeos\Controller\Jobs\Index\Rebuild\Standard($context, $aimeos); |
|
| 79 | 79 | $object->run(); |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param string|null $name Name of the controller or "Standard" if null |
| 30 | 30 | * @return \Aimeos\Controller\Jobs\Iface New controller object |
| 31 | 31 | */ |
| 32 | - public static function createController( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos, $name = null ) |
|
| 32 | + public static function createController(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos, $name = null) |
|
| 33 | 33 | { |
| 34 | 34 | /** controller/jobs/media/scale/name |
| 35 | 35 | * Class name of the used media scale job controller implementation |
@@ -64,20 +64,20 @@ discard block |
||
| 64 | 64 | * @since 2017.01 |
| 65 | 65 | * @category Developer |
| 66 | 66 | */ |
| 67 | - if( $name === null ) { |
|
| 68 | - $name = $context->getConfig()->get( 'controller/jobs/media/scale/name', 'Standard' ); |
|
| 67 | + if ($name === null) { |
|
| 68 | + $name = $context->getConfig()->get('controller/jobs/media/scale/name', 'Standard'); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if( ctype_alnum( $name ) === false ) |
|
| 71 | + if (ctype_alnum($name) === false) |
|
| 72 | 72 | { |
| 73 | - $classname = is_string( $name ) ? '\\Aimeos\\Controller\\Jobs\\Media\\Scale\\' . $name : '<not a string>'; |
|
| 74 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
| 73 | + $classname = is_string($name) ? '\\Aimeos\\Controller\\Jobs\\Media\\Scale\\' . $name : '<not a string>'; |
|
| 74 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in class name "%1$s"', $classname)); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $iface = '\\Aimeos\\Controller\\Jobs\\Iface'; |
| 78 | 78 | $classname = '\\Aimeos\\Controller\\Jobs\\Media\\Scale\\' . $name; |
| 79 | 79 | |
| 80 | - $controller = self::createControllerBase( $context, $aimeos, $classname, $iface ); |
|
| 80 | + $controller = self::createControllerBase($context, $aimeos, $classname, $iface); |
|
| 81 | 81 | |
| 82 | 82 | /** controller/jobs/media/scale/decorators/excludes |
| 83 | 83 | * Excludes decorators added by the "common" option from the media scale controllers |
@@ -153,6 +153,6 @@ discard block |
||
| 153 | 153 | * @see controller/jobs/media/scale/decorators/excludes |
| 154 | 154 | * @see controller/jobs/media/scale/decorators/global |
| 155 | 155 | */ |
| 156 | - return self::addControllerDecorators( $context, $aimeos, $controller, 'media/scale' ); |
|
| 156 | + return self::addControllerDecorators($context, $aimeos, $controller, 'media/scale'); |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | \ No newline at end of file |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | $context = \TestHelperJobs::getContext(); |
| 17 | 17 | $aimeos = \TestHelperJobs::getAimeos(); |
| 18 | 18 | |
| 19 | - $obj = \Aimeos\Controller\Jobs\Media\Scale\Factory::createController( $context, $aimeos ); |
|
| 20 | - $this->assertInstanceOf( '\\Aimeos\\Controller\\Jobs\\Iface', $obj ); |
|
| 19 | + $obj = \Aimeos\Controller\Jobs\Media\Scale\Factory::createController($context, $aimeos); |
|
| 20 | + $this->assertInstanceOf('\\Aimeos\\Controller\\Jobs\\Iface', $obj); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | $context = \TestHelperJobs::getContext(); |
| 27 | 27 | $aimeos = \TestHelperJobs::getAimeos(); |
| 28 | 28 | |
| 29 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
| 30 | - \Aimeos\Controller\Jobs\Media\Scale\Factory::createController( $context, $aimeos, 'Wrong$$$Name' ); |
|
| 29 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
| 30 | + \Aimeos\Controller\Jobs\Media\Scale\Factory::createController($context, $aimeos, 'Wrong$$$Name'); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | $context = \TestHelperJobs::getContext(); |
| 37 | 37 | $aimeos = \TestHelperJobs::getAimeos(); |
| 38 | 38 | |
| 39 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
| 40 | - \Aimeos\Controller\Jobs\Media\Scale\Factory::createController( $context, $aimeos, 'WrongClass' ); |
|
| 39 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
| 40 | + \Aimeos\Controller\Jobs\Media\Scale\Factory::createController($context, $aimeos, 'WrongClass'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | $context = \TestHelperJobs::getContext(); |
| 47 | 47 | $aimeos = \TestHelperJobs::getAimeos(); |
| 48 | 48 | |
| 49 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
| 50 | - \Aimeos\Controller\Jobs\Media\Scale\Factory::createController( $context, $aimeos, 'Factory' ); |
|
| 49 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
| 50 | + \Aimeos\Controller\Jobs\Media\Scale\Factory::createController($context, $aimeos, 'Factory'); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $context = \TestHelperJobs::getContext(); |
| 20 | 20 | $aimeos = \TestHelperJobs::getAimeos(); |
| 21 | 21 | |
| 22 | - $this->object = new \Aimeos\Controller\Jobs\Media\Scale\Standard( $context, $aimeos ); |
|
| 22 | + $this->object = new \Aimeos\Controller\Jobs\Media\Scale\Standard($context, $aimeos); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -31,14 +31,14 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function testGetName() |
| 33 | 33 | { |
| 34 | - $this->assertEquals( 'Rescale product images', $this->object->getName() ); |
|
| 34 | + $this->assertEquals('Rescale product images', $this->object->getName()); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | public function testGetDescription() |
| 39 | 39 | { |
| 40 | 40 | $text = 'Rescales product images to the new sizes'; |
| 41 | - $this->assertEquals( $text, $this->object->getDescription() ); |
|
| 41 | + $this->assertEquals($text, $this->object->getDescription()); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | |
@@ -49,31 +49,31 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | $name = 'ControllerJobsMediaScaleStandardRun'; |
| 52 | - $context->getConfig()->set( 'mshop/media/manager/name', $name ); |
|
| 53 | - $context->getConfig()->set( 'controller/common/media/name', $name ); |
|
| 52 | + $context->getConfig()->set('mshop/media/manager/name', $name); |
|
| 53 | + $context->getConfig()->set('controller/common/media/name', $name); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - $managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Media\\Manager\\Standard' ) |
|
| 57 | - ->setMethods( array( 'saveItem' ) ) |
|
| 58 | - ->setConstructorArgs( array( $context ) ) |
|
| 56 | + $managerStub = $this->getMockBuilder('\\Aimeos\\MShop\\Media\\Manager\\Standard') |
|
| 57 | + ->setMethods(array('saveItem')) |
|
| 58 | + ->setConstructorArgs(array($context)) |
|
| 59 | 59 | ->getMock(); |
| 60 | 60 | |
| 61 | - \Aimeos\MShop\Media\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Media\\Manager\\' . $name, $managerStub ); |
|
| 61 | + \Aimeos\MShop\Media\Manager\Factory::injectManager('\\Aimeos\\MShop\\Media\\Manager\\' . $name, $managerStub); |
|
| 62 | 62 | |
| 63 | - $managerStub->expects( $this->atLeast( 1 ) )->method( 'saveItem' ); |
|
| 63 | + $managerStub->expects($this->atLeast(1))->method('saveItem'); |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - $cntlStub = $this->getMockBuilder( '\\Aimeos\\Controller\\Common\\Media\\Standard' ) |
|
| 67 | - ->setMethods( array( 'scale' ) ) |
|
| 68 | - ->setConstructorArgs( array( $context ) ) |
|
| 66 | + $cntlStub = $this->getMockBuilder('\\Aimeos\\Controller\\Common\\Media\\Standard') |
|
| 67 | + ->setMethods(array('scale')) |
|
| 68 | + ->setConstructorArgs(array($context)) |
|
| 69 | 69 | ->getMock(); |
| 70 | 70 | |
| 71 | - \Aimeos\Controller\Common\Media\Factory::injectController( '\\Aimeos\\Controller\\Common\\Media\\' . $name, $cntlStub ); |
|
| 71 | + \Aimeos\Controller\Common\Media\Factory::injectController('\\Aimeos\\Controller\\Common\\Media\\' . $name, $cntlStub); |
|
| 72 | 72 | |
| 73 | - $cntlStub->expects( $this->atLeast( 1 ) )->method( 'scale' ); |
|
| 73 | + $cntlStub->expects($this->atLeast(1))->method('scale'); |
|
| 74 | 74 | |
| 75 | 75 | |
| 76 | - $object = new \Aimeos\Controller\Jobs\Media\Scale\Standard( $context, $aimeos ); |
|
| 76 | + $object = new \Aimeos\Controller\Jobs\Media\Scale\Standard($context, $aimeos); |
|
| 77 | 77 | $object->run(); |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -351,8 +351,7 @@ discard block |
||
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | $container->close(); |
| 354 | - } |
|
| 355 | - catch( \Exception $e ) |
|
| 354 | + } catch( \Exception $e ) |
|
| 356 | 355 | { |
| 357 | 356 | $logger->log( 'Product import error: ' . $e->getMessage() ); |
| 358 | 357 | $logger->log( $e->getTraceAsString() ); |
@@ -540,8 +539,7 @@ discard block |
||
| 540 | 539 | } |
| 541 | 540 | |
| 542 | 541 | $manager->commit(); |
| 543 | - } |
|
| 544 | - catch( \Exception $e ) |
|
| 542 | + } catch( \Exception $e ) |
|
| 545 | 543 | { |
| 546 | 544 | $manager->rollback(); |
| 547 | 545 | |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | * @param \Aimeos\MShop\Context\Item\Iface $context MShop context object |
| 31 | 31 | * @param \Aimeos\Bootstrap $aimeos \Aimeos\Bootstrap main object |
| 32 | 32 | */ |
| 33 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos ) |
|
| 33 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos) |
|
| 34 | 34 | { |
| 35 | - parent::__construct( $context, $aimeos ); |
|
| 35 | + parent::__construct($context, $aimeos); |
|
| 36 | 36 | |
| 37 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'product/type' ); |
|
| 38 | - $search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
|
| 37 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'product/type'); |
|
| 38 | + $search = $manager->createSearch()->setSlice(0, 0x7fffffff); |
|
| 39 | 39 | |
| 40 | - foreach( $manager->searchItems( $search ) as $item ) { |
|
| 40 | + foreach ($manager->searchItems($search) as $item) { |
|
| 41 | 41 | $this->types[$item->getCode()] = $item->getCode(); |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function getName() |
| 52 | 52 | { |
| 53 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Product import CSV' ); |
|
| 53 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Product import CSV'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function getDescription() |
| 63 | 63 | { |
| 64 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Imports new and updates existing products from CSV files' ); |
|
| 64 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Imports new and updates existing products from CSV files'); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $context = $this->getContext(); |
| 77 | 77 | $config = $context->getConfig(); |
| 78 | 78 | $logger = $context->getLogger(); |
| 79 | - $domains = array( 'attribute', 'media', 'price', 'product', 'product/property', 'text' ); |
|
| 79 | + $domains = array('attribute', 'media', 'price', 'product', 'product/property', 'text'); |
|
| 80 | 80 | $mappings = $this->getDefaultMapping(); |
| 81 | 81 | |
| 82 | 82 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @see controller/common/product/import/csv/converter |
| 97 | 97 | * @see controller/common/product/import/csv/max-size |
| 98 | 98 | */ |
| 99 | - $domains = $config->get( 'controller/common/product/import/csv/domains', $domains ); |
|
| 99 | + $domains = $config->get('controller/common/product/import/csv/domains', $domains); |
|
| 100 | 100 | |
| 101 | 101 | /** controller/jobs/product/import/csv/domains |
| 102 | 102 | * List of item domain names that should be retrieved along with the product items |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * @see controller/jobs/product/import/csv/backup |
| 117 | 117 | * @see controller/common/product/import/csv/max-size |
| 118 | 118 | */ |
| 119 | - $domains = $config->get( 'controller/jobs/product/import/csv/domains', $domains ); |
|
| 119 | + $domains = $config->get('controller/jobs/product/import/csv/domains', $domains); |
|
| 120 | 120 | |
| 121 | 121 | |
| 122 | 122 | /** controller/common/product/import/csv/mapping |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @see controller/common/product/import/csv/converter |
| 142 | 142 | * @see controller/common/product/import/csv/max-size |
| 143 | 143 | */ |
| 144 | - $mappings = $config->get( 'controller/common/product/import/csv/mapping', $mappings ); |
|
| 144 | + $mappings = $config->get('controller/common/product/import/csv/mapping', $mappings); |
|
| 145 | 145 | |
| 146 | 146 | /** controller/jobs/product/import/csv/mapping |
| 147 | 147 | * List of mappings between the position in the CSV file and item keys |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @see controller/jobs/product/import/csv/backup |
| 162 | 162 | * @see controller/common/product/import/csv/max-size |
| 163 | 163 | */ |
| 164 | - $mappings = $config->get( 'controller/jobs/product/import/csv/mapping', $mappings ); |
|
| 164 | + $mappings = $config->get('controller/jobs/product/import/csv/mapping', $mappings); |
|
| 165 | 165 | |
| 166 | 166 | |
| 167 | 167 | /** controller/common/product/import/csv/converter |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * @see controller/common/product/import/csv/mapping |
| 204 | 204 | * @see controller/common/product/import/csv/max-size |
| 205 | 205 | */ |
| 206 | - $converters = $config->get( 'controller/common/product/import/csv/converter', [] ); |
|
| 206 | + $converters = $config->get('controller/common/product/import/csv/converter', []); |
|
| 207 | 207 | |
| 208 | 208 | /** controller/jobs/product/import/csv/converter |
| 209 | 209 | * List of converter names for the values at the position in the CSV file |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @see controller/jobs/product/import/csv/backup |
| 224 | 224 | * @see controller/common/product/import/csv/max-size |
| 225 | 225 | */ |
| 226 | - $converters = $config->get( 'controller/jobs/product/import/csv/converter', $converters ); |
|
| 226 | + $converters = $config->get('controller/jobs/product/import/csv/converter', $converters); |
|
| 227 | 227 | |
| 228 | 228 | |
| 229 | 229 | /** controller/common/product/import/csv/max-size |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | * @see controller/common/product/import/csv/mapping |
| 244 | 244 | * @see controller/common/product/import/csv/converter |
| 245 | 245 | */ |
| 246 | - $maxcnt = (int) $config->get( 'controller/common/product/import/csv/max-size', 1000 ); |
|
| 246 | + $maxcnt = (int) $config->get('controller/common/product/import/csv/max-size', 1000); |
|
| 247 | 247 | |
| 248 | 248 | |
| 249 | 249 | /** controller/jobs/product/import/csv/skip-lines |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @see controller/jobs/product/import/csv/backup |
| 266 | 266 | * @see controller/common/product/import/csv/max-size |
| 267 | 267 | */ |
| 268 | - $skiplines = (int) $config->get( 'controller/jobs/product/import/csv/skip-lines', 0 ); |
|
| 268 | + $skiplines = (int) $config->get('controller/jobs/product/import/csv/skip-lines', 0); |
|
| 269 | 269 | |
| 270 | 270 | |
| 271 | 271 | /** controller/jobs/product/import/csv/strict |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * @see controller/jobs/product/import/csv/backup |
| 290 | 290 | * @see controller/common/product/import/csv/max-size |
| 291 | 291 | */ |
| 292 | - $strict = (bool) $config->get( 'controller/jobs/product/import/csv/strict', true ); |
|
| 292 | + $strict = (bool) $config->get('controller/jobs/product/import/csv/strict', true); |
|
| 293 | 293 | |
| 294 | 294 | |
| 295 | 295 | /** controller/jobs/product/import/csv/backup |
@@ -322,74 +322,74 @@ discard block |
||
| 322 | 322 | * @see controller/jobs/product/import/csv/strict |
| 323 | 323 | * @see controller/common/product/import/csv/max-size |
| 324 | 324 | */ |
| 325 | - $backup = $config->get( 'controller/jobs/product/import/csv/backup' ); |
|
| 325 | + $backup = $config->get('controller/jobs/product/import/csv/backup'); |
|
| 326 | 326 | |
| 327 | 327 | |
| 328 | - if( !isset( $mappings['item'] ) || !is_array( $mappings['item'] ) ) |
|
| 328 | + if (!isset($mappings['item']) || !is_array($mappings['item'])) |
|
| 329 | 329 | { |
| 330 | - $msg = sprintf( 'Required mapping key "%1$s" is missing or contains no array', 'item' ); |
|
| 331 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 330 | + $msg = sprintf('Required mapping key "%1$s" is missing or contains no array', 'item'); |
|
| 331 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | try |
| 335 | 335 | { |
| 336 | 336 | $procMappings = $mappings; |
| 337 | - unset( $procMappings['item'] ); |
|
| 337 | + unset($procMappings['item']); |
|
| 338 | 338 | |
| 339 | - $codePos = $this->getCodePosition( $mappings['item'] ); |
|
| 340 | - $convlist = $this->getConverterList( $converters ); |
|
| 341 | - $processor = $this->getProcessors( $procMappings ); |
|
| 339 | + $codePos = $this->getCodePosition($mappings['item']); |
|
| 340 | + $convlist = $this->getConverterList($converters); |
|
| 341 | + $processor = $this->getProcessors($procMappings); |
|
| 342 | 342 | $container = $this->getContainer(); |
| 343 | 343 | $path = $container->getName(); |
| 344 | 344 | |
| 345 | - $msg = sprintf( 'Started product import from "%1$s" (%2$s)', $path, __CLASS__ ); |
|
| 346 | - $logger->log( $msg, \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 345 | + $msg = sprintf('Started product import from "%1$s" (%2$s)', $path, __CLASS__); |
|
| 346 | + $logger->log($msg, \Aimeos\MW\Logger\Base::NOTICE); |
|
| 347 | 347 | |
| 348 | - foreach( $container as $content ) |
|
| 348 | + foreach ($container as $content) |
|
| 349 | 349 | { |
| 350 | 350 | $name = $content->getName(); |
| 351 | 351 | |
| 352 | - for( $i = 0; $i < $skiplines; $i++ ) { |
|
| 352 | + for ($i = 0; $i < $skiplines; $i++) { |
|
| 353 | 353 | $content->next(); |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - while( ( $data = $this->getData( $content, $maxcnt, $codePos ) ) !== [] ) |
|
| 356 | + while (($data = $this->getData($content, $maxcnt, $codePos)) !== []) |
|
| 357 | 357 | { |
| 358 | - $data = $this->convertData( $convlist, $data ); |
|
| 359 | - $products = $this->getProducts( array_keys( $data ), $domains ); |
|
| 360 | - $errcnt = $this->import( $products, $data, $mappings['item'], $processor, $strict ); |
|
| 361 | - $chunkcnt = count( $data ); |
|
| 358 | + $data = $this->convertData($convlist, $data); |
|
| 359 | + $products = $this->getProducts(array_keys($data), $domains); |
|
| 360 | + $errcnt = $this->import($products, $data, $mappings['item'], $processor, $strict); |
|
| 361 | + $chunkcnt = count($data); |
|
| 362 | 362 | |
| 363 | 363 | $msg = 'Imported product lines from "%1$s": %2$d/%3$d (%4$s)'; |
| 364 | - $logger->log( sprintf( $msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 364 | + $logger->log(sprintf($msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
| 365 | 365 | |
| 366 | 366 | $errors += $errcnt; |
| 367 | 367 | $total += $chunkcnt; |
| 368 | - unset( $products, $data ); |
|
| 368 | + unset($products, $data); |
|
| 369 | 369 | } |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | $container->close(); |
| 373 | 373 | } |
| 374 | - catch( \Exception $e ) |
|
| 374 | + catch (\Exception $e) |
|
| 375 | 375 | { |
| 376 | - $logger->log( 'Product import error: ' . $e->getMessage() ); |
|
| 377 | - $logger->log( $e->getTraceAsString() ); |
|
| 376 | + $logger->log('Product import error: ' . $e->getMessage()); |
|
| 377 | + $logger->log($e->getTraceAsString()); |
|
| 378 | 378 | |
| 379 | - throw new \Aimeos\Controller\Jobs\Exception( $e->getMessage() ); |
|
| 379 | + throw new \Aimeos\Controller\Jobs\Exception($e->getMessage()); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | $msg = 'Finished product import from "%1$s": %2$d successful, %3$s errors, %4$s total (%5$s)'; |
| 383 | - $logger->log( sprintf( $msg, $path, $total - $errors, $errors, $total, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 383 | + $logger->log(sprintf($msg, $path, $total - $errors, $errors, $total, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
| 384 | 384 | |
| 385 | - if( $errors > 0 ) |
|
| 385 | + if ($errors > 0) |
|
| 386 | 386 | { |
| 387 | - $msg = sprintf( 'Invalid product lines in "%1$s": %2$d/%3$d', $path, $errors, $total ); |
|
| 388 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 387 | + $msg = sprintf('Invalid product lines in "%1$s": %2$d/%3$d', $path, $errors, $total); |
|
| 388 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - if( !empty( $backup ) && @rename( $path, strftime( $backup ) ) === false ) { |
|
| 392 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Unable to move imported file' ) ); |
|
| 391 | + if (!empty($backup) && @rename($path, strftime($backup)) === false) { |
|
| 392 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Unable to move imported file')); |
|
| 393 | 393 | } |
| 394 | 394 | } |
| 395 | 395 | |
@@ -401,16 +401,16 @@ discard block |
||
| 401 | 401 | * @return integer Position of the "product.code" column |
| 402 | 402 | * @throws \Aimeos\Controller\Jobs\Exception If no mapping for "product.code" is found |
| 403 | 403 | */ |
| 404 | - protected function getCodePosition( array $mapping ) |
|
| 404 | + protected function getCodePosition(array $mapping) |
|
| 405 | 405 | { |
| 406 | - foreach( $mapping as $pos => $key ) |
|
| 406 | + foreach ($mapping as $pos => $key) |
|
| 407 | 407 | { |
| 408 | - if( $key === 'product.code' ) { |
|
| 408 | + if ($key === 'product.code') { |
|
| 409 | 409 | return $pos; |
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "product.code" column in CSV mapping found' ) ); |
|
| 413 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('No "product.code" column in CSV mapping found')); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | * @see controller/jobs/product/import/csv/container/content |
| 446 | 446 | * @see controller/jobs/product/import/csv/container/options |
| 447 | 447 | */ |
| 448 | - $location = $config->get( 'controller/jobs/product/import/csv/location' ); |
|
| 448 | + $location = $config->get('controller/jobs/product/import/csv/location'); |
|
| 449 | 449 | |
| 450 | 450 | /** controller/jobs/product/import/csv/container/type |
| 451 | 451 | * Nave of the container type to read the data from |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | * @see controller/jobs/product/import/csv/container/content |
| 469 | 469 | * @see controller/jobs/product/import/csv/container/options |
| 470 | 470 | */ |
| 471 | - $container = $config->get( 'controller/jobs/product/import/csv/container/type', 'Directory' ); |
|
| 471 | + $container = $config->get('controller/jobs/product/import/csv/container/type', 'Directory'); |
|
| 472 | 472 | |
| 473 | 473 | /** controller/jobs/product/import/csv/container/content |
| 474 | 474 | * Name of the content type inside the container to read the data from |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | * @see controller/jobs/product/import/csv/container/type |
| 490 | 490 | * @see controller/jobs/product/import/csv/container/options |
| 491 | 491 | */ |
| 492 | - $content = $config->get( 'controller/jobs/product/import/csv/container/content', 'CSV' ); |
|
| 492 | + $content = $config->get('controller/jobs/product/import/csv/container/content', 'CSV'); |
|
| 493 | 493 | |
| 494 | 494 | /** controller/jobs/product/import/csv/container/options |
| 495 | 495 | * List of file container options for the product import files |
@@ -507,15 +507,15 @@ discard block |
||
| 507 | 507 | * @see controller/jobs/product/import/csv/container/content |
| 508 | 508 | * @see controller/jobs/product/import/csv/container/type |
| 509 | 509 | */ |
| 510 | - $options = $config->get( 'controller/jobs/product/import/csv/container/options', [] ); |
|
| 510 | + $options = $config->get('controller/jobs/product/import/csv/container/options', []); |
|
| 511 | 511 | |
| 512 | - if( $location === null ) |
|
| 512 | + if ($location === null) |
|
| 513 | 513 | { |
| 514 | - $msg = sprintf( 'Required configuration for "%1$s" is missing', 'controller/jobs/product/import/csv/location' ); |
|
| 515 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 514 | + $msg = sprintf('Required configuration for "%1$s" is missing', 'controller/jobs/product/import/csv/location'); |
|
| 515 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
| 518 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | |
@@ -530,68 +530,68 @@ discard block |
||
| 530 | 530 | * @return integer Number of products that couldn't be imported |
| 531 | 531 | * @throws \Aimeos\Controller\Jobs\Exception |
| 532 | 532 | */ |
| 533 | - protected function import( array $products, array $data, array $mapping, |
|
| 534 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict ) |
|
| 533 | + protected function import(array $products, array $data, array $mapping, |
|
| 534 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict) |
|
| 535 | 535 | { |
| 536 | 536 | $items = []; |
| 537 | 537 | $errors = 0; |
| 538 | 538 | $context = $this->getContext(); |
| 539 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
| 540 | - $indexManager = \Aimeos\MShop\Factory::createManager( $context, 'index' ); |
|
| 539 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
| 540 | + $indexManager = \Aimeos\MShop\Factory::createManager($context, 'index'); |
|
| 541 | 541 | |
| 542 | - foreach( $data as $code => $list ) |
|
| 542 | + foreach ($data as $code => $list) |
|
| 543 | 543 | { |
| 544 | 544 | $manager->begin(); |
| 545 | 545 | |
| 546 | 546 | try |
| 547 | 547 | { |
| 548 | - $code = trim( $code ); |
|
| 548 | + $code = trim($code); |
|
| 549 | 549 | |
| 550 | - if( isset( $products[$code] ) ) { |
|
| 550 | + if (isset($products[$code])) { |
|
| 551 | 551 | $product = $products[$code]; |
| 552 | 552 | } else { |
| 553 | 553 | $product = $manager->createItem(); |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - $map = $this->getMappedChunk( $list, $mapping ); |
|
| 556 | + $map = $this->getMappedChunk($list, $mapping); |
|
| 557 | 557 | |
| 558 | - if( isset( $map[0] ) ) |
|
| 558 | + if (isset($map[0])) |
|
| 559 | 559 | { |
| 560 | 560 | $map = $map[0]; // there can only be one chunk for the base product data |
| 561 | - $map['product.type'] = $this->getValue( $map, 'product.type', 'default' ); |
|
| 561 | + $map['product.type'] = $this->getValue($map, 'product.type', 'default'); |
|
| 562 | 562 | |
| 563 | - if( !in_array( $map['product.type'], $this->types ) ) |
|
| 563 | + if (!in_array($map['product.type'], $this->types)) |
|
| 564 | 564 | { |
| 565 | - $msg = sprintf( 'Invalid product type "%1$s"', $map['product.type'] ); |
|
| 566 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 565 | + $msg = sprintf('Invalid product type "%1$s"', $map['product.type']); |
|
| 566 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - $product = $manager->saveItem( $product->fromArray( $map ) ); |
|
| 569 | + $product = $manager->saveItem($product->fromArray($map)); |
|
| 570 | 570 | |
| 571 | - $list = $processor->process( $product, $list ); |
|
| 571 | + $list = $processor->process($product, $list); |
|
| 572 | 572 | |
| 573 | - $product = $manager->saveItem( $product ); |
|
| 573 | + $product = $manager->saveItem($product); |
|
| 574 | 574 | $items[$product->getId()] = $product; |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | $manager->commit(); |
| 578 | 578 | } |
| 579 | - catch( \Exception $e ) |
|
| 579 | + catch (\Exception $e) |
|
| 580 | 580 | { |
| 581 | 581 | $manager->rollback(); |
| 582 | 582 | |
| 583 | - $msg = sprintf( 'Unable to import product with code "%1$s": %2$s', $code, $e->getMessage() ); |
|
| 584 | - $context->getLogger()->log( $msg ); |
|
| 583 | + $msg = sprintf('Unable to import product with code "%1$s": %2$s', $code, $e->getMessage()); |
|
| 584 | + $context->getLogger()->log($msg); |
|
| 585 | 585 | |
| 586 | 586 | $errors++; |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | - if( $strict && !empty( $list ) ) { |
|
| 590 | - $context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) ); |
|
| 589 | + if ($strict && !empty($list)) { |
|
| 590 | + $context->getLogger()->log('Not imported: ' . print_r($list, true)); |
|
| 591 | 591 | } |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - $indexManager->rebuildIndex( $items ); |
|
| 594 | + $indexManager->rebuildIndex($items); |
|
| 595 | 595 | |
| 596 | 596 | return $errors; |
| 597 | 597 | } |
@@ -131,8 +131,7 @@ |
||
| 131 | 131 | $data = $this->getObject()->process( $product, $data ); |
| 132 | 132 | |
| 133 | 133 | $manager->commit(); |
| 134 | - } |
|
| 135 | - catch( \Exception $e ) |
|
| 134 | + } catch( \Exception $e ) |
|
| 136 | 135 | { |
| 137 | 136 | $manager->rollback(); |
| 138 | 137 | throw $e; |
@@ -42,15 +42,15 @@ discard block |
||
| 42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 43 | 43 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 44 | 44 | */ |
| 45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 47 | 47 | { |
| 48 | - parent::__construct( $context, $mapping, $object ); |
|
| 48 | + parent::__construct($context, $mapping, $object); |
|
| 49 | 49 | |
| 50 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'stock/type' ); |
|
| 51 | - $search = $manager->createSearch()->setSlice( 0, 0x7fffffff ); |
|
| 50 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'stock/type'); |
|
| 51 | + $search = $manager->createSearch()->setSlice(0, 0x7fffffff); |
|
| 52 | 52 | |
| 53 | - foreach( $manager->searchItems( $search ) as $item ) { |
|
| 53 | + foreach ($manager->searchItems($search) as $item) { |
|
| 54 | 54 | $this->types[$item->getCode()] = $item->getCode(); |
| 55 | 55 | } |
| 56 | 56 | } |
@@ -63,47 +63,47 @@ discard block |
||
| 63 | 63 | * @param array $data List of CSV fields with position as key and data as value |
| 64 | 64 | * @return array List of data which hasn't been imported |
| 65 | 65 | */ |
| 66 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 66 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 67 | 67 | { |
| 68 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' ); |
|
| 68 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'stock'); |
|
| 69 | 69 | $manager->begin(); |
| 70 | 70 | |
| 71 | 71 | try |
| 72 | 72 | { |
| 73 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 74 | - $items = $this->getStockItems( $product->getCode() ); |
|
| 73 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 74 | + $items = $this->getStockItems($product->getCode()); |
|
| 75 | 75 | |
| 76 | - foreach( $map as $pos => $list ) |
|
| 76 | + foreach ($map as $pos => $list) |
|
| 77 | 77 | { |
| 78 | - if( !array_key_exists( 'stock.stocklevel', $list ) ) { |
|
| 78 | + if (!array_key_exists('stock.stocklevel', $list)) { |
|
| 79 | 79 | continue; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $list['stock.productcode'] = $product->getCode(); |
| 83 | - $list['stock.dateback'] = $this->getValue( $list, 'stock.dateback' ); |
|
| 84 | - $list['stock.stocklevel'] = $this->getValue( $list, 'stock.stocklevel' ); |
|
| 85 | - $list['stock.type'] = $this->getValue( $list, 'stock.type', 'default' ); |
|
| 83 | + $list['stock.dateback'] = $this->getValue($list, 'stock.dateback'); |
|
| 84 | + $list['stock.stocklevel'] = $this->getValue($list, 'stock.stocklevel'); |
|
| 85 | + $list['stock.type'] = $this->getValue($list, 'stock.type', 'default'); |
|
| 86 | 86 | |
| 87 | - if( !in_array( $list['stock.type'], $this->types ) ) |
|
| 87 | + if (!in_array($list['stock.type'], $this->types)) |
|
| 88 | 88 | { |
| 89 | - $msg = sprintf( 'Invalid type "%1$s" (%2$s)', $list['stock.type'], 'stock' ); |
|
| 90 | - throw new \Aimeos\Controller\Common\Exception( $msg ); |
|
| 89 | + $msg = sprintf('Invalid type "%1$s" (%2$s)', $list['stock.type'], 'stock'); |
|
| 90 | + throw new \Aimeos\Controller\Common\Exception($msg); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if( ( $item = array_pop( $items ) ) === null ) { |
|
| 93 | + if (($item = array_pop($items)) === null) { |
|
| 94 | 94 | $item = $manager->createItem(); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - $manager->saveItem( $item->fromArray( $list ), false ); |
|
| 97 | + $manager->saveItem($item->fromArray($list), false); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - $manager->deleteItems( array_keys( $items ) ); |
|
| 100 | + $manager->deleteItems(array_keys($items)); |
|
| 101 | 101 | |
| 102 | - $data = $this->getObject()->process( $product, $data ); |
|
| 102 | + $data = $this->getObject()->process($product, $data); |
|
| 103 | 103 | |
| 104 | 104 | $manager->commit(); |
| 105 | 105 | } |
| 106 | - catch( \Exception $e ) |
|
| 106 | + catch (\Exception $e) |
|
| 107 | 107 | { |
| 108 | 108 | $manager->rollback(); |
| 109 | 109 | throw $e; |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | * @param string $code Unique product code |
| 120 | 120 | * @return \Aimeos\MShop\Stock\Item\Iface[] Associative list of stock items |
| 121 | 121 | */ |
| 122 | - protected function getStockItems( $code ) |
|
| 122 | + protected function getStockItems($code) |
|
| 123 | 123 | { |
| 124 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' ); |
|
| 124 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'stock'); |
|
| 125 | 125 | |
| 126 | 126 | $search = $manager->createSearch(); |
| 127 | - $search->setConditions( $search->compare( '==', 'stock.productcode', $code ) ); |
|
| 127 | + $search->setConditions($search->compare('==', 'stock.productcode', $code)); |
|
| 128 | 128 | |
| 129 | - return $manager->searchItems( $search ); |
|
| 129 | + return $manager->searchItems($search); |
|
| 130 | 130 | } |
| 131 | 131 | } |