Skip to content

Commit 548487f

Browse files
committed
MAGETWO-38844: Contribution of Ogres Sprint 31
Merge remote-tracking branch 'ogresCE/MAGETWO-30245-uninstall-modules-via-cli-PR' into PR_Branch
2 parents a0a9459 + 11876cf commit 548487f

File tree

58 files changed

+4758
-470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4758
-470
lines changed

app/code/Magento/Theme/Console/Command/ThemeUninstallCommand.php

Lines changed: 407 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Theme\Model;
7+
8+
use Magento\Store\Model\StoreManagerInterface;
9+
use Magento\Framework\View\DesignInterface;
10+
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
11+
use Magento\Framework\App\Config\ValueInterface;
12+
use Magento\Store\Model\ScopeInterface;
13+
14+
/**
15+
* Class ThemeValidator
16+
*/
17+
class ThemeValidator
18+
{
19+
20+
/**
21+
* Store Manager
22+
*
23+
* @var StoreManagerInterface $storeManager
24+
*/
25+
private $storeManager;
26+
27+
/**
28+
* Provider for themes registered in db
29+
*
30+
* @var ThemeProviderInterface $themeProvider
31+
*/
32+
private $themeProvider;
33+
34+
/**
35+
* Configuration Data
36+
*
37+
* @var ValueInterface $configData
38+
*/
39+
private $configData;
40+
41+
42+
/**
43+
* @param StoreManagerInterface $storeManager
44+
* @param ThemeProviderInterface $themeProvider
45+
* @param ValueInterface $configData
46+
*/
47+
public function __construct(
48+
StoreManagerInterface $storeManager,
49+
ThemeProviderInterface $themeProvider,
50+
ValueInterface $configData
51+
) {
52+
$this->storeManager = $storeManager;
53+
$this->themeProvider = $themeProvider;
54+
$this->configData = $configData;
55+
}
56+
57+
/**
58+
* Validate the theme if being in use in default, website, or store.
59+
*
60+
* @param string[] $themePaths
61+
* @return array
62+
*/
63+
public function validateIsThemeInUse($themePaths)
64+
{
65+
$messages = [];
66+
$themesById = [];
67+
foreach ($themePaths as $themePath) {
68+
$theme = $this->themeProvider->getThemeByFullPath($themePath);
69+
$themesById[$theme->getId()] = $themePath;
70+
}
71+
$configData = $this->configData
72+
->getCollection()
73+
->addFieldToFilter('path', DesignInterface::XML_PATH_THEME_ID)
74+
->addFieldToFilter('value', ['in' => array_keys($themesById)]);
75+
foreach ($configData as $row) {
76+
switch($row['scope']) {
77+
case 'default':
78+
$messages[] = $themesById[$row['value']] . ' is in use in default config';
79+
break;
80+
case ScopeInterface::SCOPE_WEBSITES:
81+
$messages[] = $themesById[$row['value']] . ' is in use in website '
82+
. $this->storeManager->getWebsite($row['scope_id'])->getName();
83+
break;
84+
case ScopeInterface::SCOPE_STORES:
85+
$messages[] = $themesById[$row['value']] . ' is in use in store '
86+
. $this->storeManager->getStore($row['scope_id'])->getName();
87+
break;
88+
}
89+
}
90+
return $messages;
91+
}
92+
}

0 commit comments

Comments
 (0)