/** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { $fs = new Filesystem(); $addon_id = $input->getArgument('name'); $abs_cart_path = rtrim(realpath($input->getArgument('cart-directory')), '\\/') . '/'; $this->validateCartPath($abs_cart_path, $input, $output); $abs_addon_path = rtrim(realpath($input->getArgument('addon-directory')), '\\/') . '/'; chdir($abs_addon_path); $addon = new Addon($addon_id, $abs_addon_path); $addon_files_glob_masks = $addon->getFilesGlobMasks(); $addon_files_glob_masks = array_filter($addon_files_glob_masks, function ($glob_mask) { // Always ignore "design/themes/" masks because there shouldn't // be such directory in add-on files directory if (mb_strpos($glob_mask, 'design/themes/') === 0) { return false; } return true; }); $glob_matches = $addon->matchFilesAgainstGlobMasks($addon_files_glob_masks, $abs_addon_path); $output->writeln(sprintf('<fg=magenta;options=bold>Creating symlinks at the "%s" directory:</>', $abs_cart_path)); foreach ($glob_matches as $rel_filepath) { $abs_addon_filepath = $abs_addon_path . $rel_filepath; // Add-on templates at the "var/themes_repository/" directory will be // symlinked to the "design/themes/" directory. if ($input->getOption('templates-to-design') && mb_strpos($rel_filepath, 'var/themes_repository/') === 0) { $abs_cart_filepath = $abs_cart_path . 'design/themes/' . mb_substr($rel_filepath, mb_strlen('var/themes_repository/')); } else { $abs_cart_filepath = $abs_cart_path . $rel_filepath; } // Delete existing files and links located at cart directory clearstatcache(true, $abs_cart_filepath); if (file_exists($abs_cart_filepath)) { $is_link = is_link($abs_cart_filepath); $is_file = $is_link ? is_file(readlink($abs_cart_filepath)) : is_file($abs_cart_filepath); $is_dir = $is_link ? is_dir(readlink($abs_cart_filepath)) : is_dir($abs_cart_filepath); // Confirm overwriting of the found conflicting file or directory on the same path. // We only ask confirmation for files which are not symbolic links, because we assume // that symbolic links were created by this command earlier and can be overwritten without // the loss of any data. if (!$is_link && ($is_file || $is_dir)) { $helper = $this->getHelper('question'); $question = new ConfirmationQuestion(sprintf('<question>%s "%s" already exists. Overwrite? [y/N]:</question> ', $is_dir ? 'Directory' : 'File', $abs_cart_filepath), false); if (!$helper->ask($input, $output, $question)) { continue; } } $fs->remove($abs_cart_filepath); } $symlink_target_filepath = $input->getOption('relative') ? $fs->makePathRelative(dirname($abs_addon_filepath), dirname($abs_cart_filepath)) . basename($abs_cart_filepath) : $abs_addon_filepath; $fs->symlink($symlink_target_filepath, $abs_cart_filepath); $output->writeln(sprintf('Creating symlink for %s... <info>OK</info>', $rel_filepath)); } }
/** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { $fs = new Filesystem(); $addon_id = $input->getArgument('name'); $abs_cart_path = rtrim(realpath($input->getArgument('cart-directory')), '\\/') . '/'; $this->validateCartPath($abs_cart_path, $input, $output); $fs->mkdir($input->getArgument('addon-directory'), 0755); $abs_addon_path = rtrim(realpath($input->getArgument('addon-directory')), '\\/') . '/'; $output->writeln(sprintf('<fg=magenta;options=bold>%s add-on files to the "%s" directory:</>', $input->getOption('delete') ? 'Moving' : 'Copying', $abs_addon_path)); $addon = new Addon($addon_id, $abs_cart_path); $addon_files_glob_masks = $addon->getFilesGlobMasks(); $addon_files_glob_masks = array_filter($addon_files_glob_masks, function ($glob_mask) use($input) { if ($input->getOption('templates-from-design')) { // Ignore "var/themes_repository/" masks if (mb_strpos($glob_mask, 'var/themes_repository/') === 0) { return false; } return true; } else { // Ignore "design/themes/" masks if (mb_strpos($glob_mask, 'design/themes/') === 0) { return false; } return true; } }); $glob_matches = $addon->matchFilesAgainstGlobMasks($addon_files_glob_masks, $abs_cart_path); $counter = 0; foreach ($glob_matches as $rel_filepath) { $abs_cart_filepath = $abs_cart_path . $rel_filepath; // Skip links pointing to target add-on directory if (is_link($abs_cart_filepath)) { $output->writeln(sprintf('Found symlink "%s", <info>skipping</info>', $rel_filepath)); continue; } // Add-on templates at the "design/" directory will be // exported to the "var/themes_repository/" directory. if ($input->getOption('templates-from-design') && mb_strpos($rel_filepath, 'design/themes/') === 0) { $abs_addon_filepath = $abs_addon_path . 'var/themes_repository/' . mb_substr($rel_filepath, mb_strlen('design/themes/')); } else { $abs_addon_filepath = $abs_addon_path . $rel_filepath; } if (file_exists($abs_addon_filepath)) { $helper = $this->getHelper('question'); $question = new ConfirmationQuestion(sprintf('<question>%s "%s" already exists. Overwrite? [y/N]:</question> ', is_dir($abs_addon_filepath) ? 'Directory' : 'File', $abs_addon_filepath), false); if (!$helper->ask($input, $output, $question)) { continue; } } $fs->mkdir(dirname($abs_addon_filepath), 0755); $output->write(sprintf('%s "%s" to "%s" ... ', $input->getOption('delete') ? 'Moving' : 'Copying', $rel_filepath, $abs_addon_filepath)); if ($input->getOption('delete')) { $fs->rename($abs_cart_filepath, $abs_addon_filepath, true); } else { if (is_dir($abs_cart_filepath)) { $fs->mirror($abs_cart_filepath, $abs_addon_filepath, null, ['override' => true]); } elseif (is_file($abs_cart_filepath)) { $fs->copy($abs_cart_filepath, $abs_addon_filepath, true); } } $counter++; $output->writeln('<info>OK</info>'); } $output->writeln(sprintf('<options=bold>%u</> <info>files and directories have been %s.</info>', $counter, $input->getOption('delete') ? 'moved' : 'copied')); }