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 backup file to appdata #4346

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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
16 changes: 12 additions & 4 deletions lib/Migration/Version11000Date20250114182030.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\IAppData;
use OCP\IDBConnection;
use OCP\ITempManager;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version11000Date20250114182030 extends SimpleMigrationStep {
protected IAppData $appData;
public function __construct(
private IDBConnection $connection,
private ITempManager $tempManager,
private IAppDataFactory $appDataFactory,
) {
$this->appData = $appDataFactory->get('libresign');
}

/**
Expand All @@ -47,9 +50,10 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
->orderBy('lim.id');
$result = $qb1->executeQuery();
$identifyMethods = [];
$backup = $this->tempManager->getTemporaryFile('.csv');
$folder = $this->appData->getFolder('/');
$file = $folder->newFile('backup-table-libresign_identify_method.csv');
$maxId = 0;
$fp = fopen($backup, 'w');
$fp = $file->write();
$row = $result->fetch();
$identifyMethods[] = $row;
fputcsv($fp, array_keys($row));
Expand All @@ -65,6 +69,10 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
}
fclose($fp);
$result->closeCursor();
if ($maxId === 0) {
$file->delete();
return;
}
// BACKUP END

// Delete bad rows
Expand Down
Loading