Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move tools to vendor bin plugin #762

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

require_once './vendor/autoload.php';
require_once './vendor-bin/cs-fixer/vendor/autoload.php';

use Nextcloud\CodingStandard\Config;

Expand Down
15 changes: 12 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
}
},
"scripts": {
"post-install-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all install --ansi"
],
"post-update-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all update --ansi"
],
"cs:fix": "php-cs-fixer fix",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -not -path './node_modules/*' -print0 | xargs -0 -n1 php -l",
Expand All @@ -19,15 +25,18 @@
"optimize-autoloader": true,
"classmap-authoritative": true,
"platform": {
"php": "8.0.2"
"php": "8.1"
},
"allow-plugins": {
"bamarni/composer-bin-plugin": true
}
},
"require-dev": {
"nextcloud/coding-standard": "^1.0.0",
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^5.6",
"doctrine/dbal": "^3",
"deepdiver/zipstreamer": "^2.0",
"nextcloud/ocp": "dev-master"
"nextcloud/ocp": "dev-master",
"bamarni/composer-bin-plugin": "^1.8"
}
}
59 changes: 58 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/BackgroundJob/UserExportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
LoggerInterface $logger,
NotificationManager $notificationManager,
UserExportMapper $mapper,
IRootFolder $root
IRootFolder $root,
) {
parent::__construct($timeFactory);

Expand Down
2 changes: 1 addition & 1 deletion lib/BackgroundJob/UserImportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(
NotificationManager $notificationManager,
UserImportMapper $mapper,
IConfig $config,
IRootFolder $root
IRootFolder $root,
) {
parent::__construct($timeFactory);

Expand Down
4 changes: 2 additions & 2 deletions lib/Command/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$folder = realpath($folder);

$exportName = $user->getUID().'_'.date('Y-m-d_H-i-s');
$exportName = $user->getUID() . '_' . date('Y-m-d_H-i-s');
$partSuffix = '.part';
$exportPath = "$folder/$exportName.zip$partSuffix";

Expand All @@ -205,7 +205,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$path = $exportDestination->getPath();
$finalPath = substr($path, 0, -mb_strlen($partSuffix));
if (rename($path, $finalPath) === false) {
throw new \Exception('Failed to rename '.basename($path).' to '.basename($finalPath));
throw new \Exception('Failed to rename ' . basename($path) . ' to ' . basename($finalPath));
}
$io->writeln("Export saved in $finalPath");
} catch (\Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ApiController extends OCSController {
public function __construct(
IRequest $request,
IUserSession $userSession,
UserMigrationService $migrationService
UserMigrationService $migrationService,
) {
parent::__construct(Application::APP_ID, $request);
$this->userSession = $userSession;
Expand Down
6 changes: 3 additions & 3 deletions lib/ExportDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ public function copyFolder(Folder $folder, string $destinationPath, ?callable $n
continue;
}
$read = $node->fopen('rb');
$success = $this->streamer->addFileFromStream($read, $destinationPath.'/'.$node->getName(), [
$success = $this->streamer->addFileFromStream($read, $destinationPath . '/' . $node->getName(), [
'timestamp' => $node->getMTime(),
]);
if (!$success) {
throw new UserMigrationException('Failed to copy file into '.$destinationPath.'/'.$node->getName().' in archive');
throw new UserMigrationException('Failed to copy file into ' . $destinationPath . '/' . $node->getName() . ' in archive');
}
} elseif ($node instanceof Folder) {
$this->copyFolder($node, $destinationPath.'/'.$node->getName(), $nodeFilter);
$this->copyFolder($node, $destinationPath . '/' . $node->getName(), $nodeFilter);
} else {
// ignore unknown node type, shouldn't happen
continue;
Expand Down
12 changes: 6 additions & 6 deletions lib/ImportSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getFileContents(string $path): string {
if (is_string($string)) {
return $string;
} else {
throw new UserMigrationException('Failed to get '.$path.' from archive');
throw new UserMigrationException('Failed to get ' . $path . ' from archive');
}
}

Expand All @@ -70,7 +70,7 @@ public function getFileAsStream(string $path) {
if ($stream !== false) {
return $stream;
} else {
throw new UserMigrationException('Failed to get '.$path.' from archive');
throw new UserMigrationException('Failed to get ' . $path . ' from archive');
}
}

Expand All @@ -92,7 +92,7 @@ public function pathExists(string $path): bool {
* {@inheritDoc}
*/
public function copyToFolder(Folder $destination, string $sourcePath): void {
$sourcePath = rtrim($sourcePath, '/').'/';
$sourcePath = rtrim($sourcePath, '/') . '/';
$files = $this->archive->getFolder($sourcePath);

try {
Expand All @@ -111,10 +111,10 @@ public function copyToFolder(Folder $destination, string $sourcePath): void {
} catch (NotFoundException $e) {
$folder = $destination->newFolder($path);
}
$this->copyToFolder($folder, $sourcePath.$path);
$this->copyToFolder($folder, $sourcePath . $path);
$folder->touch($stat['mtime']);
} else {
$stream = $this->archive->getStream($sourcePath.$path, 'r');
$stream = $this->archive->getStream($sourcePath . $path, 'r');
if ($stream === false) {
throw new UserMigrationException('Failed to get "' . $sourcePath . $path . '" from archive');
}
Expand Down Expand Up @@ -171,7 +171,7 @@ public function getOriginalUid(): string {
if (isset($data['uid'])) {
return $data['uid'];
} else {
throw new UserMigrationException('No uid found in '.static::PATH_USER);
throw new UserMigrationException('No uid found in ' . static::PATH_USER);
}
} catch (\Exception $e) {
throw new UserMigrationException('Failed to original uid', 0, $e);
Expand Down
30 changes: 15 additions & 15 deletions lib/Migrator/FilesMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
class FilesMigrator implements IMigrator, ISizeEstimationMigrator {
use TMigratorBasicVersionHandling;

protected const PATH_FILES = Application::APP_ID.'/files';
protected const PATH_VERSIONS = Application::APP_ID.'/files_versions';
protected const PATH_TAGS = Application::APP_ID.'/tags.json';
protected const PATH_SYSTEMTAGS = Application::APP_ID.'/systemtags.json';
protected const PATH_COMMENTS = Application::APP_ID.'/comments.json';
protected const PATH_FILES = Application::APP_ID . '/files';
protected const PATH_VERSIONS = Application::APP_ID . '/files_versions';
protected const PATH_TAGS = Application::APP_ID . '/tags.json';
protected const PATH_SYSTEMTAGS = Application::APP_ID . '/systemtags.json';
protected const PATH_COMMENTS = Application::APP_ID . '/comments.json';

protected IRootFolder $root;

Expand All @@ -79,7 +79,7 @@ public function __construct(
ISystemTagManager $systemTagManager,
ISystemTagObjectMapper $systemTagMapper,
ICommentsManager $commentsManager,
IL10N $l10n
IL10N $l10n,
) {
$this->root = $rootFolder;
$this->tagManager = $tagManager;
Expand Down Expand Up @@ -114,7 +114,7 @@ public function getEstimatedExportSize(IUser $user): int|float {
}

try {
$versionsFolder = $this->root->get('/'.$uid.'/'.FilesVersionsStorage::VERSIONS_ROOT);
$versionsFolder = $this->root->get('/' . $uid . '/' . FilesVersionsStorage::VERSIONS_ROOT);
if ($versionsFolder instanceof Folder) {
$size += $versionsFolder->getSize() / 1024;
}
Expand Down Expand Up @@ -156,7 +156,7 @@ private function estimateFolderSize(Folder $folder, ?callable $nodeFilter = null
public function export(
IUser $user,
IExportDestination $exportDestination,
OutputInterface $output
OutputInterface $output,
): void {
$output->writeln('Exporting files…');

Expand All @@ -174,7 +174,7 @@ public function export(

try {
if (class_exists(FilesVersionsStorage::class)) {
$versionsFolder = $this->root->get('/'.$uid.'/'.FilesVersionsStorage::VERSIONS_ROOT);
$versionsFolder = $this->root->get('/' . $uid . '/' . FilesVersionsStorage::VERSIONS_ROOT);
$output->writeln('Exporting file versions…');
try {
$exportDestination->copyFolder($versionsFolder, static::PATH_VERSIONS);
Expand Down Expand Up @@ -258,11 +258,11 @@ private function collectIds(Folder $folder, string $rootPath, ?callable $nodeFil
if (($nodeFilter !== null) && !$nodeFilter($node)) {
continue;
}
$objectIds[preg_replace('/^'.preg_quote($rootPath, '/').'/', '', $node->getPath())] = $node->getId();
$objectIds[preg_replace('/^' . preg_quote($rootPath, '/') . '/', '', $node->getPath())] = $node->getId();
if ($node instanceof Folder) {
$this->collectIds($node, $rootPath, $nodeFilter, $objectIds);
} elseif (!($node instanceof File)) {
throw new UserMigrationException('Unsupported node type: '.get_class($node));
throw new UserMigrationException('Unsupported node type: ' . get_class($node));
}
}

Expand All @@ -275,10 +275,10 @@ private function collectIds(Folder $folder, string $rootPath, ?callable $nodeFil
public function import(
IUser $user,
IImportSource $importSource,
OutputInterface $output
OutputInterface $output,
): void {
if ($importSource->getMigratorVersion($this->getId()) === null) {
$output->writeln('No version for migrator '.$this->getId().' ('.static::class.'), skipping import…');
$output->writeln('No version for migrator ' . $this->getId() . ' (' . static::class . '), skipping import…');
return;
}
$output->writeln('Importing files…');
Expand All @@ -296,9 +296,9 @@ public function import(
if ($importSource->pathExists(static::PATH_VERSIONS)) {
if (class_exists(FilesVersionsStorage::class)) {
try {
$versionsFolder = $this->root->get('/'.$uid.'/'.FilesVersionsStorage::VERSIONS_ROOT);
$versionsFolder = $this->root->get('/' . $uid . '/' . FilesVersionsStorage::VERSIONS_ROOT);
} catch (NotFoundException $e) {
$versionsFolder = $this->root->newFolder('/'.$uid.'/'.FilesVersionsStorage::VERSIONS_ROOT);
$versionsFolder = $this->root->newFolder('/' . $uid . '/' . FilesVersionsStorage::VERSIONS_ROOT);
}
$output->writeln('Importing file versions…');
try {
Expand Down
12 changes: 6 additions & 6 deletions lib/Service/UserMigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function __construct(
Coordinator $coordinator,
UserExportMapper $exportMapper,
UserImportMapper $importMapper,
IJobList $jobList
IJobList $jobList,
) {
$this->root = $rootFolder;
$this->config = $config;
Expand Down Expand Up @@ -212,7 +212,7 @@ public function export(IExportDestination $exportDestination, IUser $user, ?arra
];
foreach ($this->getMigrators() as $migrator) {
if ($filteredMigratorList !== null && !in_array($migrator->getId(), $filteredMigratorList)) {
$output->writeln('Skip non-selected migrator: '.$migrator->getId(), OutputInterface::VERBOSITY_VERBOSE);
$output->writeln('Skip non-selected migrator: ' . $migrator->getId(), OutputInterface::VERBOSITY_VERBOSE);
continue;
}
$migrator->export($user, $exportDestination, $output);
Expand All @@ -232,13 +232,13 @@ public function import(IImportSource $importSource, ?IUser $user = null, ?Output

try {
if (!$this->canImport($importSource)) {
throw new UserMigrationException('Version '.($importSource->getMigratorVersion($this->getId()) ?? 'null').' for main class '.static::class.' is not compatible');
throw new UserMigrationException('Version ' . ($importSource->getMigratorVersion($this->getId()) ?? 'null') . ' for main class ' . static::class . ' is not compatible');
}

// Check versions
foreach ($this->getMigrators() as $migrator) {
if (!$migrator->canImport($importSource)) {
throw new UserMigrationException('Version '.($importSource->getMigratorVersion($migrator->getId()) ?? 'null').' for migrator '.get_class($migrator).' is not supported');
throw new UserMigrationException('Version ' . ($importSource->getMigratorVersion($migrator->getId()) ?? 'null') . ' for migrator ' . get_class($migrator) . ' is not supported');
}
}

Expand All @@ -263,7 +263,7 @@ public function import(IImportSource $importSource, ?IUser $user = null, ?Output
protected function exportUserInformation(IUser $user,
IExportDestination $exportDestination,
OutputInterface $output): void {
$output->writeln('Exporting user information in '.IImportSource::PATH_USER.'…');
$output->writeln('Exporting user information in ' . IImportSource::PATH_USER . '…');

// TODO store backend? email? cloud id? quota?
$userinfo = [
Expand All @@ -286,7 +286,7 @@ protected function exportUserInformation(IUser $user,
protected function importUser(?IUser $user,
IImportSource $importSource,
OutputInterface $output): IUser {
$output->writeln('Importing user information from '.IImportSource::PATH_USER.'…');
$output->writeln('Importing user information from ' . IImportSource::PATH_USER . '…');

$data = json_decode($importSource->getFileContents(IImportSource::PATH_USER), true, 512, JSON_THROW_ON_ERROR);

Expand Down
2 changes: 1 addition & 1 deletion lib/Settings/Personal/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Section implements IIconSection {

public function __construct(
IURLGenerator $url,
IL10N $l
IL10N $l,
) {
$this->url = $url;
$this->l = $l;
Expand Down
2 changes: 1 addition & 1 deletion lib/Settings/Personal/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
IInitialState $initialState,
ICacheFactory $memcacheFactory,
IUserSession $userSession,
IL10N $l10n
IL10N $l10n,
) {
$this->serverConfig = $serverConfig;
$this->initialState = $initialState;
Expand Down
Loading