ttskch / WordPress.Skeleton

Composer based WordPress project skeleton.
http://ttskch.github.io/WordPress.Skeleton/
GNU General Public License v2.0
46 stars 8 forks source link

Cannot create-project on Windows 7 #2

Closed ttskch closed 8 years ago

ttskch commented 10 years ago

php 5.3+ is ready to use symlink() on windows, but following error occurs on my windows 7 64bit environment... refs. https://bugs.php.net/bug.php?id=48975 ?

$ composer install --no-dev
Loading composer repositories with package information
Installing dependencies from lock file
  - Installing johnpbloch/wordpress (4.3.1)
    Loading from cache

Script Installer::postPackageInstall handling the post-package-install event terminated with an exception

  [ErrorException]
  symlink(): Could not fetch file information(error 3)

install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [--ignore-platform-reqs] [packages1] ... [packagesN]
ttskch commented 9 years ago

workaround:

$ composer create-project wordpress/skeleton {project-name} --no-scripts
$ cd {project-name}
$ ln -s ../../wp-content/themes wp/wp-content/my-themes   # or create symlink with some way
$ rm -rf wp/wp-content/plugins
$ ln -s ../../wp-content/plugins wp/wp-content/plugins   # or create symlink with some way
FlyingDR commented 8 years ago

@qckanemoto, here is how it can be fixed. Separate set of console commands are used depending on if it is Windows or not. Unfortunately plugins directory removal through PHP causes "Access denied' error on subsequent attempt to create link.

    private static function initWordPress()
    {
        $isWin = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
        $projectRoot = dirname(__DIR__);
        // create symlinks under wp/wp-content dir.
        $paths = array(
            array(
                'target' => '../../wp-content/themes',
                'link'   => "{$projectRoot}/wp/wp-content/my-themes",
            ),
            array(
                'target' => '../../wp-content/plugins',
                'link'   => "{$projectRoot}/wp/wp-content/plugins",
            ),
        );
        foreach ($paths as $path) {
            if ($isWin) {
                array_walk($path, function (&$v) {
                    $v = str_replace('/', '\\', $v);
                });
            }
            if (file_exists($path['link'])) {
                $cmd = $isWin ? 'rmdir /s /q %s' : 'rm -rf %s';
                exec(sprintf($cmd, escapeshellarg($path['link'])));
            }
            $cmd = strtr($isWin ? 'mklink /D {link} {target}' : 'ln -s {target} {link}', array(
                '{link}'   => escapeshellarg($path['link']),
                '{target}' => escapeshellarg($path['target']),
            ));
            exec($cmd);
        }
    }

I've tested it on both Windows 7 and Debian, works fine for me.

ttskch commented 8 years ago

@FlyingDR So sorry for my very late reply 🙇 And thanks so much for your advice! I implemented your idea in #7 and merged it 👍