protected function removeComponent($name, array $directoriesToRemove) { $pagesOutComponents = $this->config->getParsed('pages_out_components'); $pagesToUpdate = array(); foreach ($pagesOutComponents as $pageName => $outComponents) { if (in_array($name, $outComponents)) { $pagesToUpdate[] = $pageName; } } $question = "Are you sure that you want to delete {$this->componentType} component {$name}? "; $questionAppendix = ""; $commonComponents = $this->config->get('common_output_components'); if (isset($commonComponents[$name])) { $questionAppendix .= "\nComponent is enlisted as common component.\n"; } if (!empty($pagesToUpdate)) { $questionAppendix .= "\nIt is a dependency for next pages (pages will be updated, also): " . $this->arrToStr($pagesToUpdate) . "\n"; } if (!empty($questionAppendix)) { $question .= "\n{$questionAppendix}\nAnswer? (yes|no): "; } else { $question .= "(yes|no)"; } $answer = $this->scriptParams->askYesNo($question); if ($answer == 'no') { return "Giving up on removing output component."; } $pagesDependencies = $this->config->get('pages_out_components'); foreach ($pagesToUpdate as $pageName) { if (!in_array($name, $pagesDependencies[$pageName])) { throw new \Exception("Page \"{$pageName}\" does not have output component \"{$name}\" as its dependency."); } if (($key = array_search($name, $pagesDependencies[$pageName])) !== false) { unset($pagesDependencies[$pageName][$key]); } } $this->config->set('pages_out_components', $pagesDependencies); if (isset($commonComponents[$name])) { unset($commonComponents[$name]); } $this->config->set('common_output_components', $commonComponents); $statusText = parent::removeComponent($name, $directoriesToRemove, false); $ocOptions = $this->outputComponentsOptions; if (isset($ocOptions[$name])) { unset($ocOptions[$name]); } $this->config->set($this->outputComponentOptionsConfigIndex, $ocOptions); return $statusText; }
protected function removeComponent($name, array $directoriesToRemove, $askSecQuestion = true) { $question = "Are you sure that you want to delete logic component \"{$name}\" "; $outputComponents = $this->config->get('output_components'); $outputComponentsToUpdate = array(); foreach ($outputComponents as $ocName => $logicDependencies) { if (in_array($name, $logicDependencies)) { $outputComponentsToUpdate[] = $ocName; } } $logicComponents = $this->config->get('logic_components'); $logicComponentsToUpdate = array(); foreach ($logicComponents as $lcName => $logicDependencies) { if (in_array($name, $logicDependencies)) { $logicComponentsToUpdate[] = $lcName; } } $questionAppendix = ""; if (!empty($outputComponentsToUpdate)) { $outputComponentsToUpdateStr = $this->arrToStr($outputComponentsToUpdate); $questionAppendix .= "\nListed as dependency on next output components: {$outputComponentsToUpdateStr}\n"; } if (!empty($logicComponentsToUpdate)) { $logicComponentsToUpdateStr = $this->arrToStr($logicComponentsToUpdate); $questionAppendix .= "\nListed as dependency on next logic components: {$logicComponentsToUpdateStr}\n"; } if (!empty($questionAppendix)) { $question .= "\n{$questionAppendix}\nAnswer? (yes|no): "; } else { $question .= "(yes|no)"; } $answer = $this->scriptParams->askYesNo($question); if ($answer == 'no') { return "Giving up on deleting component."; } foreach ($outputComponentsToUpdate as $ocName) { if (!in_array($name, $outputComponents[$ocName])) { throw new \Exception("Component \"{$ocName}\" does not have logic component \"{$name}\" as its dependency."); } if (($key = array_search($name, $outputComponents[$ocName])) !== false) { unset($outputComponents[$ocName][$key]); } } $this->config->set('output_components', $outputComponents); foreach ($logicComponentsToUpdate as $lcName) { if (!in_array($name, $logicComponents[$lcName])) { throw new \Exception("Logic component \"{$lcName}\" does not have logic component \"{$name}\" as its dependency."); } if (($key = array_search($name, $logicComponents[$lcName])) !== false) { unset($logicComponents[$lcName][$key]); } } $this->config->set('logic_components', $logicComponents); return parent::removeComponent($name, $directoriesToRemove, false); }