Skip to content

Commit

Permalink
Merge pull request #4348 from LibreSign/backport/4346/stable30
Browse files Browse the repository at this point in the history
[stable30] chore: move backup file to appdata
  • Loading branch information
vitormattos authored Jan 16, 2025
2 parents f84b799 + c85f9b6 commit afd353a
Showing 1 changed file with 12 additions and 4 deletions.
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

0 comments on commit afd353a

Please sign in to comment.