client = $client; $this->query = $query; parent::__construct(); } protected function execute(InputInterface $input, OutputInterface $output): int { chdir(__DIR__.'/../../public'); $remoteFiles = $this->client->ls('/'); $localFiles = []; foreach ($this->query->find() as $entity) { $localFiles[basename($entity->getFile())] = $entity->getFile(); } foreach ($localFiles as $basename => $file) { if (!$this->client->exists($basename)) { $this->client->sendFile($file, $basename); $output->writeln(sprintf( 'Fichier %s envoyé', $file )); } } $isFirst = true; foreach ($remoteFiles as $remoteFile) { $name = $remoteFile['{DAV:}displayname']; if (!isset($localFiles[$name]) && !$isFirst) { $this->client->rm($name); $output->writeln(sprintf( 'Fichier distant %s supprimé', $name )); } $isFirst = false; } return Command::SUCCESS; } }