Skip to content

Commit

Permalink
fix: Remove coding-standard from main composer.json and update the on…
Browse files Browse the repository at this point in the history
…e in bin folder instead

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Feb 10, 2025
1 parent 34cd7da commit 81ca110
Show file tree
Hide file tree
Showing 59 changed files with 611 additions and 1,087 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"psalm:fix": "- --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
"nextcloud/coding-standard": "^1.1"
"bamarni/composer-bin-plugin": "^1.8"
},
"extra": {
"bamarni-bin": {
Expand Down
150 changes: 5 additions & 145 deletions composer.lock

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

54 changes: 27 additions & 27 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ private function getAppDirectories(): array {
throw new \Exception('Invalid configuration in apps_paths configuration key');
}
$appDir = basename($appsPath['path']);
if (strpos($appsPath['path'], $this->nextcloudDir.'/') === 0) {
$relativePath = substr($appsPath['path'], strlen($this->nextcloudDir.'/'));
if (strpos($appsPath['path'], $this->nextcloudDir . '/') === 0) {
$relativePath = substr($appsPath['path'], strlen($this->nextcloudDir . '/'));
if ($relativePath !== 'apps') {
$expected[] = $relativePath;
}
Expand All @@ -305,7 +305,7 @@ private function getRecursiveDirectoryIterator(string $folder, array $excludedPa
$handle = opendir($folder);

if ($handle === false) {
throw new \Exception('Could not open '.$folder);
throw new \Exception('Could not open ' . $folder);
}

/* Store first level children in an array to avoid trouble if changes happen while iterating */
Expand All @@ -323,7 +323,7 @@ private function getRecursiveDirectoryIterator(string $folder, array $excludedPa
closedir($handle);

foreach ($children as $name) {
$path = $folder.'/'.$name;
$path = $folder . '/' . $name;
if (is_dir($path)) {
yield from $this->getRecursiveDirectoryIterator($path, []);
}
Expand Down Expand Up @@ -382,7 +382,7 @@ public function checkWritePermissions(): void {
* @throws \Exception when config.php can't be written
*/
public function setMaintenanceMode(bool $state): void {
$this->silentLog('[info] setMaintenanceMode("' . ($state ? 'true' : 'false') . '")');
$this->silentLog('[info] setMaintenanceMode("' . ($state ? 'true' : 'false') . '")');

if ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) {
$configFileName = rtrim($dir, '/') . '/config.php';
Expand Down Expand Up @@ -424,7 +424,7 @@ public function createBackup(): void {
];

// Create new folder for the backup
$backupFolderLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid').'/backups/nextcloud-'.$this->getConfigOptionMandatoryString('version') . '-' . time() . '/';
$backupFolderLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/backups/nextcloud-' . $this->getConfigOptionMandatoryString('version') . '-' . time() . '/';
$this->silentLog('[info] backup folder location: ' . $backupFolderLocation);

$state = mkdir($backupFolderLocation, 0750, true);
Expand All @@ -440,7 +440,7 @@ public function createBackup(): void {
if (!file_exists($backupFolderLocation . '/' . $relativeDirectory)) {
$state = mkdir($backupFolderLocation . '/' . $relativeDirectory, 0750, true);
if ($state === false) {
throw new \Exception('Could not create folder: '.$backupFolderLocation.'/'.$relativeDirectory);
throw new \Exception('Could not create folder: ' . $backupFolderLocation . '/' . $relativeDirectory);
}
}

Expand Down Expand Up @@ -501,7 +501,7 @@ private function getUpdateServerResponse(): array {
$this->silentLog('[info] releaseChannel: ' . $releaseChannel);
$this->silentLog('[info] internal version: ' . $this->getConfigOptionMandatoryString('version'));

$updateURL = $updaterServer . '?version='. str_replace('.', 'x', $this->getConfigOptionMandatoryString('version')) .'xxx'.$releaseChannel.'xx'.urlencode($this->buildTime).'x'.PHP_MAJOR_VERSION.'x'.PHP_MINOR_VERSION.'x'.PHP_RELEASE_VERSION;
$updateURL = $updaterServer . '?version=' . str_replace('.', 'x', $this->getConfigOptionMandatoryString('version')) . 'xxx' . $releaseChannel . 'xx' . urlencode($this->buildTime) . 'x' . PHP_MAJOR_VERSION . 'x' . PHP_MINOR_VERSION . 'x' . PHP_RELEASE_VERSION;
$this->silentLog('[info] updateURL: ' . $updateURL);

// Download update response
Expand All @@ -523,7 +523,7 @@ private function getUpdateServerResponse(): array {
/** @var false|string $response */
$response = curl_exec($curl);
if ($response === false) {
throw new \Exception('Could not do request to updater server: '.curl_error($curl));
throw new \Exception('Could not do request to updater server: ' . curl_error($curl));
}
curl_close($curl);

Expand Down Expand Up @@ -551,7 +551,7 @@ public function downloadUpdate(): void {

$response = $this->getUpdateServerResponse();

$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
if (file_exists($storageLocation)) {
$this->silentLog('[info] storage location exists');
$this->recursiveDelete($storageLocation);
Expand Down Expand Up @@ -622,7 +622,7 @@ public function downloadUpdate(): void {
* @throws \Exception
*/
private function getDownloadedFilePath(): string {
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/';
$this->silentLog('[info] storage location: ' . $storageLocation);

$filesInStorageLocation = scandir($storageLocation);
Expand Down Expand Up @@ -732,23 +732,23 @@ public function extractDownload(): void {
throw new \Exception('Required PHP extension missing: zip');
}

$libzip_version = defined("ZipArchive::LIBZIP_VERSION") ? \ZipArchive::LIBZIP_VERSION : "Unknown (but old)";
$libzip_version = defined('ZipArchive::LIBZIP_VERSION') ? \ZipArchive::LIBZIP_VERSION : 'Unknown (but old)';
$this->silentLog('[info] Libzip version detected: ' . $libzip_version);

$zip = new \ZipArchive;
$zipState = $zip->open($downloadedFilePath);
if ($zipState === true) {
$extraction = $zip->extractTo(dirname($downloadedFilePath));
if ($extraction === false) {
throw new \Exception('Error during unpacking zipfile: '.($zip->getStatusString()));
throw new \Exception('Error during unpacking zipfile: ' . ($zip->getStatusString()));
}
$zip->close();
$state = unlink($downloadedFilePath);
if ($state === false) {
throw new \Exception("Can't unlink ". $downloadedFilePath);
throw new \Exception("Can't unlink " . $downloadedFilePath);
}
} else {
throw new \Exception("Can't handle ZIP file. Error code is: ".print_r($zipState, true));
throw new \Exception("Can't handle ZIP file. Error code is: " . print_r($zipState, true));
}

// Ensure that the downloaded version is not lower
Expand Down Expand Up @@ -790,7 +790,7 @@ public function replaceEntryPoints(): void {
}
$state = file_put_contents($this->nextcloudDir . '/' . $file, $content);
if ($state === false) {
throw new \Exception('Can\'t replace entry point: '.$file);
throw new \Exception('Can\'t replace entry point: ' . $file);
}
}

Expand Down Expand Up @@ -846,7 +846,7 @@ public function deleteOldFiles(): void {
throw new \Exception('core/shipped.json content is invalid');
}

$newShippedAppsFile = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/nextcloud/core/shipped.json';
$newShippedAppsFile = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/nextcloud/core/shipped.json';
$newShippedAppsFileContent = file_get_contents($newShippedAppsFile);
if ($newShippedAppsFileContent === false) {
throw new \Exception('core/shipped.json is not available in the new release');
Expand Down Expand Up @@ -906,12 +906,12 @@ public function deleteOldFiles(): void {
if ($fileInfo->isFile() || $fileInfo->isLink()) {
$state = unlink($path);
if ($state === false) {
throw new \Exception('Could not unlink: '.$path);
throw new \Exception('Could not unlink: ' . $path);
}
} elseif ($fileInfo->isDir()) {
$state = rmdir($path);
if ($state === false) {
throw new \Exception('Could not rmdir: '.$path);
throw new \Exception('Could not rmdir: ' . $path);
}
}
}
Expand Down Expand Up @@ -973,7 +973,7 @@ public function moveNewVersionInPlace(): void {
'public.php',
'ocs',
];
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/nextcloud/';
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/nextcloud/';
$this->silentLog('[info] storage location: ' . $storageLocation);

// Rename apps and other stuff
Expand All @@ -993,15 +993,15 @@ public function moveNewVersionInPlace(): void {
public function finalize(): void {
$this->silentLog('[info] finalize()');

$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/nextcloud/';
$storageLocation = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/downloads/nextcloud/';
$this->silentLog('[info] storage location: ' . $storageLocation);
$this->moveWithExclusions($storageLocation, []);
$state = rmdir($storageLocation);
if ($state === false) {
throw new \Exception('Could not rmdir $storagelocation');
}

$state = unlink($this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/.step');
$state = unlink($this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid') . '/.step');
if ($state === false) {
throw new \Exception('Could not rmdir .step');
}
Expand All @@ -1018,7 +1018,7 @@ public function finalize(): void {
* @throws \Exception
*/
private function writeStep(string $state, int $step): void {
$updaterDir = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid');
$updaterDir = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid');
if (!file_exists($updaterDir . '/.step')) {
if (!file_exists($updaterDir)) {
$result = mkdir($updaterDir);
Expand Down Expand Up @@ -1060,8 +1060,8 @@ public function endStep(int $step): void {
public function currentStep(): array {
$this->silentLog('[info] currentStep()');

$updaterDir = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid');
if (!file_exists($updaterDir. '/.step')) {
$updaterDir = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid');
if (!file_exists($updaterDir . '/.step')) {
return [];
}

Expand All @@ -1079,7 +1079,7 @@ public function currentStep(): array {
}

public function getUpdateStepFileLocation(): string {
$updaterDir = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid');
$updaterDir = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOption('instanceid');
return $updaterDir . '/.step';
}

Expand All @@ -1091,7 +1091,7 @@ public function getUpdateStepFileLocation(): string {
public function rollbackChanges(int $step): void {
$this->silentLog('[info] rollbackChanges("' . $step . '")');

$updaterDir = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid');
$updaterDir = $this->getUpdateDirectoryLocation() . '/updater-' . $this->getConfigOptionMandatoryString('instanceid');
if (file_exists($updaterDir . '/.step')) {
$this->silentLog('[info] unlink .step');
$state = unlink($updaterDir . '/.step');
Expand Down
Loading

0 comments on commit 81ca110

Please sign in to comment.