Remove symlinks for Contao sources before update, then add them again afterwards.

{@inheritdoc}

@throws \InvalidArgumentException When the requested package is not installed.
341104
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
    {
        if (!$repo->hasPackage($initial)) {
            throw new \InvalidArgumentException('Package is not installed: '.$initial);
        }

        $this->logVerbose(sprintf('Updating Contao sources for %s', $initial->getName()));

        $contaoRoot = $this->getContaoRoot();

        $this->removeSymlinks($initial, $contaoRoot, $this->getSources($initial));

        parent::update($repo, $initial, $target);

        $this->addSymlinks($target, $contaoRoot, $this->getSources($target));
        $this->addCopies($target, $this->getFilesRoot(), $this->getUserFiles($target), self::DUPLICATE_IGNORE);
        $this->addRunonces($target, $this->getRunonces($target));

        $this->logVerbose('');
    }
707691
protected function getSource($package)
    {
        $namespaces = $this->config->getNamespaces();

        $source = isset($namespaces[$package]) ? $namespaces[$package] : null;

        if (is_null($source) || ! $this->files->isDirectory($source)) {
            throw new \InvalidArgumentException("Configuration not found.");
        }

        return $source;
    }
763611
public function symlink($target, $link)
    {
        if (!file_exists($target)) {
            throw new \InvalidArgumentException('Target not found: ' . $target);
        }
        if ($this->relative) {
            $target = $this->makePathRelative($target, dirname($link));
        }
        $this->fs->symlink($target, $link, $this->copyOnWindows);
    }
182512
protected function checkAndRemovePackageSymlinks(StorageInterface $storage)
    {
        if (!$storage instanceof PackageStorage) {
            return;
        }
        foreach ($storage->getPublicResourcePaths() as $packageKey => $path) {
            $targetPathAndFilename = $this->path . $packageKey;
            if (Files::is_link($targetPathAndFilename)) {
                Files::unlink($targetPathAndFilename);
            }
        }
    }
1365577
public function updateCode( PackageInterface $initial, PackageInterface $target )
    {
        $actualLegacyDir = $this->ezpublishLegacyDir;
        $this->ezpublishLegacyDir = $this->generateTempDirName();
        if ( $this->io->isVerbose() )
        {
            $this->io->write( "Installing in temporary directory." );
        }

        $this->installCode( $target );

        $fileSystem = new Filesystem();
        if ( $this->io->isVerbose() )
        {
            $this->io->write( "Updating new code over existing installation." );
        }
        /// @todo the following function does not warn of any failures in copying stuff over. We should probably fix it...
        $fileSystem->copyThenRemove( $this->ezpublishLegacyDir, $actualLegacyDir );

        $this->ezpublishLegacyDir = $actualLegacyDir;
    }
397721
private function initInstalledPackages()
    {
        /** @var PackageInterface $package */
        foreach ($this->installedRepository->getPackages() as $package) {
            $operator = $this->getFilterOperator($package);
            /** @var Link $link */
            $link = current($this->arrayLoader->parseLinks($this->package->getName(), $this->package->getVersion(), 'installed', array($package->getName() => $operator.$package->getPrettyVersion())));
            $link = $this->includeRootConstraint($package, $link);

            $this->requires[$package->getName()] = $link;
        }
    }
208591
public function upgradeDatabase()
    {
        $em = $this->getPackageEntityManager();
        if ($em !== null) {
            $this->destroyProxyClasses($em);
            $this->installEntitiesDatabase();
        }
        static::installDB($this->getPackagePath() . '/' . FILENAME_PACKAGE_DB);
    }
742106
public function rewritingSelfVersionDependencies()
    {
        $composer = $this->embeddedComposer->createComposer($this->io);
        $package = $composer->getPackage();
        $configSource = new JsonConfigSource(new JsonFile('composer.json'));

        foreach (BasePackage::$supportedLinkTypes as $type => $meta) {
            foreach ($package->{'get'.$meta['method']}() as $link) {
                if ($link->getPrettyConstraint() === 'self.version') {
                    $configSource->addLink(
                        $type,
                        $link->getTarget(),
                        $package->getPrettyVersion()
                    );
                }
            }
        }
    }
787243
public function setDefaultPackageKey($defaultPackageKey)
    {
        if (!preg_match(Package::PATTERN_MATCH_PACKAGEKEY, $defaultPackageKey)) {
            throw new \InvalidArgumentException('The given argument was not a valid package key.', 1277287099);
        }
        $this->defaultPackageKey = $defaultPackageKey;
    }
1160340
protected function updateAutoloader()
    {
        $cwd = getcwd();

        try {
            /** @var DumpAutoload $autoload */
            $autoload = $this->actions['autoload'];
            $autoload->execute();
        } catch (PackageManagerException $e) {
            // Write access is potentially disabled
        }

        chdir($cwd);
    }
