Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename children directories before parent in renameSubFolders #280

Merged
merged 3 commits into from
May 6, 2024

Conversation

bancer
Copy link

@bancer bancer commented May 3, 2024

Fixes #279.

@ADmad
Copy link
Member

ADmad commented May 3, 2024

Using the RecursiveIteratorIterator::CHILD_FIRST flag when creating the iterator instance should avoid having to manually sort the paths.

@bancer
Copy link
Author

bancer commented May 3, 2024

    protected function renameSubFolders(string $path): void
    {
        $this->io->out("Moving sub directories of <info>$path</info>");
        if ($this->args->getOption('dry-run')) {
            return;
        }

        $folders = ['Layout', 'Element', 'Cell', 'Email', 'Plugin', 'Flash'];

        foreach ($folders as $folder) {
            $dirIter = new RecursiveDirectoryIterator(
                $path,
                RecursiveDirectoryIterator::UNIX_PATHS
            );
            $iterIter = new RecursiveIteratorIterator($dirIter,  RecursiveIteratorIterator::CHILD_FIRST);
            $templateDirs = new RegexIterator(
                $iterIter,
                '#/' . $folder . '/\.$#',
                RecursiveRegexIterator::SPLIT
            );

            foreach ($templateDirs as $val) {
                $this->renameWithCasing(
                    $val[0] . '/' . $folder,
                    $val[0] . '/' . strtolower($folder)
                );
            }
        }
    }

This with RecursiveIteratorIterator::CHILD_FIRST did not work for me. Still got "PHP Fatal error: Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(/path/to/project/templates/Layout/Email): Failed to open directory: No such file or directory in /path/to/upgrade/src/Command/FileRenameCommand.php:210" error.

@markstory markstory merged commit 1fd0a42 into cakephp:4.x May 6, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants