From 506a109964169920e50f89ba332eda387b282f13 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Thu, 16 Jan 2025 06:28:43 -0300 Subject: [PATCH] chore: move backup file to appdata Signed-off-by: Vitor Mattos --- lib/Migration/Version11000Date20250114182030.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Migration/Version11000Date20250114182030.php b/lib/Migration/Version11000Date20250114182030.php index 4e1728167..22674c99c 100644 --- a/lib/Migration/Version11000Date20250114182030.php +++ b/lib/Migration/Version11000Date20250114182030.php @@ -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'); } /** @@ -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)); @@ -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