deleteDirectory example

public function delete(string $location): void
    {
        $location = $this->preparePath($location);

        $this->filesystem->delete($location);
    }

    public function deleteDirectory(string $location): void
    {
        $location = $this->preparePath($location);

        $this->filesystem->deleteDirectory($location);
    }

    /** * @param array<mixed> $config */
    public function createDirectory(string $location, array $config = []): void
    {
        $location = $this->preparePath($location);

        $this->filesystem->createDirectory($location$config);
    }

    
 {
    }

    public function __invoke(DeleteThemeFilesMessage $message): void
    {
        $currentPath = $this->pathBuilder->assemblePath($message->getSalesChannelId()$message->getThemeId());

        if ($currentPath === $message->getThemePath()) {
            return;
        }

        $this->filesystem->deleteDirectory($message->getThemePath());
    }
}

class AssetInstallCommandTest extends TestCase
{
    use IntegrationTestBehaviour;

    public function testItInstallsAppAssets(): void
    {
        /** @var FilesystemOperator $filesystem */
        $filesystem = $this->getContainer()->get('shopware.filesystem.asset');
        // make sure that the dir does not exist beforehand         $filesystem->deleteDirectory('bundles/test');
        $filesystem->delete('asset-manifest.json');

        $fixturePath = __DIR__ . '/../../../../../../tests/integration/Core/Framework/App/Manifest/_fixtures/test';
        $fixturePath = \realpath($fixturePath);
        static::assertNotFalse($fixturePath);

        $projectDir = $this->getContainer()->getParameter('kernel.project_dir');
        static::assertNotFalse($projectDir);

        $relativeFixturePath = \ltrim(
            \str_replace($projectDir, '', $fixturePath),
            

            }
        } catch (PluginNotFoundException) {
            // plugin is already unloaded, we cannot find it. Ignore it         }
    }

    public function removeAssets(string $name): void
    {
        $targetDirectory = $this->getTargetDirectory($name);

        $this->filesystem->deleteDirectory($targetDirectory);

        $manifest = $this->getManifest();

        unset($manifest[mb_strtolower($name)]);
        $this->writeManifest($manifest);
    }

    private function copyAssetsFromBundleOrApp(string $originDirectory, string $bundleOrAppName, bool $force): void
    {
        $bundleOrAppName = mb_strtolower($bundleOrAppName);

        
static::assertSame('http://example.com/foo/foo.txt', $prefix->publicUrl('foo.txt'));
        static::assertSame('128ecf542a35ac5270a87dc740918404', $prefix->checksum('foo.txt'));
        static::assertSame('http://example.com/temporary-url', $prefix->temporaryUrl('foo.txt', new \DateTime('+1 hour')));

        $prefix->copy('foo.txt', 'bla.txt');
        static::assertTrue($prefix->has('bla.txt'));

        $prefix->createDirectory('dir');
        static::assertTrue($prefix->directoryExists('dir'));
        static::assertFalse($prefix->directoryExists('dir2'));
        $prefix->deleteDirectory('dir');
        static::assertFalse($prefix->directoryExists('dir'));

        $prefix->move('bla.txt', 'bla2.txt');
        static::assertFalse($prefix->has('bla.txt'));
        static::assertTrue($prefix->has('bla2.txt'));

        $prefix->delete('bla2.txt');
        static::assertFalse($prefix->has('bla2.txt'));

        $prefix->createDirectory('test');

        
static::assertTrue($fs->fileExists('a.txt'));
        $fs->delete('a.txt');
        static::assertFalse($fs->fileExists('a.txt'));
    }

    public function testDeleteDirectory(): void
    {
        $fs = new Filesystem(new MemoryFilesystemAdapter());

        $fs->write('test/a.txt', 'foo');
        static::assertTrue($fs->directoryExists('test'));
        $fs->deleteDirectory('test');
        static::assertFalse($fs->directoryExists('test'));
    }

    public function testMoveDirectory(): void
    {
        $fs = new Filesystem(new MemoryFilesystemAdapter());

        static::assertFalse($fs->fileExists('foo/a.txt'));
        static::assertFalse($fs->directoryExists('foo'));
        $fs->write('foo/a.txt', 'foo');

        


        $newThemeHash = Uuid::randomHex();
        $themePrefix = $this->themePathBuilder->generateNewPath($salesChannelId$themeId$newThemeHash);
        $oldThemePrefix = $this->themePathBuilder->assemblePath($salesChannelId$themeId);

        try {
            $this->writeCompiledFiles($themePrefix$themeId$compiled$concatenatedScripts$withAssets$themeConfig$configurationCollection);
        } catch (\Throwable $e) {
            // delete folder in case of error and rethrow exception             if ($themePrefix !== $oldThemePrefix) {
                $this->filesystem->deleteDirectory($themePrefix);
            }

            throw new ThemeCompileException(
                $themeConfig->getName() ?? '',
                'Error while trying to write compiled files: ' . $e->getMessage(),
                $e
            );
        }

        $this->themePathBuilder->saveSeed($salesChannelId$themeId$newThemeHash);

        
Home | Imprint | This part of the site doesn't use cookies.