Skip to content

Commit 7156d96

Browse files
Merge pull request #18 from magento/develop
Merge develop into 1.0
2 parents 19b447b + d8c2cf8 commit 7156d96

22 files changed

+1138
-60
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
.idea
2-
composer.lock
1+
/.idea
2+
/composer.lock
3+
/vendor
4+
/auth.json

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
dist: trusty
2+
3+
git:
4+
depth: false
5+
6+
language: php
7+
php:
8+
- '7.1'
9+
- '7.2'
10+
- '7.3'
11+
12+
env:
13+
- TEST_SUITE=static-unit XDEBUG=true
14+
15+
install:
16+
- composer config http-basic.repo.magento.com ${REPO_USERNAME} ${REPO_PASSWORD};
17+
- composer config repositories.magento composer https://repo.magento.com/
18+
- composer require "magento/framework:*" --no-update
19+
- composer require "magento/module-store:*" --no-update
20+
- composer require "magento/module-url-rewrite:*" --no-update
21+
- composer update -n --no-suggest
22+
23+
script:
24+
- if [ "$TEST_SUITE" == "static-unit" ]; then ./Test/static/static-travis.sh; fi
25+

Console/Command/ConfigShowDefaultUrlCommand.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\CloudComponents\Console\Command;
79

10+
use Magento\CloudComponents\Model\UrlFixer;
811
use Magento\Framework\Console\Cli;
912
use Magento\Framework\UrlInterface;
1013
use Magento\Store\Model\Store;
@@ -23,13 +26,20 @@ class ConfigShowDefaultUrlCommand extends Command
2326
*/
2427
private $storeManager;
2528

29+
/**
30+
* @var UrlFixer
31+
*/
32+
private $urlFixer;
33+
2634
/**
2735
* @param StoreManagerInterface $storeManager
36+
* @param UrlFixer $urlFixer
2837
*/
29-
public function __construct(StoreManagerInterface $storeManager)
38+
public function __construct(StoreManagerInterface $storeManager, UrlFixer $urlFixer)
3039
{
3140
parent::__construct();
3241
$this->storeManager = $storeManager;
42+
$this->urlFixer = $urlFixer;
3343
}
3444

3545
/**
@@ -52,7 +62,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
5262
{
5363
/** @var Store $store */
5464
$store = $this->storeManager->getDefaultStoreView();
55-
$output->write($store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure()));
65+
$baseUrl = $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure());
66+
$output->writeln($this->urlFixer->run($store, $baseUrl));
5667

5768
return Cli::RETURN_SUCCESS;
5869
}

Console/Command/ConfigShowEntityUrlsCommand.php

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\CloudComponents\Console\Command;
79

10+
use Magento\CloudComponents\Model\UrlFinder\Product;
11+
use Magento\CloudComponents\Model\UrlFinderFactory;
812
use Magento\Framework\App\Area;
913
use Magento\Framework\App\State;
1014
use Magento\Framework\Console\Cli;
1115
use Magento\Framework\Exception\LocalizedException;
12-
use Magento\Framework\UrlFactory;
16+
use Magento\Framework\Exception\NoSuchEntityException;
1317
use Magento\Store\Api\Data\StoreInterface;
1418
use Magento\Store\Model\StoreManagerInterface;
1519
use Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite;
16-
use Magento\UrlRewrite\Model\UrlFinderInterface;
1720
use Symfony\Component\Console\Command\Command;
1821
use Symfony\Component\Console\Input\InputInterface;
1922
use Symfony\Component\Console\Input\InputOption;
2023
use Symfony\Component\Console\Output\OutputInterface;
21-
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
2224

2325
/**
2426
* Returns list of category or cms-page urls for given stores
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2528
*/
2629
class ConfigShowEntityUrlsCommand extends Command
2730
{
@@ -30,47 +33,45 @@ class ConfigShowEntityUrlsCommand extends Command
3033
*/
3134
const INPUT_OPTION_STORE_ID = 'store-id';
3235
const INPUT_OPTION_ENTITY_TYPE = 'entity-type';
36+
const INPUT_OPTION_PRODUCT_SKU = 'product-sku';
37+
const INPUT_OPTION_PRODUCT_LIMIT = 'product-limit';
3338

3439
/**
3540
* @var StoreManagerInterface
3641
*/
3742
private $storeManager;
3843

3944
/**
40-
* @var UrlFinderInterface
41-
*/
42-
private $urlFinder;
43-
44-
/**
45-
* @var UrlFactory
45+
* @var State
4646
*/
47-
private $urlFactory;
47+
private $state;
4848

4949
/**
50-
* @var State
50+
* @var UrlFinderFactory
5151
*/
52-
private $state;
52+
private $urlFinderFactory;
5353

5454
/**
5555
* @var array
5656
*/
57-
private $possibleEntities = [Rewrite::ENTITY_TYPE_CMS_PAGE, Rewrite::ENTITY_TYPE_CATEGORY];
57+
private $possibleEntities = [
58+
Rewrite::ENTITY_TYPE_CMS_PAGE,
59+
Rewrite::ENTITY_TYPE_CATEGORY,
60+
Rewrite::ENTITY_TYPE_PRODUCT
61+
];
5862

5963
/**
6064
* @param StoreManagerInterface $storeManager
61-
* @param UrlFinderInterface $urlFinder
62-
* @param UrlFactory $urlFactory
65+
* @param UrlFinderFactory $urlFinderFactory
6366
* @param State $state
6467
*/
6568
public function __construct(
6669
StoreManagerInterface $storeManager,
67-
UrlFinderInterface $urlFinder,
68-
UrlFactory $urlFactory,
70+
UrlFinderFactory $urlFinderFactory,
6971
State $state
7072
) {
7173
$this->storeManager = $storeManager;
72-
$this->urlFinder = $urlFinder;
73-
$this->urlFactory = $urlFactory;
74+
$this->urlFinderFactory = $urlFinderFactory;
7475
$this->state = $state;
7576

7677
parent::__construct();
@@ -89,7 +90,7 @@ protected function configure()
8990
$this->addOption(
9091
self::INPUT_OPTION_STORE_ID,
9192
null,
92-
InputOption::VALUE_OPTIONAL,
93+
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
9394
'Store ID'
9495
);
9596
$this->addOption(
@@ -98,6 +99,19 @@ protected function configure()
9899
InputOption::VALUE_REQUIRED,
99100
'Entity type: ' . implode(',', $this->possibleEntities)
100101
);
102+
$this->addOption(
103+
self::INPUT_OPTION_PRODUCT_SKU,
104+
null,
105+
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
106+
'Product SKUs'
107+
);
108+
$this->addOption(
109+
self::INPUT_OPTION_PRODUCT_LIMIT,
110+
null,
111+
InputOption::VALUE_OPTIONAL,
112+
'Product limit per store uses in case when product SKUs isn\'t provided',
113+
Product::PRODUCT_LIMIT
114+
);
101115

102116
parent::configure();
103117
}
@@ -121,17 +135,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
121135
return Cli::RETURN_FAILURE;
122136
}
123137