684898
public function postInstall()
    {
        if (!$this->initialized) {
            $this->initialize();
        }

        // This method is called twice. Run it only once.
        if (!$this->runPostInstall) {
            return;
        }

        $this->runPostInstall = false;

        $this->io->write('<info>Synchronizing Puli with Composer</info>');

        $rootPackage = $this->composer->getPackage();
        $composerPackages = $this->loadComposerPackages();
        $prodPackageNames = $this->filterProdPackageNames($composerPackages, $rootPackage);
        $env = $this->isDev ? PuliPackage::ENV_DEV : PuliPackage::ENV_PROD;

        try {
            $puliPackages = $this->loadPuliPackages();
        } catch (PuliRunnerException $e) {
            $this->printWarning('Could not load Puli packages', $e);

            return;
        }

        // Don't remove non-existing packages in production environment
        // Removed packages could be dev dependencies (i.e. "require-dev"
        // of the root package or "require" of another dev dependency), and
        // we can't find out whether they are since Composer doesn't load them
        if (PuliPackage::ENV_PROD !== $env) {
            $this->removeRemovedPackages($composerPackages, $puliPackages);
        }

        $this->installNewPackages($composerPackages, $prodPackageNames, $puliPackages);

        // Don't print warnings for non-existing packages in production
        if (PuliPackage::ENV_PROD !== $env) {
            $this->checkForNotFoundErrors($puliPackages);
        }

        $this->checkForNotLoadableErrors($puliPackages);
        $this->adoptComposerName($puliPackages);
        $this->removePuliDir();
        $this->buildPuli();
    }
365906
public function move($from, $to)
    {
        $this->clearAll();

        $from = trim($from);
        if (!$this->validatePath($from)) {
            throw new \InvalidArgumentException('Invalid source path');
        }

        $to = trim($to);
        if (!$this->validatePath($to)) {
            throw new \InvalidArgumentException('Invalid destination path');
        }

        $this->addCommandName(self::GIT_MOVE);
        $this->addCommandSubject($from);
        $this->addCommandSubject2($to);

        return $this->getCommand();
    }
428529
protected function removeStandards(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        $srcStandards = $this->getSourceStandards($package);
        $dstStandards = $this->getDestinationStandards($repo);
        $this->io->writeError('    Removing PHP-CodeSniffer Standards:', false);
        foreach ($srcStandards as $srcStandard) {
            if (! $dstStandards->hasStandard($srcStandard)) {
                continue;
            }
            $this->io->writeError(sprintf(' <info>%s</info>', $srcStandard->getName()));
            $dstStandard = $dstStandards->getStandard($srcStandard);

            $this->filesystem->removeDirectory($dstStandard->getPath());
        }
    }
455059
static function systemRepositoryInformation()
    {
        $ini = eZINI::instance( 'package.ini' );
        $vendor = $ini->variable( 'RepositorySettings', 'Vendor' );
        return eZPackage::repositoryInformation( $vendor );
    }
637676
private function prependRepositories(RootPackageInterface $root)
    {
        $json = $this->getJson();

        if (isset($json['repositories'])) {
            $repoManager  = $this->getComposer()->getRepositoryManager();
            $repositories = [];

            foreach ($json['repositories'] as $repoJson) {
                $this->addRepository($repoManager, $repositories, $repoJson);
            }

            /** @var \Composer\Package\RootPackageInterface $unwrapped */
            self::unwrapIfNeeded($root, 'setRepositories')
                ->setRepositories(array_merge($repositories, $root->getRepositories()));
        }
    }
512233
protected function scanAvailablePackages()
    {
        $newPackageStatesConfiguration = ['packages' => []];
        foreach ($this->findComposerPackagesInPath($this->packagesBasePath) as $packagePath) {
            $composerManifest = ComposerUtility::getComposerManifest($packagePath);
            if (!isset($composerManifest['name'])) {
                throw new InvalidConfigurationException(sprintf('A package composer.json was found at "%s" that contained no "name".', $packagePath), 1445933572);
            }

            if (strpos($packagePath, Files::concatenatePaths([$this->packagesBasePath, 'Inactive'])) === 0) {
                // Skip packages in legacy "Inactive" folder.
                continue;
            }

            $packageKey = $this->getPackageKeyFromManifest($composerManifest, $packagePath);
            $this->composerNameToPackageKeyMap[strtolower($composerManifest['name'])] = $packageKey;

            $packageConfiguration = $this->preparePackageStateConfiguration($packageKey, $packagePath, $composerManifest);
            if (isset($newPackageStatesConfiguration['packages'][$composerManifest['name']])) {
                throw new PackageException(
                    sprintf('The package with the name "%s" was found more than once, please make sure it exists only once. Paths "%s" and "%s".',
                        $composerManifest['name'],
                        $packageConfiguration['packagePath'],
                        $newPackageStatesConfiguration['packages'][$composerManifest['name']]['packagePath']),
                    1493030262
                );
            }

            $newPackageStatesConfiguration['packages'][$composerManifest['name']] = $packageConfiguration;
        }

        return $newPackageStatesConfiguration;
    }
658349
public static function checkPackageUpdates()
    {
        $em = \ORM::entityManager();
        $items = self::getAvailableMarketplaceItems(false);
        foreach ($items as $i) {
            $p = Package::getByHandle($i->getHandle());
            if (is_object($p)) {
                /**
                 * @var $p \Concrete\Core\Entity\Package
                 */
                $p->setPackageAvailableVersion($i->getVersion());
                $em->persist($p);
            }
        }
        $em->flush();
    }