1 | <?php |
||
12 | class DeleteCommand extends AbstractConfigCommand |
||
13 | { |
||
14 | /** |
||
15 | * @var Collection |
||
16 | */ |
||
17 | private $collection; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $_scopes = array( |
||
23 | 'default', |
||
24 | 'websites', |
||
25 | 'stores', |
||
26 | ); |
||
27 | |||
28 | protected function configure() |
||
50 | |||
51 | /** |
||
52 | * @param Collection $collection |
||
53 | */ |
||
54 | public function inject(Collection $collection) |
||
58 | |||
59 | /** |
||
60 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
61 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
62 | * @return int|void |
||
63 | */ |
||
64 | protected function execute(InputInterface $input, OutputInterface $output) |
||
90 | |||
91 | /** |
||
92 | * |
||
93 | */ |
||
94 | private function resolvePaths($path, $scopeId) |
||
121 | |||
122 | /** |
||
123 | * @param InputInterface $input |
||
124 | * @param WriterInterface $configWriter |
||
125 | * @param $path |
||
126 | * @param $scopeId |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | protected function _deletePath( |
||
131 | InputInterface $input, |
||
132 | WriterInterface $configWriter, |
||
133 | $path, |
||
134 | $scopeId |
||
135 | ) { |
||
136 | $deleted = array(); |
||
137 | if ($input->getOption('all')) { |
||
138 | $storeManager = $this->getObjectManager()->get('Magento\Store\Model\StoreManager'); |
||
139 | |||
140 | // Delete default |
||
141 | $this->delete($configWriter, $deleted, $path, 'default', 0); |
||
142 | |||
143 | $deleted[] = array( |
||
144 | 'path' => $path, |
||
145 | 'scope' => 'default', |
||
146 | 'scopeId' => 0, |
||
147 | ); |
||
148 | |||
149 | // Delete websites |
||
150 | foreach ($storeManager->getWebsites() as $website) { |
||
151 | $this->delete($configWriter, $deleted, $path, 'websites', $website->getId()); |
||
152 | } |
||
153 | |||
154 | // Delete stores |
||
155 | foreach ($storeManager->getStores() as $store) { |
||
156 | $this->delete($configWriter, $deleted, $path, 'stores', $store->getId()); |
||
157 | } |
||
158 | } else { |
||
159 | foreach ($this->resolveScopeIds($path, $input->getOption('scope'), $scopeId) as $item) { |
||
160 | $this->delete($configWriter, $deleted, $path, $item[1], $item[2]); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | return $deleted; |
||
165 | } |
||
166 | |||
167 | private function delete(WriterInterface $configWriter, &$deleted, $path, $scope, $scopeId) |
||
177 | |||
178 | /** |
||
179 | * @param string $path |
||
180 | * @param string $scope |
||
181 | * @param int|null $scopeId |
||
182 | * |
||
183 | * @return array |
||
184 | */ |
||
185 | private function resolveScopeIds($path, $scope, $scopeId) |
||
209 | } |
||
210 |