@@ -31,7 +31,7 @@ class ExportService
31
31
32
32
protected string $ file ;
33
33
34
- protected $ archive ;
34
+ protected \ STS \ ZipStream \ Builder $ archive ;
35
35
36
36
protected bool $ assets = false ;
37
37
@@ -168,9 +168,11 @@ protected function prepare(): self
168
168
File::ensureDirectoryExists ($ saveFolder );
169
169
170
170
// We want the full path for jobs running in the queue.
171
- $ this ->file = $ this ->campaign ->id . '_ ' . date ('Ymd_His ' ) . ($ this ->assets ? '_assets ' : null ) . '.zip ' ;
171
+ $ this ->file =
172
+ Str::slug ($ this ->campaign ->name ) . '_ ' .
173
+ date ('Ymd_His ' ) . '.zip ' ;
172
174
CampaignCache::campaign ($ this ->campaign );
173
- $ this ->path = $ saveFolder . $ this ->file ;
175
+ // $this->path = $saveFolder . $this->file;
174
176
$ this ->archive = Zip::create ($ this ->file );
175
177
176
178
// Count the number of elements to export to get a rough idea of progress
@@ -240,7 +242,7 @@ protected function entities(): self
240
242
'entity ' ,
241
243
'entity.entityTags ' , 'entity.relationships ' ,
242
244
'entity.posts ' , 'entity.posts.postTags ' , 'entity.abilities ' , 'entity.abilities.ability ' ,
243
- 'entity.events ' ,
245
+ 'entity.reminders ' ,
244
246
'entity.image ' ,
245
247
'entity.header ' ,
246
248
'entity.assets ' ,
@@ -263,9 +265,8 @@ protected function entities(): self
263
265
}
264
266
} catch (Exception $ e ) {
265
267
Log::error ('Campaign export ' , ['err ' => $ e ->getMessage ()]);
266
- $ saveFolder = storage_path ($ this ->exportPath );
267
- $ this ->archive ->saveTo ($ saveFolder );
268
- unlink ($ this ->path );
268
+ //$saveFolder = storage_path($this->exportPath);
269
+ //$this->archive->saveTo($saveFolder);
269
270
throw new Exception (
270
271
'Missing campaign entity relation: ' . $ entity . '- ' . $ class . '? '
271
272
. $ e ->getMessage ()
@@ -281,7 +282,7 @@ protected function customEntities(): self
281
282
$ entityWith = [
282
283
'entityTags ' , 'relationships ' ,
283
284
'posts ' , 'posts.postTags ' , 'abilities ' , 'abilities.ability ' ,
284
- 'events ' ,
285
+ 'reminders ' ,
285
286
'image ' ,
286
287
'header ' ,
287
288
'assets ' ,
@@ -311,9 +312,8 @@ protected function customEntities(): self
311
312
}
312
313
} catch (Exception $ e ) {
313
314
Log::error ('Campaign export ' , ['err ' => $ e ->getMessage ()]);
314
- $ saveFolder = storage_path ($ this ->exportPath );
315
- $ this ->archive ->saveTo ($ saveFolder );
316
- unlink ($ this ->path );
315
+ // $saveFolder = storage_path($this->exportPath);
316
+ // $this->archive->saveTo($saveFolder);
317
317
throw new Exception (
318
318
'Missing campaign entity relation: ' . $ entityType ->singular . '? '
319
319
. $ e ->getMessage ()
@@ -343,9 +343,8 @@ protected function gallery(): self
343
343
/** @var Image $image */
344
344
$ this ->processImage ($ image );
345
345
} catch (Exception $ e ) {
346
- $ saveFolder = storage_path ($ this ->exportPath );
347
- $ this ->archive ->saveTo ($ saveFolder );
348
- unlink ($ this ->path );
346
+ // $saveFolder = storage_path($this->exportPath);
347
+ // $this->archive->saveTo($saveFolder);
349
348
throw new Exception (
350
349
$ e ->getMessage ()
351
350
);
@@ -461,31 +460,24 @@ protected function finish(): self
461
460
{
462
461
// Save all the content.
463
462
try {
464
- $ saveFolder = storage_path ($ this ->exportPath );
465
- Log::info ('Campaign export ' , ['path ' => $ saveFolder , 'exportPath ' => $ this ->exportPath ]);
466
- $ this ->archive ->saveTo ($ saveFolder );
467
- $ this ->filesize = (int ) floor (filesize ($ this ->path ) / pow (1024 , 2 ));
463
+ $ path = 'exports/campaigns/ ' . $ this ->campaign ->id . '/ ' ;
464
+ $ this ->exportPath = $ path . $ this ->file ;
465
+ Log::info ('Campaign export finished ' , ['exportPath ' => $ this ->exportPath ]);
466
+ $ this ->archive ->saveToDisk ('s3 ' , $ path );
467
+ Storage::disk ('s3 ' )->setVisibility ($ this ->exportPath , 'public ' );
468
+ $ this ->filesize = (int ) floor ($ this ->archive ->getFinalSize () / pow (1024 , 2 ));
468
469
} catch (Exception $ e ) {
469
470
Log::error ('Campaign export ' , ['action ' => 'finish ' , 'err ' => $ e ->getMessage ()]);
470
471
// The export might fail if the zip is too big.
471
472
$ this ->files = 0 ;
472
473
throw new Exception ($ e ->getMessage ());
473
474
}
474
- if ($ this ->files === 0 ) {
475
- return $ this ;
476
- }
477
-
478
- // Move to ?
479
- $ this ->exportPath = Storage::putFileAs ('exports/campaigns/ ' . $ this ->campaign ->id , $ this ->path , $ this ->file , 'public ' );
480
- unlink ($ this ->path );
481
475
482
476
return $ this ;
483
477
}
484
478
485
479
/**
486
480
* Track that the export had an issue
487
- *
488
- * @return $this
489
481
*/
490
482
public function fail (): self
491
483
{
0 commit comments