@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function getName() |
31 | 31 | { |
32 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Removes unfinished orders' ); |
|
32 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Removes unfinished orders'); |
|
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', 'Deletes unfinished orders an makes their products and coupon codes available again' ); |
|
43 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Deletes unfinished orders an makes their products and coupon codes available again'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | public function run() |
53 | 53 | { |
54 | 54 | $context = $this->getContext(); |
55 | - $controller = \Aimeos\Controller\Common\Order\Factory::createController( $context ); |
|
56 | - $baseManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
|
57 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'order' ); |
|
55 | + $controller = \Aimeos\Controller\Common\Order\Factory::createController($context); |
|
56 | + $baseManager = \Aimeos\MShop\Factory::createManager($context, 'order/base'); |
|
57 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'order'); |
|
58 | 58 | |
59 | 59 | /** controller/jobs/order/cleanup/unfinished/keep-hours |
60 | 60 | * Release the ordered products after the configured time if no payment was confirmed |
@@ -74,35 +74,35 @@ discard block |
||
74 | 74 | * @since 2014.07 |
75 | 75 | * @category User |
76 | 76 | */ |
77 | - $hours = $context->getConfig()->get( 'controller/jobs/order/cleanup/unfinished/keep-hours', 24 ); |
|
78 | - $limit = date( 'Y-m-d H:i:s', time() - 3600 * $hours ); |
|
77 | + $hours = $context->getConfig()->get('controller/jobs/order/cleanup/unfinished/keep-hours', 24); |
|
78 | + $limit = date('Y-m-d H:i:s', time() - 3600 * $hours); |
|
79 | 79 | |
80 | 80 | $search = $manager->createSearch(); |
81 | 81 | $expr = array( |
82 | - $search->compare( '<', 'order.mtime', $limit ), |
|
83 | - $search->compare( '==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_UNFINISHED ), |
|
82 | + $search->compare('<', 'order.mtime', $limit), |
|
83 | + $search->compare('==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_UNFINISHED), |
|
84 | 84 | ); |
85 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
85 | + $search->setConditions($search->combine('&&', $expr)); |
|
86 | 86 | |
87 | 87 | $start = 0; |
88 | 88 | |
89 | 89 | do |
90 | 90 | { |
91 | 91 | $baseIds = []; |
92 | - $items = $manager->searchItems( $search ); |
|
92 | + $items = $manager->searchItems($search); |
|
93 | 93 | |
94 | - foreach( $items as $item ) |
|
94 | + foreach ($items as $item) |
|
95 | 95 | { |
96 | - $controller->unblock( $item ); |
|
96 | + $controller->unblock($item); |
|
97 | 97 | $baseIds[] = $item->getBaseId(); |
98 | 98 | } |
99 | 99 | |
100 | - $baseManager->deleteItems( $baseIds ); |
|
100 | + $baseManager->deleteItems($baseIds); |
|
101 | 101 | |
102 | - $count = count( $items ); |
|
102 | + $count = count($items); |
|
103 | 103 | $start += $count; |
104 | - $search->setSlice( $start ); |
|
104 | + $search->setSlice($start); |
|
105 | 105 | } |
106 | - while( $count >= $search->getSliceSize() ); |
|
106 | + while ($count >= $search->getSliceSize()); |
|
107 | 107 | } |
108 | 108 | } |
@@ -15,14 +15,14 @@ discard block |
||
15 | 15 | public static function bootstrap() |
16 | 16 | { |
17 | 17 | self::getAimeos(); |
18 | - \Aimeos\MShop\Factory::setCache( false ); |
|
18 | + \Aimeos\MShop\Factory::setCache(false); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | |
22 | - public static function getContext( $site = 'unittest' ) |
|
22 | + public static function getContext($site = 'unittest') |
|
23 | 23 | { |
24 | - if( !isset( self::$context[$site] ) ) { |
|
25 | - self::$context[$site] = self::createContext( $site ); |
|
24 | + if (!isset(self::$context[$site])) { |
|
25 | + self::$context[$site] = self::createContext($site); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | return clone self::$context[$site]; |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | |
32 | 32 | public static function getAimeos() |
33 | 33 | { |
34 | - if( !isset( self::$aimeos ) ) |
|
34 | + if (!isset(self::$aimeos)) |
|
35 | 35 | { |
36 | 36 | require_once 'Bootstrap.php'; |
37 | - spl_autoload_register( 'Aimeos\\Bootstrap::autoload' ); |
|
37 | + spl_autoload_register('Aimeos\\Bootstrap::autoload'); |
|
38 | 38 | |
39 | - $extdir = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ); |
|
40 | - self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), true ); |
|
39 | + $extdir = dirname(dirname(dirname(dirname(dirname(__FILE__))))); |
|
40 | + self::$aimeos = new \Aimeos\Bootstrap(array($extdir), true); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return self::$aimeos; |
@@ -47,40 +47,40 @@ discard block |
||
47 | 47 | /** |
48 | 48 | * @param string $site |
49 | 49 | */ |
50 | - private static function createContext( $site ) |
|
50 | + private static function createContext($site) |
|
51 | 51 | { |
52 | 52 | $ctx = new \Aimeos\MShop\Context\Item\Standard(); |
53 | 53 | $aimeos = self::getAimeos(); |
54 | 54 | |
55 | 55 | |
56 | - $paths = $aimeos->getConfigPaths( 'mysql' ); |
|
56 | + $paths = $aimeos->getConfigPaths('mysql'); |
|
57 | 57 | $paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config'; |
58 | 58 | $file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser'; |
59 | 59 | |
60 | - $conf = new \Aimeos\MW\Config\PHPArray( [], $paths ); |
|
61 | - $conf = new \Aimeos\MW\Config\Decorator\Memory( $conf ); |
|
62 | - $conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file ); |
|
63 | - $ctx->setConfig( $conf ); |
|
60 | + $conf = new \Aimeos\MW\Config\PHPArray([], $paths); |
|
61 | + $conf = new \Aimeos\MW\Config\Decorator\Memory($conf); |
|
62 | + $conf = new \Aimeos\MW\Config\Decorator\Documentor($conf, $file); |
|
63 | + $ctx->setConfig($conf); |
|
64 | 64 | |
65 | 65 | |
66 | - $dbm = new \Aimeos\MW\DB\Manager\PDO( $conf ); |
|
67 | - $ctx->setDatabaseManager( $dbm ); |
|
66 | + $dbm = new \Aimeos\MW\DB\Manager\PDO($conf); |
|
67 | + $ctx->setDatabaseManager($dbm); |
|
68 | 68 | |
69 | 69 | |
70 | - $logger = new \Aimeos\MW\Logger\File( 'unittest.log', \Aimeos\MW\Logger\Base::DEBUG ); |
|
71 | - $ctx->setLogger( $logger ); |
|
70 | + $logger = new \Aimeos\MW\Logger\File('unittest.log', \Aimeos\MW\Logger\Base::DEBUG); |
|
71 | + $ctx->setLogger($logger); |
|
72 | 72 | |
73 | 73 | |
74 | 74 | $session = new \Aimeos\MW\Session\None(); |
75 | - $ctx->setSession( $session ); |
|
75 | + $ctx->setSession($session); |
|
76 | 76 | |
77 | 77 | |
78 | - $localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $ctx ); |
|
79 | - $locale = $localeManager->bootstrap( $site, '', '', false ); |
|
80 | - $ctx->setLocale( $locale ); |
|
78 | + $localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager($ctx); |
|
79 | + $locale = $localeManager->bootstrap($site, '', '', false); |
|
80 | + $ctx->setLocale($locale); |
|
81 | 81 | |
82 | 82 | |
83 | - $ctx->setEditor( 'core:controller/common' ); |
|
83 | + $ctx->setEditor('core:controller/common'); |
|
84 | 84 | |
85 | 85 | return $ctx; |
86 | 86 | } |
@@ -14,92 +14,92 @@ discard block |
||
14 | 14 | |
15 | 15 | protected function setUp() |
16 | 16 | { |
17 | - \Aimeos\MShop\Factory::setCache( true ); |
|
17 | + \Aimeos\MShop\Factory::setCache(true); |
|
18 | 18 | |
19 | 19 | $context = \TestHelperCntl::getContext(); |
20 | 20 | $aimeos = \TestHelperCntl::getAimeos(); |
21 | 21 | |
22 | - $this->object = new TestAbstract( $context, $aimeos ); |
|
22 | + $this->object = new TestAbstract($context, $aimeos); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | |
26 | 26 | protected function tearDown() |
27 | 27 | { |
28 | - \Aimeos\MShop\Factory::setCache( false ); |
|
28 | + \Aimeos\MShop\Factory::setCache(false); |
|
29 | 29 | \Aimeos\MShop\Factory::clear(); |
30 | 30 | } |
31 | 31 | |
32 | 32 | |
33 | 33 | public function testGetCache() |
34 | 34 | { |
35 | - $cache = $this->object->getCachePublic( 'attribute' ); |
|
35 | + $cache = $this->object->getCachePublic('attribute'); |
|
36 | 36 | |
37 | - $this->assertInstanceOf( '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\Iface', $cache ); |
|
37 | + $this->assertInstanceOf('\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\Iface', $cache); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | |
41 | 41 | public function testGetCacheInvalidType() |
42 | 42 | { |
43 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
44 | - $this->object->getCachePublic( '$' ); |
|
43 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
44 | + $this->object->getCachePublic('$'); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | |
48 | 48 | public function testGetCacheInvalidClass() |
49 | 49 | { |
50 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
51 | - $this->object->getCachePublic( 'unknown' ); |
|
50 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
51 | + $this->object->getCachePublic('unknown'); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | |
55 | 55 | public function testGetCacheInvalidInterface() |
56 | 56 | { |
57 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
58 | - $this->object->getCachePublic( 'attribute', 'unknown' ); |
|
57 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
58 | + $this->object->getCachePublic('attribute', 'unknown'); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | |
62 | 62 | public function testGetProcessors() |
63 | 63 | { |
64 | - $processor = $this->object->getProcessorsPublic( array( 'attribute' => [] ) ); |
|
64 | + $processor = $this->object->getProcessorsPublic(array('attribute' => [])); |
|
65 | 65 | |
66 | - $this->assertInstanceOf( '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Processor\\Iface', $processor ); |
|
66 | + $this->assertInstanceOf('\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Processor\\Iface', $processor); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
70 | 70 | public function testGetProcessorsInvalidType() |
71 | 71 | { |
72 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
73 | - $this->object->getProcessorsPublic( array( '$' => [] ) ); |
|
72 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
73 | + $this->object->getProcessorsPublic(array('$' => [])); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | |
77 | 77 | public function testGetProcessorsInvalidClass() |
78 | 78 | { |
79 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
80 | - $this->object->getProcessorsPublic( array( 'unknown' => [] ) ); |
|
79 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
80 | + $this->object->getProcessorsPublic(array('unknown' => [])); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
84 | 84 | public function testGetProcessorsInvalidInterface() |
85 | 85 | { |
86 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
87 | - $this->object->getProcessorsPublic( array( 'unknown' => [] ) ); |
|
86 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
87 | + $this->object->getProcessorsPublic(array('unknown' => [])); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | |
91 | 91 | public function testGetTypeId() |
92 | 92 | { |
93 | - $typeid = $this->object->getTypeIdPublic( 'attribute/type', 'product', 'color' ); |
|
93 | + $typeid = $this->object->getTypeIdPublic('attribute/type', 'product', 'color'); |
|
94 | 94 | |
95 | - $this->assertNotEquals( null, $typeid ); |
|
95 | + $this->assertNotEquals(null, $typeid); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | |
99 | 99 | public function testGetTypeIdUnknown() |
100 | 100 | { |
101 | - $this->setExpectedException( '\\Aimeos\\Controller\\Jobs\\Exception' ); |
|
102 | - $this->object->getTypeIdPublic( 'attribute/type', 'product', 'unknown' ); |
|
101 | + $this->setExpectedException('\\Aimeos\\Controller\\Jobs\\Exception'); |
|
102 | + $this->object->getTypeIdPublic('attribute/type', 'product', 'unknown'); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
@@ -107,21 +107,21 @@ discard block |
||
107 | 107 | class TestAbstract |
108 | 108 | extends \Aimeos\Controller\Common\Product\Import\Csv\Base |
109 | 109 | { |
110 | - public function getCachePublic( $type, $name = null ) |
|
110 | + public function getCachePublic($type, $name = null) |
|
111 | 111 | { |
112 | - return $this->getCache( $type, $name ); |
|
112 | + return $this->getCache($type, $name); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | |
116 | - public function getProcessorsPublic( array $mappings ) |
|
116 | + public function getProcessorsPublic(array $mappings) |
|
117 | 117 | { |
118 | - return $this->getProcessors( $mappings ); |
|
118 | + return $this->getProcessors($mappings); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | |
122 | - public function getTypeIdPublic( $path, $domain, $code ) |
|
122 | + public function getTypeIdPublic($path, $domain, $code) |
|
123 | 123 | { |
124 | - return $this->getTypeId( $path, $domain, $code ); |
|
124 | + return $this->getTypeId($path, $domain, $code); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
42 | 42 | */ |
43 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
|
43 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context) |
|
44 | 44 | { |
45 | - parent::__construct( $context ); |
|
45 | + parent::__construct($context); |
|
46 | 46 | |
47 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'attribute' ); |
|
48 | - $result = $manager->searchItems( $manager->createSearch() ); |
|
47 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'attribute'); |
|
48 | + $result = $manager->searchItems($manager->createSearch()); |
|
49 | 49 | |
50 | - foreach( $result as $id => $item ) { |
|
51 | - $this->attributes[ $item->getCode() ][ $item->getType() ] = $item; |
|
50 | + foreach ($result as $id => $item) { |
|
51 | + $this->attributes[$item->getCode()][$item->getType()] = $item; |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
@@ -60,24 +60,24 @@ discard block |
||
60 | 60 | * @param string|null $type Attribute type |
61 | 61 | * @return \Aimeos\MShop\Attribute\Item\Iface|null Attribute object or null if not found |
62 | 62 | */ |
63 | - public function get( $code, $type = null ) |
|
63 | + public function get($code, $type = null) |
|
64 | 64 | { |
65 | - if( isset( $this->attributes[$code] ) && isset( $this->attributes[$code][$type] ) ) { |
|
65 | + if (isset($this->attributes[$code]) && isset($this->attributes[$code][$type])) { |
|
66 | 66 | return $this->attributes[$code][$type]; |
67 | 67 | } |
68 | 68 | |
69 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
69 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
70 | 70 | |
71 | 71 | $search = $manager->createSearch(); |
72 | 72 | $expr = array( |
73 | - $search->compare( '==', 'attribute.code', $code ), |
|
74 | - $search->compare( '==', 'attribute.type.code', $type ), |
|
73 | + $search->compare('==', 'attribute.code', $code), |
|
74 | + $search->compare('==', 'attribute.type.code', $type), |
|
75 | 75 | ); |
76 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
76 | + $search->setConditions($search->combine('&&', $expr)); |
|
77 | 77 | |
78 | - $result = $manager->searchItems( $search ); |
|
78 | + $result = $manager->searchItems($search); |
|
79 | 79 | |
80 | - if( ( $item = reset( $result ) ) !== false ) |
|
80 | + if (($item = reset($result)) !== false) |
|
81 | 81 | { |
82 | 82 | $this->attributes[$code][$type] = $item; |
83 | 83 | return $item; |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @param \Aimeos\MShop\Common\Item\Iface $item Attribute object |
92 | 92 | */ |
93 | - public function set( \Aimeos\MShop\Common\Item\Iface $item ) |
|
93 | + public function set(\Aimeos\MShop\Common\Item\Iface $item) |
|
94 | 94 | { |
95 | 95 | $code = $item->getCode(); |
96 | 96 | |
97 | - if( !isset( $this->attributes[$code] ) || !is_array( $this->attributes[$code] ) ) { |
|
97 | + if (!isset($this->attributes[$code]) || !is_array($this->attributes[$code])) { |
|
98 | 98 | $this->attributes[$code] = []; |
99 | 99 | } |
100 | 100 | |
101 | - $this->attributes[$code][ $item->getType() ] = $item; |
|
101 | + $this->attributes[$code][$item->getType()] = $item; |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | \ No newline at end of file |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | * @param array $data Associative list of product codes and lists of CSV field indexes and their data |
31 | 31 | * @return array Associative list of CSV field indexes and their converted data |
32 | 32 | */ |
33 | - protected function convertData( array $convlist, array $data ) |
|
33 | + protected function convertData(array $convlist, array $data) |
|
34 | 34 | { |
35 | - foreach( $convlist as $idx => $converter ) |
|
35 | + foreach ($convlist as $idx => $converter) |
|
36 | 36 | { |
37 | - foreach( $data as $code => $list ) |
|
37 | + foreach ($data as $code => $list) |
|
38 | 38 | { |
39 | - if( isset( $list[$idx] ) ) { |
|
40 | - $data[$code][$idx] = $converter->translate( $list[$idx] ); |
|
39 | + if (isset($list[$idx])) { |
|
40 | + $data[$code][$idx] = $converter->translate($list[$idx]); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | } |
@@ -53,38 +53,38 @@ discard block |
||
53 | 53 | * @param string|null Name of the cache implementation |
54 | 54 | * @return \Aimeos\Controller\Common\Product\Import\Csv\Cache\Iface Cache object |
55 | 55 | */ |
56 | - protected function getCache( $type, $name = null ) |
|
56 | + protected function getCache($type, $name = null) |
|
57 | 57 | { |
58 | 58 | $context = $this->getContext(); |
59 | 59 | $config = $context->getConfig(); |
60 | 60 | $iface = '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\Iface'; |
61 | 61 | |
62 | - if( ctype_alnum( $type ) === false ) |
|
62 | + if (ctype_alnum($type) === false) |
|
63 | 63 | { |
64 | 64 | $classname = is_string($name) ? '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\' . $type : '<not a string>'; |
65 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
65 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in class name "%1$s"', $classname)); |
|
66 | 66 | } |
67 | 67 | |
68 | - if( $name === null ) { |
|
69 | - $name = $config->get( 'controller/common/product/import/csv/cache/' . $type . '/name', 'Standard' ); |
|
68 | + if ($name === null) { |
|
69 | + $name = $config->get('controller/common/product/import/csv/cache/' . $type . '/name', 'Standard'); |
|
70 | 70 | } |
71 | 71 | |
72 | - if( ctype_alnum( $name ) === false ) |
|
72 | + if (ctype_alnum($name) === false) |
|
73 | 73 | { |
74 | 74 | $classname = is_string($name) ? '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\' . $type . '\\' . $name : '<not a string>'; |
75 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
75 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in class name "%1$s"', $classname)); |
|
76 | 76 | } |
77 | 77 | |
78 | - $classname = '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\' . ucfirst( $type ) . '\\' . $name; |
|
78 | + $classname = '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Cache\\' . ucfirst($type) . '\\' . $name; |
|
79 | 79 | |
80 | - if( class_exists( $classname ) === false ) { |
|
81 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" not found', $classname ) ); |
|
80 | + if (class_exists($classname) === false) { |
|
81 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Class "%1$s" not found', $classname)); |
|
82 | 82 | } |
83 | 83 | |
84 | - $object = new $classname( $context ); |
|
84 | + $object = new $classname($context); |
|
85 | 85 | |
86 | - if( !( $object instanceof $iface ) ) { |
|
87 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" does not implement interface "%2$s"', $classname, $iface ) ); |
|
86 | + if (!($object instanceof $iface)) { |
|
87 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Class "%1$s" does not implement interface "%2$s"', $classname, $iface)); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | return $object; |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | * @param array $convmap List of converter names for the values at the position in the CSV file |
98 | 98 | * @return array Associative list of positions and converter objects |
99 | 99 | */ |
100 | - protected function getConverterList( array $convmap ) |
|
100 | + protected function getConverterList(array $convmap) |
|
101 | 101 | { |
102 | 102 | $convlist = []; |
103 | 103 | |
104 | - foreach( $convmap as $idx => $name ) { |
|
105 | - $convlist[$idx] = \Aimeos\MW\Convert\Factory::createConverter( $name ); |
|
104 | + foreach ($convmap as $idx => $name) { |
|
105 | + $convlist[$idx] = \Aimeos\MW\Convert\Factory::createConverter($name); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return $convlist; |
@@ -117,15 +117,15 @@ discard block |
||
117 | 117 | * @param integer $codePos Column position which contains the unique product code (starting from 0) |
118 | 118 | * @return array List of arrays with product codes as keys and list of values from the CSV file |
119 | 119 | */ |
120 | - protected function getData( \Aimeos\MW\Container\Content\Iface $content, $maxcnt, $codePos ) |
|
120 | + protected function getData(\Aimeos\MW\Container\Content\Iface $content, $maxcnt, $codePos) |
|
121 | 121 | { |
122 | 122 | $count = 0; |
123 | 123 | $data = []; |
124 | 124 | |
125 | - while( $content->valid() && $count++ < $maxcnt ) |
|
125 | + while ($content->valid() && $count++ < $maxcnt) |
|
126 | 126 | { |
127 | 127 | $row = $content->current(); |
128 | - $data[ $row[$codePos] ] = $row; |
|
128 | + $data[$row[$codePos]] = $row; |
|
129 | 129 | $content->next(); |
130 | 130 | } |
131 | 131 | |
@@ -222,21 +222,21 @@ discard block |
||
222 | 222 | * @param array $mapping List of domain item keys with the CSV field position as key |
223 | 223 | * @return array List of associative arrays containing the chunked properties |
224 | 224 | */ |
225 | - protected function getMappedChunk( array &$data, array $mapping ) |
|
225 | + protected function getMappedChunk(array &$data, array $mapping) |
|
226 | 226 | { |
227 | 227 | $idx = 0; |
228 | 228 | $map = []; |
229 | 229 | |
230 | - foreach( $mapping as $pos => $key ) |
|
230 | + foreach ($mapping as $pos => $key) |
|
231 | 231 | { |
232 | - if( isset( $map[$idx][$key] ) ) { |
|
232 | + if (isset($map[$idx][$key])) { |
|
233 | 233 | $idx++; |
234 | 234 | } |
235 | 235 | |
236 | - if( isset( $data[$pos] ) ) |
|
236 | + if (isset($data[$pos])) |
|
237 | 237 | { |
238 | 238 | $map[$idx][$key] = $data[$pos]; |
239 | - unset( $data[$pos] ); |
|
239 | + unset($data[$pos]); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
@@ -250,39 +250,39 @@ discard block |
||
250 | 250 | * @param array $mappings Associative list of processor types as keys and index/data mappings as values |
251 | 251 | * @return \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface Processor object |
252 | 252 | */ |
253 | - protected function getProcessors( array $mappings ) |
|
253 | + protected function getProcessors(array $mappings) |
|
254 | 254 | { |
255 | 255 | $context = $this->getContext(); |
256 | 256 | $config = $context->getConfig(); |
257 | 257 | $iface = '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Processor\\Iface'; |
258 | - $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Done( $context, [] ); |
|
258 | + $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Done($context, []); |
|
259 | 259 | |
260 | - foreach( $mappings as $type => $mapping ) |
|
260 | + foreach ($mappings as $type => $mapping) |
|
261 | 261 | { |
262 | - if( ctype_alnum( $type ) === false ) |
|
262 | + if (ctype_alnum($type) === false) |
|
263 | 263 | { |
264 | 264 | $classname = is_string($type) ? '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Processor\\' . $type : '<not a string>'; |
265 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
265 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in class name "%1$s"', $classname)); |
|
266 | 266 | } |
267 | 267 | |
268 | - $name = $config->get( 'controller/common/product/import/csv/processor/' . $type . '/name', 'Standard' ); |
|
268 | + $name = $config->get('controller/common/product/import/csv/processor/' . $type . '/name', 'Standard'); |
|
269 | 269 | |
270 | - if( ctype_alnum( $name ) === false ) |
|
270 | + if (ctype_alnum($name) === false) |
|
271 | 271 | { |
272 | 272 | $classname = is_string($name) ? '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Processor\\' . $type . '\\' . $name : '<not a string>'; |
273 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); |
|
273 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in class name "%1$s"', $classname)); |
|
274 | 274 | } |
275 | 275 | |
276 | - $classname = '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Processor\\' . ucfirst( $type ) . '\\' . $name; |
|
276 | + $classname = '\\Aimeos\\Controller\\Common\\Product\\Import\\Csv\\Processor\\' . ucfirst($type) . '\\' . $name; |
|
277 | 277 | |
278 | - if( class_exists( $classname ) === false ) { |
|
279 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" not found', $classname ) ); |
|
278 | + if (class_exists($classname) === false) { |
|
279 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Class "%1$s" not found', $classname)); |
|
280 | 280 | } |
281 | 281 | |
282 | - $object = new $classname( $context, $mapping, $object ); |
|
282 | + $object = new $classname($context, $mapping, $object); |
|
283 | 283 | |
284 | - if( !( $object instanceof $iface ) ) { |
|
285 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Class "%1$s" does not implement interface "%2$s"', $classname, $iface ) ); |
|
284 | + if (!($object instanceof $iface)) { |
|
285 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Class "%1$s" does not implement interface "%2$s"', $classname, $iface)); |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | |
@@ -297,17 +297,17 @@ discard block |
||
297 | 297 | * @param array $domains List of domains whose items should be fetched too |
298 | 298 | * @return array Associative list of product codes as key and product items as value |
299 | 299 | */ |
300 | - protected function getProducts( array $codes, array $domains ) |
|
300 | + protected function getProducts(array $codes, array $domains) |
|
301 | 301 | { |
302 | 302 | $result = []; |
303 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product' ); |
|
303 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product'); |
|
304 | 304 | |
305 | 305 | $search = $manager->createSearch(); |
306 | - $search->setConditions( $search->compare( '==', 'product.code', $codes ) ); |
|
307 | - $search->setSlice( 0, count( $codes ) ); |
|
306 | + $search->setConditions($search->compare('==', 'product.code', $codes)); |
|
307 | + $search->setSlice(0, count($codes)); |
|
308 | 308 | |
309 | - foreach( $manager->searchItems( $search, $domains ) as $item ) { |
|
310 | - $result[ $item->getCode() ] = $item; |
|
309 | + foreach ($manager->searchItems($search, $domains) as $item) { |
|
310 | + $result[$item->getCode()] = $item; |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | return $result; |
@@ -322,23 +322,23 @@ discard block |
||
322 | 322 | * @param string $code Unique code of the type item |
323 | 323 | * @return string Unique ID of the type item |
324 | 324 | */ |
325 | - protected function getTypeId( $path, $domain, $code ) |
|
325 | + protected function getTypeId($path, $domain, $code) |
|
326 | 326 | { |
327 | - if( !isset( self::$types[$path][$domain] ) ) |
|
327 | + if (!isset(self::$types[$path][$domain])) |
|
328 | 328 | { |
329 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $path ); |
|
330 | - $key = str_replace( '/', '.', $path ); |
|
329 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $path); |
|
330 | + $key = str_replace('/', '.', $path); |
|
331 | 331 | |
332 | 332 | $search = $manager->createSearch(); |
333 | - $search->setConditions( $search->compare( '==', $key . '.domain', $domain ) ); |
|
333 | + $search->setConditions($search->compare('==', $key . '.domain', $domain)); |
|
334 | 334 | |
335 | - foreach( $manager->searchItems( $search ) as $id => $item ) { |
|
336 | - self::$types[$path][$domain][ $item->getCode() ] = $id; |
|
335 | + foreach ($manager->searchItems($search) as $id => $item) { |
|
336 | + self::$types[$path][$domain][$item->getCode()] = $id; |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
340 | - if( !isset( self::$types[$path][$domain][$code] ) ) { |
|
341 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No type item for "%1$s/%2$s" in "%3$s" found', $domain, $code, $path ) ); |
|
340 | + if (!isset(self::$types[$path][$domain][$code])) { |
|
341 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('No type item for "%1$s/%2$s" in "%3$s" found', $domain, $code, $path)); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | return self::$types[$path][$domain][$code]; |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
44 | 44 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
45 | 45 | */ |
46 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
47 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
46 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
47 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
48 | 48 | { |
49 | - parent::__construct( $context, $mapping, $object ); |
|
49 | + parent::__construct($context, $mapping, $object); |
|
50 | 50 | |
51 | 51 | /** controller/common/product/import/csv/processor/product/listtypes |
52 | 52 | * Names of the product list types that are updated or removed |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | * @see controller/common/product/import/csv/processor/price/listtypes |
74 | 74 | * @see controller/common/product/import/csv/processor/text/listtypes |
75 | 75 | */ |
76 | - $default = array( 'default', 'suggestion' ); |
|
76 | + $default = array('default', 'suggestion'); |
|
77 | 77 | $key = 'controller/common/product/import/csv/processor/product/listtypes'; |
78 | - $this->listTypes = $context->getConfig()->get( $key, $default ); |
|
78 | + $this->listTypes = $context->getConfig()->get($key, $default); |
|
79 | 79 | |
80 | - $this->cache = $this->getCache( 'product' ); |
|
80 | + $this->cache = $this->getCache('product'); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | * @param array $data List of CSV fields with position as key and data as value |
89 | 89 | * @return array List of data which hasn't been imported |
90 | 90 | */ |
91 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
91 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
92 | 92 | { |
93 | 93 | $context = $this->getContext(); |
94 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
95 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
94 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
95 | + $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n"); |
|
96 | 96 | |
97 | - $this->cache->set( $product ); |
|
97 | + $this->cache->set($product); |
|
98 | 98 | |
99 | 99 | $manager->begin(); |
100 | 100 | |
@@ -102,37 +102,37 @@ discard block |
||
102 | 102 | { |
103 | 103 | $types = []; |
104 | 104 | |
105 | - foreach( $this->getMappedChunk( $data, $this->getMapping() ) as $list ) |
|
105 | + foreach ($this->getMappedChunk($data, $this->getMapping()) as $list) |
|
106 | 106 | { |
107 | - if( $this->checkEntry( $list ) === false ) { |
|
107 | + if ($this->checkEntry($list) === false) { |
|
108 | 108 | continue; |
109 | 109 | } |
110 | 110 | |
111 | 111 | $listMap = []; |
112 | - $type = ( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
112 | + $type = (isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
113 | 113 | $types[] = $type; |
114 | 114 | |
115 | - foreach( explode( $separator, $list['product.code'] ) as $code ) |
|
115 | + foreach (explode($separator, $list['product.code']) as $code) |
|
116 | 116 | { |
117 | - if( ( $prodid = $this->cache->get( $code ) ) === null ) |
|
117 | + if (($prodid = $this->cache->get($code)) === null) |
|
118 | 118 | { |
119 | 119 | $msg = 'No product for code "%1$s" available when importing product with code "%2$s"'; |
120 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( $msg, $code, $product->getCode() ) ); |
|
120 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf($msg, $code, $product->getCode())); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | $listMap[$prodid] = $list; |
124 | 124 | } |
125 | 125 | |
126 | - $manager->updateListItems( $product, $listMap, 'product', $type ); |
|
126 | + $manager->updateListItems($product, $listMap, 'product', $type); |
|
127 | 127 | } |
128 | 128 | |
129 | - $this->deleteListItems( $product->getId(), $types ); |
|
129 | + $this->deleteListItems($product->getId(), $types); |
|
130 | 130 | |
131 | - $data = $this->getObject()->process( $product, $data ); |
|
131 | + $data = $this->getObject()->process($product, $data); |
|
132 | 132 | |
133 | 133 | $manager->commit(); |
134 | 134 | } |
135 | - catch( \Exception $e ) |
|
135 | + catch (\Exception $e) |
|
136 | 136 | { |
137 | 137 | $manager->rollback(); |
138 | 138 | throw $e; |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | * @param array $list Associative list of key/value pairs from the mapping |
149 | 149 | * @return boolean True if valid, false if not |
150 | 150 | */ |
151 | - protected function checkEntry( array $list ) |
|
151 | + protected function checkEntry(array $list) |
|
152 | 152 | { |
153 | - if( !isset( $list['product.code'] ) || $list['product.code'] === '' || isset( $list['product.lists.type'] ) |
|
154 | - && $this->listTypes !== null && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
153 | + if (!isset($list['product.code']) || $list['product.code'] === '' || isset($list['product.lists.type']) |
|
154 | + && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
155 | 155 | ) { |
156 | 156 | return false; |
157 | 157 | } |
@@ -166,19 +166,19 @@ discard block |
||
166 | 166 | * @param string $prodId Unique product ID |
167 | 167 | * @param array $types List of types that have been updated |
168 | 168 | */ |
169 | - protected function deleteListItems( $prodId, array $types ) |
|
169 | + protected function deleteListItems($prodId, array $types) |
|
170 | 170 | { |
171 | - $codes = array_diff( $this->listTypes, $types ); |
|
172 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
171 | + $codes = array_diff($this->listTypes, $types); |
|
172 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
173 | 173 | |
174 | 174 | $search = $manager->createSearch(); |
175 | 175 | $expr = array( |
176 | - $search->compare( '==', 'product.lists.parentid', $prodId ), |
|
177 | - $search->compare( '==', 'product.lists.domain', 'product' ), |
|
178 | - $search->compare( '==', 'product.lists.type.code', $codes ), |
|
176 | + $search->compare('==', 'product.lists.parentid', $prodId), |
|
177 | + $search->compare('==', 'product.lists.domain', 'product'), |
|
178 | + $search->compare('==', 'product.lists.type.code', $codes), |
|
179 | 179 | ); |
180 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
180 | + $search->setConditions($search->combine('&&', $expr)); |
|
181 | 181 | |
182 | - $manager->deleteItems( array_keys( $manager->searchItems( $search ) ) ); |
|
182 | + $manager->deleteItems(array_keys($manager->searchItems($search))); |
|
183 | 183 | } |
184 | 184 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getName() |
30 | 30 | { |
31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Product site map' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Product site map'); |
|
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', 'Creates a product site map for search engines' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Creates a product site map for search engines'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | { |
53 | 53 | $container = $this->createContainer(); |
54 | 54 | |
55 | - $files = $this->export( $container ); |
|
56 | - $this->createSitemapIndex( $container, $files ); |
|
55 | + $files = $this->export($container); |
|
56 | + $this->createSitemapIndex($container, $files); |
|
57 | 57 | |
58 | 58 | $container->close(); |
59 | 59 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param \Aimeos\MW\Container\Content\Iface $content File content object |
66 | 66 | * @param \Aimeos\MShop\Product\Item\Iface[] $items List of product items |
67 | 67 | */ |
68 | - protected function addItems( \Aimeos\MW\Container\Content\Iface $content, array $items ) |
|
68 | + protected function addItems(\Aimeos\MW\Container\Content\Iface $content, array $items) |
|
69 | 69 | { |
70 | 70 | $config = $this->getContext()->getConfig(); |
71 | 71 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @see controller/jobs/product/export/sitemap/max-items |
97 | 97 | * @see controller/jobs/product/export/sitemap/max-query |
98 | 98 | */ |
99 | - $changefreq = $config->get( 'controller/jobs/product/export/sitemap/changefreq', 'daily' ); |
|
99 | + $changefreq = $config->get('controller/jobs/product/export/sitemap/changefreq', 'daily'); |
|
100 | 100 | |
101 | 101 | /** controller/jobs/product/export/sitemap/standard/template-items |
102 | 102 | * Relative path to the XML items template of the product site map job controller. |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $view->siteItems = $items; |
130 | 130 | $view->siteFreq = $changefreq; |
131 | 131 | |
132 | - $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); |
|
132 | + $content->add($view->render($context->getConfig()->get($tplconf, $default))); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @see controller/jobs/product/export/sitemap/max-query |
176 | 176 | * @see controller/jobs/product/export/sitemap/changefreq |
177 | 177 | */ |
178 | - $location = $config->get( 'controller/jobs/product/export/sitemap/location', sys_get_temp_dir() ); |
|
178 | + $location = $config->get('controller/jobs/product/export/sitemap/location', sys_get_temp_dir()); |
|
179 | 179 | |
180 | 180 | /** controller/jobs/product/export/sitemap/container/options |
181 | 181 | * List of file container options for the site map files |
@@ -196,10 +196,10 @@ discard block |
||
196 | 196 | * @see controller/jobs/product/export/sitemap/max-query |
197 | 197 | * @see controller/jobs/product/export/sitemap/changefreq |
198 | 198 | */ |
199 | - $default = array( 'gzip-mode' => 'wb' ); |
|
200 | - $options = $config->get( 'controller/jobs/product/export/sitemap/container/options', $default ); |
|
199 | + $default = array('gzip-mode' => 'wb'); |
|
200 | + $options = $config->get('controller/jobs/product/export/sitemap/container/options', $default); |
|
201 | 201 | |
202 | - return \Aimeos\MW\Container\Factory::getContainer( $location, 'Directory', 'Gzip', $options ); |
|
202 | + return \Aimeos\MW\Container\Factory::getContainer($location, 'Directory', 'Gzip', $options); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @param integer $filenum New file number |
211 | 211 | * @return \Aimeos\MW\Container\Content\Iface New content object |
212 | 212 | */ |
213 | - protected function createContent( \Aimeos\MW\Container\Iface $container, $filenum ) |
|
213 | + protected function createContent(\Aimeos\MW\Container\Iface $container, $filenum) |
|
214 | 214 | { |
215 | 215 | /** controller/jobs/product/export/sitemap/standard/template-header |
216 | 216 | * Relative path to the XML site map header template of the product site map job controller. |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | $context = $this->getContext(); |
241 | 241 | $view = $context->getView(); |
242 | 242 | |
243 | - $content = $container->create( $this->getFilename( $filenum ) ); |
|
244 | - $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); |
|
245 | - $container->add( $content ); |
|
243 | + $content = $container->create($this->getFilename($filenum)); |
|
244 | + $content->add($view->render($context->getConfig()->get($tplconf, $default))); |
|
245 | + $container->add($content); |
|
246 | 246 | |
247 | 247 | return $content; |
248 | 248 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * |
254 | 254 | * @param \Aimeos\MW\Container\Content\Iface $content |
255 | 255 | */ |
256 | - protected function closeContent( \Aimeos\MW\Container\Content\Iface $content ) |
|
256 | + protected function closeContent(\Aimeos\MW\Container\Content\Iface $content) |
|
257 | 257 | { |
258 | 258 | /** controller/jobs/product/export/sitemap/standard/template-footer |
259 | 259 | * Relative path to the XML site map footer template of the product site map job controller. |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | $context = $this->getContext(); |
284 | 284 | $view = $context->getView(); |
285 | 285 | |
286 | - $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); |
|
286 | + $content->add($view->render($context->getConfig()->get($tplconf, $default))); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * @param \Aimeos\MW\Container\Iface $container File container object |
294 | 294 | * @param array $files List of generated site map file names |
295 | 295 | */ |
296 | - protected function createSitemapIndex( \Aimeos\MW\Container\Iface $container, array $files ) |
|
296 | + protected function createSitemapIndex(\Aimeos\MW\Container\Iface $container, array $files) |
|
297 | 297 | { |
298 | 298 | /** controller/jobs/product/export/sitemap/standard/template-index |
299 | 299 | * Relative path to the XML site map index template of the product site map job controller. |
@@ -325,9 +325,9 @@ discard block |
||
325 | 325 | |
326 | 326 | $view->siteFiles = $files; |
327 | 327 | |
328 | - $content = $container->create( 'aimeos-sitemap-index.xml' ); |
|
329 | - $content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) ); |
|
330 | - $container->add( $content ); |
|
328 | + $content = $container->create('aimeos-sitemap-index.xml'); |
|
329 | + $content->add($view->render($context->getConfig()->get($tplconf, $default))); |
|
330 | + $container->add($content); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | |
@@ -338,11 +338,11 @@ discard block |
||
338 | 338 | * @param mixed $default Default value if name is unknown |
339 | 339 | * @return mixed Configuration value |
340 | 340 | */ |
341 | - protected function getConfig( $name, $default = null ) |
|
341 | + protected function getConfig($name, $default = null) |
|
342 | 342 | { |
343 | 343 | $config = $this->getContext()->getConfig(); |
344 | 344 | |
345 | - switch( $name ) |
|
345 | + switch ($name) |
|
346 | 346 | { |
347 | 347 | case 'domain': |
348 | 348 | return []; |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @see controller/jobs/product/export/sitemap/max-query |
370 | 370 | * @see controller/jobs/product/export/sitemap/changefreq |
371 | 371 | */ |
372 | - return $config->get( 'controller/jobs/product/export/sitemap/max-items', 50000 ); |
|
372 | + return $config->get('controller/jobs/product/export/sitemap/max-items', 50000); |
|
373 | 373 | |
374 | 374 | case 'max-query': |
375 | 375 | /** controller/jobs/product/export/sitemap/max-query |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | * @see controller/jobs/product/export/sitemap/max-items |
390 | 390 | * @see controller/jobs/product/export/sitemap/changefreq |
391 | 391 | */ |
392 | - return $config->get( 'controller/jobs/product/export/sitemap/max-query', 1000 ); |
|
392 | + return $config->get('controller/jobs/product/export/sitemap/max-query', 1000); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | return $default; |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | * @param integer $number Current file number |
403 | 403 | * @return string New file name |
404 | 404 | */ |
405 | - protected function getFilename( $number ) |
|
405 | + protected function getFilename($number) |
|
406 | 406 | { |
407 | - return sprintf( 'aimeos-sitemap-%d.xml', $number ); |
|
407 | + return sprintf('aimeos-sitemap-%d.xml', $number); |
|
408 | 408 | } |
409 | 409 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getName() |
30 | 30 | { |
31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Product import CSV' ); |
|
31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Product 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 products from CSV files' ); |
|
42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Imports new and updates existing products from CSV files'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $context = $this->getContext(); |
55 | 55 | $config = $context->getConfig(); |
56 | 56 | $logger = $context->getLogger(); |
57 | - $domains = array( 'attribute', 'media', 'price', 'product', 'text' ); |
|
57 | + $domains = array('attribute', 'media', 'price', 'product', 'text'); |
|
58 | 58 | $mappings = $this->getDefaultMapping(); |
59 | 59 | |
60 | 60 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @see controller/common/product/import/csv/converter |
75 | 75 | * @see controller/common/product/import/csv/max-size |
76 | 76 | */ |
77 | - $domains = $config->get( 'controller/common/product/import/csv/domains', $domains ); |
|
77 | + $domains = $config->get('controller/common/product/import/csv/domains', $domains); |
|
78 | 78 | |
79 | 79 | /** controller/jobs/product/import/csv/domains |
80 | 80 | * List of item domain names that should be retrieved along with the product items |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @see controller/jobs/product/import/csv/backup |
95 | 95 | * @see controller/common/product/import/csv/max-size |
96 | 96 | */ |
97 | - $domains = $config->get( 'controller/jobs/product/import/csv/domains', $domains ); |
|
97 | + $domains = $config->get('controller/jobs/product/import/csv/domains', $domains); |
|
98 | 98 | |
99 | 99 | |
100 | 100 | /** controller/common/product/import/csv/mapping |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @see controller/common/product/import/csv/converter |
123 | 123 | * @see controller/common/product/import/csv/max-size |
124 | 124 | */ |
125 | - $mappings = $config->get( 'controller/common/product/import/csv/mapping', $mappings ); |
|
125 | + $mappings = $config->get('controller/common/product/import/csv/mapping', $mappings); |
|
126 | 126 | |
127 | 127 | /** controller/jobs/product/import/csv/mapping |
128 | 128 | * List of mappings between the position in the CSV file and item keys |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @see controller/jobs/product/import/csv/backup |
143 | 143 | * @see controller/common/product/import/csv/max-size |
144 | 144 | */ |
145 | - $mappings = $config->get( 'controller/jobs/product/import/csv/mapping', $mappings ); |
|
145 | + $mappings = $config->get('controller/jobs/product/import/csv/mapping', $mappings); |
|
146 | 146 | |
147 | 147 | |
148 | 148 | /** controller/common/product/import/csv/converter |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @see controller/common/product/import/csv/mapping |
185 | 185 | * @see controller/common/product/import/csv/max-size |
186 | 186 | */ |
187 | - $converters = $config->get( 'controller/common/product/import/csv/converter', [] ); |
|
187 | + $converters = $config->get('controller/common/product/import/csv/converter', []); |
|
188 | 188 | |
189 | 189 | /** controller/jobs/product/import/csv/converter |
190 | 190 | * List of converter names for the values at the position in the CSV file |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @see controller/jobs/product/import/csv/backup |
205 | 205 | * @see controller/common/product/import/csv/max-size |
206 | 206 | */ |
207 | - $converters = $config->get( 'controller/jobs/product/import/csv/converter', $converters ); |
|
207 | + $converters = $config->get('controller/jobs/product/import/csv/converter', $converters); |
|
208 | 208 | |
209 | 209 | |
210 | 210 | /** controller/common/product/import/csv/max-size |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * @see controller/common/product/import/csv/mapping |
225 | 225 | * @see controller/common/product/import/csv/converter |
226 | 226 | */ |
227 | - $maxcnt = (int) $config->get( 'controller/common/product/import/csv/max-size', 1000 ); |
|
227 | + $maxcnt = (int) $config->get('controller/common/product/import/csv/max-size', 1000); |
|
228 | 228 | |
229 | 229 | |
230 | 230 | /** controller/jobs/product/import/csv/skip-lines |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @see controller/jobs/product/import/csv/backup |
247 | 247 | * @see controller/common/product/import/csv/max-size |
248 | 248 | */ |
249 | - $skiplines = (int) $config->get( 'controller/jobs/product/import/csv/skip-lines', 0 ); |
|
249 | + $skiplines = (int) $config->get('controller/jobs/product/import/csv/skip-lines', 0); |
|
250 | 250 | |
251 | 251 | |
252 | 252 | /** controller/jobs/product/import/csv/strict |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @see controller/jobs/product/import/csv/backup |
271 | 271 | * @see controller/common/product/import/csv/max-size |
272 | 272 | */ |
273 | - $strict = (bool) $config->get( 'controller/jobs/product/import/csv/strict', true ); |
|
273 | + $strict = (bool) $config->get('controller/jobs/product/import/csv/strict', true); |
|
274 | 274 | |
275 | 275 | |
276 | 276 | /** controller/jobs/product/import/csv/backup |
@@ -303,74 +303,74 @@ discard block |
||
303 | 303 | * @see controller/jobs/product/import/csv/strict |
304 | 304 | * @see controller/common/product/import/csv/max-size |
305 | 305 | */ |
306 | - $backup = $config->get( 'controller/jobs/product/import/csv/backup' ); |
|
306 | + $backup = $config->get('controller/jobs/product/import/csv/backup'); |
|
307 | 307 | |
308 | 308 | |
309 | - if( !isset( $mappings['item'] ) || !is_array( $mappings['item'] ) ) |
|
309 | + if (!isset($mappings['item']) || !is_array($mappings['item'])) |
|
310 | 310 | { |
311 | - $msg = sprintf( 'Required mapping key "%1$s" is missing or contains no array', 'item' ); |
|
312 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
311 | + $msg = sprintf('Required mapping key "%1$s" is missing or contains no array', 'item'); |
|
312 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | try |
316 | 316 | { |
317 | 317 | $procMappings = $mappings; |
318 | - unset( $procMappings['item'] ); |
|
318 | + unset($procMappings['item']); |
|
319 | 319 | |
320 | - $codePos = $this->getCodePosition( $mappings['item'] ); |
|
321 | - $convlist = $this->getConverterList( $converters ); |
|
322 | - $processor = $this->getProcessors( $procMappings ); |
|
320 | + $codePos = $this->getCodePosition($mappings['item']); |
|
321 | + $convlist = $this->getConverterList($converters); |
|
322 | + $processor = $this->getProcessors($procMappings); |
|
323 | 323 | $container = $this->getContainer(); |
324 | 324 | $path = $container->getName(); |
325 | 325 | |
326 | - $msg = sprintf( 'Started product import from "%1$s" (%2$s)', $path, __CLASS__ ); |
|
327 | - $logger->log( $msg, \Aimeos\MW\Logger\Base::NOTICE ); |
|
326 | + $msg = sprintf('Started product import from "%1$s" (%2$s)', $path, __CLASS__); |
|
327 | + $logger->log($msg, \Aimeos\MW\Logger\Base::NOTICE); |
|
328 | 328 | |
329 | - foreach( $container as $content ) |
|
329 | + foreach ($container as $content) |
|
330 | 330 | { |
331 | 331 | $name = $content->getName(); |
332 | 332 | |
333 | - for( $i = 0; $i < $skiplines; $i++ ) { |
|
333 | + for ($i = 0; $i < $skiplines; $i++) { |
|
334 | 334 | $content->next(); |
335 | 335 | } |
336 | 336 | |
337 | - while( ( $data = $this->getData( $content, $maxcnt, $codePos ) ) !== [] ) |
|
337 | + while (($data = $this->getData($content, $maxcnt, $codePos)) !== []) |
|
338 | 338 | { |
339 | - $data = $this->convertData( $convlist, $data ); |
|
340 | - $products = $this->getProducts( array_keys( $data ), $domains ); |
|
341 | - $errcnt = $this->import( $products, $data, $mappings['item'], $processor, $strict ); |
|
342 | - $chunkcnt = count( $data ); |
|
339 | + $data = $this->convertData($convlist, $data); |
|
340 | + $products = $this->getProducts(array_keys($data), $domains); |
|
341 | + $errcnt = $this->import($products, $data, $mappings['item'], $processor, $strict); |
|
342 | + $chunkcnt = count($data); |
|
343 | 343 | |
344 | 344 | $msg = 'Imported product lines from "%1$s": %2$d/%3$d (%4$s)'; |
345 | - $logger->log( sprintf( $msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
345 | + $logger->log(sprintf($msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
346 | 346 | |
347 | 347 | $errors += $errcnt; |
348 | 348 | $total += $chunkcnt; |
349 | - unset( $products, $data ); |
|
349 | + unset($products, $data); |
|
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
353 | 353 | $container->close(); |
354 | 354 | } |
355 | - catch( \Exception $e ) |
|
355 | + catch (\Exception $e) |
|
356 | 356 | { |
357 | - $logger->log( 'Product import error: ' . $e->getMessage() ); |
|
358 | - $logger->log( $e->getTraceAsString() ); |
|
357 | + $logger->log('Product import error: ' . $e->getMessage()); |
|
358 | + $logger->log($e->getTraceAsString()); |
|
359 | 359 | |
360 | - throw new \Aimeos\Controller\Jobs\Exception( $e->getMessage() ); |
|
360 | + throw new \Aimeos\Controller\Jobs\Exception($e->getMessage()); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | $msg = 'Finished product import from "%1$s": %2$d successful, %3$s errors, %4$s total (%5$s)'; |
364 | - $logger->log( sprintf( $msg, $path, $total - $errors, $errors, $total, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
364 | + $logger->log(sprintf($msg, $path, $total - $errors, $errors, $total, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
365 | 365 | |
366 | - if( $errors > 0 ) |
|
366 | + if ($errors > 0) |
|
367 | 367 | { |
368 | - $msg = sprintf( 'Invalid product lines in "%1$s": %2$d/%3$d', $path, $errors, $total ); |
|
369 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
368 | + $msg = sprintf('Invalid product lines in "%1$s": %2$d/%3$d', $path, $errors, $total); |
|
369 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
370 | 370 | } |
371 | 371 | |
372 | - if( !empty( $backup ) && @rename( $path, strftime( $backup ) ) === false ) { |
|
373 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Unable to move imported file' ) ); |
|
372 | + if (!empty($backup) && @rename($path, strftime($backup)) === false) { |
|
373 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Unable to move imported file')); |
|
374 | 374 | } |
375 | 375 | } |
376 | 376 | |
@@ -382,16 +382,16 @@ discard block |
||
382 | 382 | * @return integer Position of the "product.code" column |
383 | 383 | * @throws \Aimeos\Controller\Jobs\Exception If no mapping for "product.code" is found |
384 | 384 | */ |
385 | - protected function getCodePosition( array $mapping ) |
|
385 | + protected function getCodePosition(array $mapping) |
|
386 | 386 | { |
387 | - foreach( $mapping as $pos => $key ) |
|
387 | + foreach ($mapping as $pos => $key) |
|
388 | 388 | { |
389 | - if( $key === 'product.code' ) { |
|
389 | + if ($key === 'product.code') { |
|
390 | 390 | return $pos; |
391 | 391 | } |
392 | 392 | } |
393 | 393 | |
394 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "product.code" column in CSV mapping found' ) ); |
|
394 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('No "product.code" column in CSV mapping found')); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @see controller/jobs/product/import/csv/container/content |
427 | 427 | * @see controller/jobs/product/import/csv/container/options |
428 | 428 | */ |
429 | - $location = $config->get( 'controller/jobs/product/import/csv/location', '.' ); |
|
429 | + $location = $config->get('controller/jobs/product/import/csv/location', '.'); |
|
430 | 430 | |
431 | 431 | /** controller/jobs/product/import/csv/container/type |
432 | 432 | * Nave of the container type to read the data from |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | * @see controller/jobs/product/import/csv/container/content |
450 | 450 | * @see controller/jobs/product/import/csv/container/options |
451 | 451 | */ |
452 | - $container = $config->get( 'controller/jobs/product/import/csv/container/type', 'Directory' ); |
|
452 | + $container = $config->get('controller/jobs/product/import/csv/container/type', 'Directory'); |
|
453 | 453 | |
454 | 454 | /** controller/jobs/product/import/csv/container/content |
455 | 455 | * Name of the content type inside the container to read the data from |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | * @see controller/jobs/product/import/csv/container/type |
471 | 471 | * @see controller/jobs/product/import/csv/container/options |
472 | 472 | */ |
473 | - $content = $config->get( 'controller/jobs/product/import/csv/container/content', 'CSV' ); |
|
473 | + $content = $config->get('controller/jobs/product/import/csv/container/content', 'CSV'); |
|
474 | 474 | |
475 | 475 | /** controller/jobs/product/import/csv/container/options |
476 | 476 | * List of file container options for the product import files |
@@ -488,9 +488,9 @@ discard block |
||
488 | 488 | * @see controller/jobs/product/import/csv/container/content |
489 | 489 | * @see controller/jobs/product/import/csv/container/type |
490 | 490 | */ |
491 | - $options = $config->get( 'controller/jobs/product/import/csv/container/options', [] ); |
|
491 | + $options = $config->get('controller/jobs/product/import/csv/container/options', []); |
|
492 | 492 | |
493 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
493 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | |
@@ -505,54 +505,54 @@ discard block |
||
505 | 505 | * @return integer Number of products that couldn't be imported |
506 | 506 | * @throws \Aimeos\Controller\Jobs\Exception |
507 | 507 | */ |
508 | - protected function import( array $products, array $data, array $mapping, |
|
509 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict ) |
|
508 | + protected function import(array $products, array $data, array $mapping, |
|
509 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict) |
|
510 | 510 | { |
511 | 511 | $errors = 0; |
512 | 512 | $context = $this->getContext(); |
513 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
513 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
514 | 514 | |
515 | - foreach( $data as $code => $list ) |
|
515 | + foreach ($data as $code => $list) |
|
516 | 516 | { |
517 | 517 | $manager->begin(); |
518 | 518 | |
519 | 519 | try |
520 | 520 | { |
521 | - if( isset( $products[$code] ) ) { |
|
521 | + if (isset($products[$code])) { |
|
522 | 522 | $product = $products[$code]; |
523 | 523 | } else { |
524 | 524 | $product = $manager->createItem(); |
525 | 525 | } |
526 | 526 | |
527 | - $map = $this->getMappedChunk( $list, $mapping ); |
|
527 | + $map = $this->getMappedChunk($list, $mapping); |
|
528 | 528 | |
529 | - if( isset( $map[0] ) ) |
|
529 | + if (isset($map[0])) |
|
530 | 530 | { |
531 | 531 | $map = $map[0]; // there can only be one chunk for the base product data |
532 | 532 | |
533 | - $typecode = ( isset( $map['product.type'] ) ? $map['product.type'] : 'default' ); |
|
534 | - $map['product.typeid'] = $this->getTypeId( 'product/type', 'product', $typecode ); |
|
533 | + $typecode = (isset($map['product.type']) ? $map['product.type'] : 'default'); |
|
534 | + $map['product.typeid'] = $this->getTypeId('product/type', 'product', $typecode); |
|
535 | 535 | |
536 | - $product->fromArray( $this->addItemDefaults( $map ) ); |
|
537 | - $product = $manager->saveItem( $product ); |
|
536 | + $product->fromArray($this->addItemDefaults($map)); |
|
537 | + $product = $manager->saveItem($product); |
|
538 | 538 | |
539 | - $list = $processor->process( $product, $list ); |
|
539 | + $list = $processor->process($product, $list); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | $manager->commit(); |
543 | 543 | } |
544 | - catch( \Exception $e ) |
|
544 | + catch (\Exception $e) |
|
545 | 545 | { |
546 | 546 | $manager->rollback(); |
547 | 547 | |
548 | - $msg = sprintf( 'Unable to import product with code "%1$s": %2$s', $code, $e->getMessage() ); |
|
549 | - $context->getLogger()->log( $msg ); |
|
548 | + $msg = sprintf('Unable to import product with code "%1$s": %2$s', $code, $e->getMessage()); |
|
549 | + $context->getLogger()->log($msg); |
|
550 | 550 | |
551 | 551 | $errors++; |
552 | 552 | } |
553 | 553 | |
554 | - if( $strict && !empty( $list ) ) { |
|
555 | - $context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) ); |
|
554 | + if ($strict && !empty($list)) { |
|
555 | + $context->getLogger()->log('Not imported: ' . print_r($list, true)); |
|
556 | 556 | } |
557 | 557 | } |
558 | 558 | |
@@ -566,9 +566,9 @@ discard block |
||
566 | 566 | * @param array $list Associative list of domain item keys and their values, e.g. "product.status" => 1 |
567 | 567 | * @return array Given associative list enriched by default values if they were not already set |
568 | 568 | */ |
569 | - protected function addItemDefaults( array $list ) |
|
569 | + protected function addItemDefaults(array $list) |
|
570 | 570 | { |
571 | - if( !isset( $list['product.status'] ) ) { |
|
571 | + if (!isset($list['product.status'])) { |
|
572 | 572 | $list['product.status'] = 1; |
573 | 573 | } |
574 | 574 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function getName() |
31 | 31 | { |
32 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Products bought together' ); |
|
32 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Products bought together'); |
|
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', 'Creates bought together product suggestions' ); |
|
43 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Creates bought together product suggestions'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @see controller/jobs/product/bought/min-confidence |
73 | 73 | * @see controller/jobs/product/bought/limit-days |
74 | 74 | */ |
75 | - $maxItems = $config->get( 'controller/jobs/product/bought/max-items', 5 ); |
|
75 | + $maxItems = $config->get('controller/jobs/product/bought/max-items', 5); |
|
76 | 76 | |
77 | 77 | /** controller/jobs/product/bought/min-support |
78 | 78 | * Minimum support value to sort out all irrelevant combinations |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @see controller/jobs/product/bought/min-confidence |
102 | 102 | * @see controller/jobs/product/bought/limit-days |
103 | 103 | */ |
104 | - $minSupport = $config->get( 'controller/jobs/product/bought/min-support', 0.02 ); |
|
104 | + $minSupport = $config->get('controller/jobs/product/bought/min-support', 0.02); |
|
105 | 105 | |
106 | 106 | /** controller/jobs/product/bought/min-confidence |
107 | 107 | * Minimum confidence value for high quality suggestions |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @see controller/jobs/product/bought/min-support |
127 | 127 | * @see controller/jobs/product/bought/limit-days |
128 | 128 | */ |
129 | - $minConfidence = $config->get( 'controller/jobs/product/bought/min-confidence', 0.66 ); |
|
129 | + $minConfidence = $config->get('controller/jobs/product/bought/min-confidence', 0.66); |
|
130 | 130 | |
131 | 131 | /** controller/jobs/product/bought/limit-days |
132 | 132 | * Only use orders placed in the past within the configured number of days for calculating bought together products |
@@ -150,45 +150,45 @@ discard block |
||
150 | 150 | * @see controller/jobs/product/bought/min-support |
151 | 151 | * @see controller/jobs/product/bought/min-confidence |
152 | 152 | */ |
153 | - $days = $config->get( 'controller/jobs/product/bought/limit-days', 180 ); |
|
154 | - $date = date( 'Y-m-d H:i:s', time() - $days * 86400 ); |
|
153 | + $days = $config->get('controller/jobs/product/bought/limit-days', 180); |
|
154 | + $date = date('Y-m-d H:i:s', time() - $days * 86400); |
|
155 | 155 | |
156 | 156 | |
157 | - $typeItem = $this->getTypeItem( 'product/lists/type', 'product', 'bought-together' ); |
|
157 | + $typeItem = $this->getTypeItem('product/lists/type', 'product', 'bought-together'); |
|
158 | 158 | |
159 | - $baseManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
|
159 | + $baseManager = \Aimeos\MShop\Factory::createManager($context, 'order/base'); |
|
160 | 160 | $search = $baseManager->createSearch(); |
161 | - $search->setConditions( $search->compare( '>', 'order.base.ctime', $date ) ); |
|
162 | - $search->setSlice( 0, 0 ); |
|
161 | + $search->setConditions($search->compare('>', 'order.base.ctime', $date)); |
|
162 | + $search->setSlice(0, 0); |
|
163 | 163 | $totalOrders = 0; |
164 | - $baseManager->searchItems( $search, [], $totalOrders ); |
|
164 | + $baseManager->searchItems($search, [], $totalOrders); |
|
165 | 165 | |
166 | - $baseProductManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' ); |
|
166 | + $baseProductManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/product'); |
|
167 | 167 | $search = $baseProductManager->createSearch(); |
168 | - $search->setConditions( $search->compare( '>', 'order.base.product.ctime', $date ) ); |
|
168 | + $search->setConditions($search->compare('>', 'order.base.product.ctime', $date)); |
|
169 | 169 | $start = 0; |
170 | 170 | |
171 | 171 | do |
172 | 172 | { |
173 | - $totalCounts = $baseProductManager->aggregate( $search, 'order.base.product.productid' ); |
|
174 | - $prodIds = array_keys( $totalCounts ); |
|
173 | + $totalCounts = $baseProductManager->aggregate($search, 'order.base.product.productid'); |
|
174 | + $prodIds = array_keys($totalCounts); |
|
175 | 175 | |
176 | - foreach( $totalCounts as $id => $count ) |
|
176 | + foreach ($totalCounts as $id => $count) |
|
177 | 177 | { |
178 | - $this->removeListItems( $id, $typeItem->getId() ); |
|
178 | + $this->removeListItems($id, $typeItem->getId()); |
|
179 | 179 | |
180 | - if( $count / $totalOrders > $minSupport ) |
|
180 | + if ($count / $totalOrders > $minSupport) |
|
181 | 181 | { |
182 | - $productIds = $this->getSuggestions( $id, $prodIds, $count, $totalOrders, $maxItems, $minSupport, $minConfidence, $date ); |
|
183 | - $this->addListItems( $id, $typeItem->getId(), $productIds ); |
|
182 | + $productIds = $this->getSuggestions($id, $prodIds, $count, $totalOrders, $maxItems, $minSupport, $minConfidence, $date); |
|
183 | + $this->addListItems($id, $typeItem->getId(), $productIds); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
187 | - $count = count( $totalCounts ); |
|
187 | + $count = count($totalCounts); |
|
188 | 188 | $start += $count; |
189 | - $search->setSlice( $start ); |
|
189 | + $search->setSlice($start); |
|
190 | 190 | } |
191 | - while( $count >= $search->getSliceSize() ); |
|
191 | + while ($count >= $search->getSliceSize()); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | |
@@ -205,59 +205,59 @@ discard block |
||
205 | 205 | * @param string $date Date in YYYY-MM-DD HH:mm:ss format after which orders should be used for calculations |
206 | 206 | * @return array List of suggested product IDs as key and their confidence as value |
207 | 207 | */ |
208 | - protected function getSuggestions( $id, $prodIds, $count, $total, $maxItems, $minSupport, $minConfidence, $date ) |
|
208 | + protected function getSuggestions($id, $prodIds, $count, $total, $maxItems, $minSupport, $minConfidence, $date) |
|
209 | 209 | { |
210 | 210 | $refIds = []; |
211 | 211 | $context = $this->getContext(); |
212 | 212 | |
213 | - $catalogListManager = \Aimeos\MShop\Factory::createManager( $context, 'catalog/lists' ); |
|
214 | - $baseProductManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' ); |
|
213 | + $catalogListManager = \Aimeos\MShop\Factory::createManager($context, 'catalog/lists'); |
|
214 | + $baseProductManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/product'); |
|
215 | 215 | |
216 | 216 | |
217 | 217 | $search = $baseProductManager->createSearch(); |
218 | - $func = $search->createFunction( 'order.base.product.count', array( (string) $id ) ); |
|
218 | + $func = $search->createFunction('order.base.product.count', array((string) $id)); |
|
219 | 219 | $expr = array( |
220 | - $search->compare( '==', 'order.base.product.productid', $prodIds ), |
|
221 | - $search->compare( '>', 'order.base.product.ctime', $date ), |
|
222 | - $search->compare( '==', $func, 1 ), |
|
220 | + $search->compare('==', 'order.base.product.productid', $prodIds), |
|
221 | + $search->compare('>', 'order.base.product.ctime', $date), |
|
222 | + $search->compare('==', $func, 1), |
|
223 | 223 | ); |
224 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
224 | + $search->setConditions($search->combine('&&', $expr)); |
|
225 | 225 | |
226 | - $relativeCounts = $baseProductManager->aggregate( $search, 'order.base.product.productid' ); |
|
226 | + $relativeCounts = $baseProductManager->aggregate($search, 'order.base.product.productid'); |
|
227 | 227 | |
228 | 228 | |
229 | 229 | $search = $catalogListManager->createSearch(); |
230 | 230 | $expr = array( |
231 | - $search->compare( '==', 'catalog.lists.refid', array_keys( $relativeCounts ) ), |
|
232 | - $search->compare( '==', 'catalog.lists.domain', 'product' ), |
|
231 | + $search->compare('==', 'catalog.lists.refid', array_keys($relativeCounts)), |
|
232 | + $search->compare('==', 'catalog.lists.domain', 'product'), |
|
233 | 233 | ); |
234 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
234 | + $search->setConditions($search->combine('&&', $expr)); |
|
235 | 235 | |
236 | - foreach( $catalogListManager->searchItems( $search ) as $listItem ) { |
|
236 | + foreach ($catalogListManager->searchItems($search) as $listItem) { |
|
237 | 237 | $refIds[$listItem->getRefId()] = true; |
238 | 238 | } |
239 | 239 | |
240 | 240 | |
241 | - unset( $relativeCounts[$id] ); |
|
241 | + unset($relativeCounts[$id]); |
|
242 | 242 | $supportA = $count / $total; |
243 | 243 | $products = []; |
244 | 244 | |
245 | - foreach( $relativeCounts as $prodId => $relCnt ) |
|
245 | + foreach ($relativeCounts as $prodId => $relCnt) |
|
246 | 246 | { |
247 | - if( !isset( $refIds[$prodId] ) ) { |
|
247 | + if (!isset($refIds[$prodId])) { |
|
248 | 248 | continue; |
249 | 249 | } |
250 | 250 | |
251 | 251 | $supportAB = $relCnt / $total; |
252 | 252 | |
253 | - if( $supportAB > $minSupport && ( $conf = ( $supportAB / $supportA ) ) > $minConfidence ) { |
|
253 | + if ($supportAB > $minSupport && ($conf = ($supportAB / $supportA)) > $minConfidence) { |
|
254 | 254 | $products[$prodId] = $conf; |
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | - arsort( $products ); |
|
258 | + arsort($products); |
|
259 | 259 | |
260 | - return array_keys( array_slice( $products, 0, $maxItems, true ) ); |
|
260 | + return array_keys(array_slice($products, 0, $maxItems, true)); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | |
@@ -268,26 +268,26 @@ discard block |
||
268 | 268 | * @param integer $typeId Unique ID of the list type used for the referenced products |
269 | 269 | * @param array $productIds List of position as key and product ID as value |
270 | 270 | */ |
271 | - protected function addListItems( $productId, $typeId, array $productIds ) |
|
271 | + protected function addListItems($productId, $typeId, array $productIds) |
|
272 | 272 | { |
273 | - if( empty( $productIds ) ) { |
|
273 | + if (empty($productIds)) { |
|
274 | 274 | return; |
275 | 275 | } |
276 | 276 | |
277 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
277 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
278 | 278 | $item = $manager->createItem(); |
279 | 279 | |
280 | - foreach( $productIds as $pos => $refid ) |
|
280 | + foreach ($productIds as $pos => $refid) |
|
281 | 281 | { |
282 | - $item->setId( null ); |
|
283 | - $item->setParentId( $productId ); |
|
284 | - $item->setDomain( 'product' ); |
|
285 | - $item->setTypeId( $typeId ); |
|
286 | - $item->setPosition( $pos ); |
|
287 | - $item->setRefId( $refid ); |
|
288 | - $item->setStatus( 1 ); |
|
289 | - |
|
290 | - $manager->saveItem( $item, false ); |
|
282 | + $item->setId(null); |
|
283 | + $item->setParentId($productId); |
|
284 | + $item->setDomain('product'); |
|
285 | + $item->setTypeId($typeId); |
|
286 | + $item->setPosition($pos); |
|
287 | + $item->setRefId($refid); |
|
288 | + $item->setStatus(1); |
|
289 | + |
|
290 | + $manager->saveItem($item, false); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | |
@@ -298,20 +298,20 @@ discard block |
||
298 | 298 | * @param string $productId Unique ID of the product the references should be removed from |
299 | 299 | * @param integer $typeId Unique ID of the list type the referenced products should be removed from |
300 | 300 | */ |
301 | - protected function removeListItems( $productId, $typeId ) |
|
301 | + protected function removeListItems($productId, $typeId) |
|
302 | 302 | { |
303 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
303 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
304 | 304 | |
305 | 305 | $search = $manager->createSearch(); |
306 | 306 | $expr = array( |
307 | - $search->compare( '==', 'product.lists.parentid', $productId ), |
|
308 | - $search->compare( '==', 'product.lists.domain', 'product' ), |
|
309 | - $search->compare( '==', 'product.lists.typeid', $typeId ), |
|
307 | + $search->compare('==', 'product.lists.parentid', $productId), |
|
308 | + $search->compare('==', 'product.lists.domain', 'product'), |
|
309 | + $search->compare('==', 'product.lists.typeid', $typeId), |
|
310 | 310 | ); |
311 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
311 | + $search->setConditions($search->combine('&&', $expr)); |
|
312 | 312 | |
313 | - $listItems = $manager->searchItems( $search ); |
|
313 | + $listItems = $manager->searchItems($search); |
|
314 | 314 | |
315 | - $manager->deleteItems( array_keys( $listItems ) ); |
|
315 | + $manager->deleteItems(array_keys($listItems)); |
|
316 | 316 | } |
317 | 317 | } |