class RsyncValidator

Checks that rsync is available.

@internal This is an internal part of Package Manager and may be changed or removed at any time without warning. External code should not interact with this class.

Hierarchy

Expanded class hierarchy of RsyncValidator

1 file declares its use of RsyncValidator
RsyncValidatorTest.php in core/modules/package_manager/tests/src/Kernel/RsyncValidatorTest.php

File

core/modules/package_manager/src/Validator/RsyncValidator.php, line 25

Namespace

Drupal\package_manager\Validator
View source
final class RsyncValidator implements EventSubscriberInterface {
    use StringTranslationTrait;
    public function __construct(ExecutableFinderInterface $executableFinder, ModuleHandlerInterface $moduleHandler) {
    }
    
    /**
     * Checks that rsync is available.
     *
     * @param \Drupal\package_manager\Event\PreOperationStageEvent $event
     *   The event being handled.
     */
    public function validate(PreOperationStageEvent $event) : void {
        try {
            $this->executableFinder
                ->find('rsync');
            $rsync_found = TRUE;
        } catch (LogicException) {
            $rsync_found = FALSE;
        }
        if ($rsync_found === FALSE) {
            $message = $this->t('<code>rsync</code> is not available.');
            if ($this->moduleHandler
                ->moduleExists('help')) {
                $help_url = Url::fromRoute('help.page')->setRouteParameter('name', 'package_manager')
                    ->setOption('fragment', 'package-manager-faq-rsync')
                    ->toString();
                $message = $this->t('@message See the <a href=":url">Package Manager help</a> for more information on how to resolve this.', [
                    '@message' => $message,
                    ':url' => $help_url,
                ]);
            }
            $event->addError([
                $message,
            ]);
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() : array {
        return [
            StatusCheckEvent::class => 'validate',
            PreCreateEvent::class => 'validate',
        ];
    }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.