public function uninstall(): OperationResult
    {
        $result = new OperationResult();

        $sourcePath = "{$this->packageInstallDir}/.installer/%s/files";
        foreach ($this->projectType->getProjectDirs() as $projectDir) {
            $directory = sprintf($sourcePath, $projectDir);
            if (is_dir($directory)) {
                /** @var \RecursiveDirectoryIterator $iteratorPackage */
                $iteratorPackage = new \RecursiveIteratorIterator(
                    new \RecursiveDirectoryIterator(
                        $directory,
                        \RecursiveDirectoryIterator::SKIP_DOTS
                    ),
                    \RecursiveIteratorIterator::CHILD_FIRST
                );

                /** @var \SplFileInfo $file */
                foreach ($iteratorPackage as $file) {
                    $target = "{$this->projectRootDir}/{$iteratorPackage->getSubPathname()}";
                    if (!file_exists($target)) {
                        continue;
                    }
                    if ($file->isDir()) {
                        @rmdir($target);
                    } else {
                        assert(is_string($file->getRealPath()));
                        $hashTarget = hash_file('sha1', $target);
                        $hashSource = hash_file('sha1', $file->getRealPath());
                        if ($hashSource === $hashTarget) {
                            if (!@unlink($target)) {
                                $result->addErrorMessage("<error>Could not delete file '${target}'</error>");
                            }
                        }
                    }
                }
            }
        }

        if (!$result->isFailure()) {
            $result->addStatusMessage("Successfully uninstalled files for {$this->packageName}");
        }

        return $result;
    }
public function uninstall(): OperationResult
    {
        $result = new OperationResult();

        $sourcePath = "{$this->packageInstallDir}/.installer/%s/files";
        foreach ($this->projectType->getProjectDirs() as $projectDir) {
            $directory = sprintf($sourcePath, $projectDir);
            if (is_dir($directory)) {
                /** @var \RecursiveDirectoryIterator $iteratorPackage */
                $iteratorPackage = new \RecursiveIteratorIterator(
                    new \RecursiveDirectoryIterator(
                        $directory,
                        \RecursiveDirectoryIterator::SKIP_DOTS
                    ),
                    \RecursiveIteratorIterator::CHILD_FIRST
                );

                /** @var \SplFileInfo $file */
                foreach ($iteratorPackage as $file) {
                    $target = "{$this->projectRootDir}/{$iteratorPackage->getSubPathname()}";
                    if (!file_exists($target)) {
                        continue;
                    }
                    if ($file->isDir()) {
                        @rmdir($target);
                    } else {
                        assert(is_string($file->getRealPath()));
                        $hashTarget = hash_file('sha1', $target);
                        $hashSource = hash_file('sha1', $file->getRealPath());
                        if ($hashSource === $hashTarget) {
                            if (!@unlink($target)) {
                                $result->addErrorMessage("<error>Could not delete file '${target}'</error>");
                            }
                        }
                    }
                }
            }
        }

        if (!$result->isFailure()) {
            $result->addStatusMessage("Successfully uninstalled files for {$this->packageName}");
        }

        return $result;
    }
public function uninstall ( ) : OperationResult { $ result = new OperationResult ( ) ; $ sourcePath = "{$this->packageInstallDir}/.installer/%s/files" ; foreach ( $ this -> projectType -> getProjectDirs ( ) as $ projectDir ) { $ directory = sprintf ( $ sourcePath , $ projectDir ) ; if ( is_dir ( $ directory ) ) { /** @var \RecursiveDirectoryIterator $iteratorPackage */ $ iteratorPackage = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ directory , \ RecursiveDirectoryIterator :: SKIP_DOTS ) , \ RecursiveIteratorIterator :: CHILD_FIRST ) ; /** @var \SplFileInfo $file */ foreach ( $ iteratorPackage as $ file ) { $ target = "{$this->projectRootDir}/{$iteratorPackage->getSubPathname()}" ; if ( ! file_exists ( $ target ) ) { continue ; } if ( $ file -> isDir ( ) ) { @ rmdir ( $ target ) ; } else { assert ( is_string ( $ file -> getRealPath ( ) ) ) ; $ hashTarget = hash_file ( 'sha1' , $ target ) ; $ hashSource = hash_file ( 'sha1' , $ file -> getRealPath ( ) ) ; if ( $ hashSource === $ hashTarget ) { if ( ! @ unlink ( $ target ) ) { $ result -> addErrorMessage ( "<error>Could not delete file '${target}'</error>" ) ; } } } } } } if ( ! $ result -> isFailure ( ) ) { $ result -> addStatusMessage ( "Successfully uninstalled files for {$this->packageName}" ) ; } return $ result ; }
Tries to remove all files that were automatically installed.
- removes empty directories
- removes installed files if their content is identical to the fresh new file
- uses sha1 for checksum

@return OperationResult
Tries to remove all files that were automatically installed . - removes empty directories - removes installed files if their content is identical to the fresh new file - uses sha1 for checksum