124-
$storeId = $input->getOption(self::INPUT_OPTION_STORE_ID);
125-
126-
if ($storeId === null) {
127-
$stores = $this->storeManager->getStores();
128-
} else {
129-
$stores = [$this->storeManager->getStore($storeId)];
130-
}
131-
132-
$urls = $this->getPageUrls($stores, $entityType);
138+
$urlFinder = $this->urlFinderFactory->create($entityType, [
139+
'stores' => $this->getStores($input),
140+
'productSku' => $input->getOption(self::INPUT_OPTION_PRODUCT_SKU),
141+
'productLimit' => $input->getOption(self::INPUT_OPTION_PRODUCT_LIMIT),
142+
]);
133143

134-
$output->write(json_encode(array_unique($urls)));
144+
$output->writeln(json_encode(array_unique($urlFinder->get())));
135145
return Cli::RETURN_SUCCESS;
136146
} catch (\Exception $e) {
137147
$output->writeln($e->getMessage());
@@ -140,28 +150,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
140150
}
141151

142152
/**
143-
* @param StoreInterface[] $stores
144-
* @param string $entityType
145-
* @return array
153+
* @param InputInterface $input
154+
* @return StoreInterface[]
155+
* @throws NoSuchEntityException
146156
*/
147-
private function getPageUrls(array $stores, string $entityType): array
157+
private function getStores(InputInterface $input): array
148158
{
149-
$urls = [];
150-
151-
foreach ($stores as $store) {
152-
$url = $this->urlFactory->create()->setScope($store->getId());
153-
154-
$entities = $this->urlFinder->findAllByData([
155-
UrlRewrite::STORE_ID => $store->getId(),
156-
UrlRewrite::ENTITY_TYPE => $entityType
157-
]);
159+
$storeIds = $input->getOption(self::INPUT_OPTION_STORE_ID);
158160

159-
foreach ($entities as $urlRewrite) {
160-
$urls[] = $url->getUrl($urlRewrite->getRequestPath());
161+
if (!empty($storeIds)) {
162+
$stores = [];
163+
foreach ($storeIds as $storeId) {
164+
$stores[] = $this->storeManager->getStore($storeId);
161165
}
166+
} else {
167+
$stores = $this->storeManager->getStores();
162168
}
163169

164-
return $urls;
170+
return $stores;
165171
}
166172

167173
/**

Console/Command/ConfigShowStoreUrlCommand.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\CloudComponents\Console\Command;
79

10+
use Magento\CloudComponents\Model\UrlFixer;
811
use Magento\Framework\Console\Cli;
912
use Magento\Framework\UrlInterface;
1013
use Magento\Store\Model\Store;
@@ -29,14 +32,22 @@ class ConfigShowStoreUrlCommand extends Command
2932
*/
3033
private $storeManager;
3134

35+
/**
36+
* @var UrlFixer
37+
*/
38+
private $urlFixer;
39+
3240
/**
3341
* @param StoreManagerInterface $storeManager
42+
* @param UrlFixer $urlFixer
3443
*/
3544
public function __construct(
36-
StoreManagerInterface $storeManager
45+
StoreManagerInterface $storeManager,
46+
UrlFixer $urlFixer
3747
) {
3848
parent::__construct();
3949
$this->storeManager = $storeManager;
50+
$this->urlFixer = $urlFixer;
4051
}
4152

4253
/**
@@ -70,15 +81,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
7081
$storeId = $input->getArgument(self::INPUT_ARGUMENT_STORE_ID);
7182
if ($storeId !== null) {
7283
$store = $this->storeManager->getStore($storeId);
84+
$baseUrl = $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure());
7385

74-
$output->writeln($store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure()));
86+
$output->writeln($this->urlFixer->run($store, $baseUrl));
7587
} else {
7688
$urls = [];
7789
foreach ($this->storeManager->getStores(true) as $store) {
78-
$urls[$store->getId()] = $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure());
90+
$urls[$store->getId()] = $this->urlFixer->run(
91+
$store,
92+
$store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure())
93+
);
7994
}
8095

81-
$output->write(json_encode($urls, JSON_FORCE_OBJECT));
96+
$output->writeln(json_encode($urls, JSON_FORCE_OBJECT));
8297
}
8398

8499
return Cli::RETURN_SUCCESS;

0 commit comments

Comments
 (0)