<commit_before><?php
namespace Meanbee\Magerun\Dac\Command;

use N98\Magento\Command\AbstractMagentoCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class CopyCommand extends AbstractMagentoCommand
{

    /**
     * Configure the command parameters.
     */
    protected function configure()
    {
        $this
            ->setName("dev:theme:copy")
            ->setDescription("Copy a file from the \"base/default\" design theme to the specified theme.")
            ->addArgument(
                "filepath",
                InputArgument::REQUIRED,
                "Path to the file to copy, relative to the theme directory in design."
            )
            ->addArgument(
                "destination",
                InputArgument::REQUIRED,
                "Destination theme (specified in <package>[/<theme>] format)."
            )
            ->addOption(
                "force", "f",
                InputOption::VALUE_NONE,
                "Overwrite the destination file if it already exists."
            )
            ->addOption(
                "source", null,
                InputOption::VALUE_REQUIRED,
                "Use an alternate theme to copy the file from (specified in <package>[/<theme>] format)."
            )
            ->addOption(
                "adminhtml", null,
                InputOption::VALUE_NONE,
                "Use adminhtml themes for source and destination."
            );
    }

    /**
     * Execute the command.
     *
     * @param InputInterface  $input
     * @param OutputInterface $output
     *
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->detectMagento($output);

        $source = $this->getDesignPath(
            $input->getOption("source"),
            $input->getArgument("filepath"),
            $input->getOption("adminhtml")
        );
        $destination = $this->getDesignPath(
            $input->getArgument("destination"),
            $input->getArgument("filepath"),
            $input->getOption("adminhtml")
        );
        $destination_dir = dirname($destination);

        $output->writeln(sprintf(
            "<info>Copy file:</info>\n\t<comment>Source: %s</comment>\n\t<comment>Destination: %s</comment>",
            $source,
            $destination
        ));

        if (!file_exists($source)) {
            $output->writeln("<error>Source file does not exist!</error>");
            return 1;
        }

        if (file_exists($destination) && !$input->getOption("force")) {
            $output->writeln("<error>Destination file already exists!</error>");
            return 1;
        }

        if (!file_exists($destination_dir)) {
            if (!mkdir($destination_dir, 0755, true)) {
                $output->writeln("<error>Failed to create the destination directory!</error>");
                return 1;
            }
        } else if (!is_dir($destination_dir)) {
            $output->writeln("<error>Destination is not a directory!</error>");
            return 1;
        }

        if (!copy($source, $destination)) {
            $output->writeln("<error>Failed!</error>");
            return 1;
        }

        $output->writeln("<info>Done</info>");

        return 0;
    }

    /**
     * Get the path to the specified theme's design folder
     * or a specific file inside it.
     *
     * @param string      $theme
     * @param string|null $file
     * @param bool        $is_adminhtml
     *
     * @return string
     */
    protected function getDesignPath($theme, $file = null, $is_adminhtml = false)
    {
        @list($package, $theme) = explode("/", $theme);

        $path = array(
            $this->getApplication()->getMagentoRootFolder(),
            "app",
            "design",
            ($is_adminhtml) ? "adminhtml" : "frontend",
            $package ?: ($is_adminhtml ? "default" : "base"),
            $theme ?: "default"
        );

        if ($file) {
            $path[] = $file;<commit_msg>Add support for copying skin files<commit_after><?php
namespace Meanbee\Magerun\Dac\Command;

use N98\Magento\Command\AbstractMagentoCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class CopyCommand extends AbstractMagentoCommand
{

    /**
     * Configure the command parameters.
     */
    protected function configure()
    {
        $this
            ->setName("dev:theme:copy")
            ->setDescription("Copy a file from the \"base/default\" design theme to the specified theme.")
            ->addArgument(
                "filepath",
                InputArgument::REQUIRED,
                "Path to the file to copy, relative to the theme directory in design."
            )
            ->addArgument(
                "destination",
                InputArgument::REQUIRED,
                "Destination theme (specified in <package>[/<theme>] format)."
            )
            ->addOption(
                "force", "f",
                InputOption::VALUE_NONE,
                "Overwrite the destination file if it already exists."
            )
            ->addOption(
                "source", null,
                InputOption::VALUE_REQUIRED,
                "Use an alternate theme to copy the file from (specified in <package>[/<theme>] format)."
            )
            ->addOption(
                "adminhtml", null,
                InputOption::VALUE_NONE,
                "Use adminhtml themes for source and destination."
            )
            ->addOption(
                "skin", null,
                InputOption::VALUE_NONE,
                "Copy the file between the theme skin folders."
            );
    }

    /**
     * Execute the command.
     *
     * @param InputInterface  $input
     * @param OutputInterface $output
     *
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->detectMagento($output);

        $source = $this->getDesignPath(
            $input->getOption("source"),
            $input->getArgument("filepath"),
            $input->getOption("skin"),
            $input->getOption("adminhtml")
        );
        $destination = $this->getDesignPath(
            $input->getArgument("destination"),
            $input->getArgument("filepath"),
            $input->getOption("skin"),
            $input->getOption("adminhtml")
        );
        $destination_dir = dirname($destination);

        $output->writeln(sprintf(
            "<info>Copy file:</info>\n\t<comment>Source: %s</comment>\n\t<comment>Destination: %s</comment>",
            $source,
            $destination
        ));

        if (!file_exists($source)) {
            $output->writeln("<error>Source file does not exist!</error>");
            return 1;
        }

        if (file_exists($destination) && !$input->getOption("force")) {
            $output->writeln("<error>Destination file already exists!</error>");
            return 1;
        }

        if (!file_exists($destination_dir)) {
            if (!mkdir($destination_dir, 0755, true)) {
                $output->writeln("<error>Failed to create the destination directory!</error>");
                return 1;
            }
        } else if (!is_dir($destination_dir)) {
            $output->writeln("<error>Destination is not a directory!</error>");
            return 1;
        }

        if (!copy($source, $destination)) {
            $output->writeln("<error>Failed!</error>");
            return 1;
        }

        $output->writeln("<info>Done</info>");

        return 0;
    }

    /**
     * Get the path to the specified theme's design folder
     * or a specific file inside it.
     *
     * @param string      $theme
     * @param string|null $file
     * @param bool        $is_skin
     * @param bool        $is_adminhtml
     *
     * @return string
     */
    protected function getDesignPath($theme, $file = null, $is_skin = false, $is_adminhtml = false)
    {
        @list($package, $theme) = explode("/", $theme);

        $path = array(
            $this->getApplication()->getMagentoRootFolder(),
            $is_skin ? "skin" : "app" . DIRECTORY_SEPARATOR . "design",
            $is_adminhtml ? "adminhtml" : "frontend",
            $package ?: ($is_adminhtml ? "default" : "base"),
            $theme ?: "default"
        );

        if ($file) {
            $path[] = $file;
{'fraction_non_alphanumeric': 0.13036020583190394, 'fraction_numerical': 0.0027444253859348197, 'mean_word_length': 1.8368472267272138, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 102, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3863106', 'n_tokens_mistral': 2355, 'n_tokens_neox': 2277, 'n_words': 518}