Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/agorakit/agorakit
Browse files Browse the repository at this point in the history
  • Loading branch information
philippejadin committed Sep 3, 2021
2 parents e55f4fb + cc7393f commit 232c559
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
45 changes: 17 additions & 28 deletions app/Console/Commands/ExportGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,57 +80,46 @@ public function handle()
Storage::disk('local')->makeDirectory('exports/' . $group->id);
Storage::put('exports/' . $group->id . '/group.json', $group->toJson());

// make a zip file
$this->info('Json export has been put into ' . 'exports/' . $group->id . '/group.json');

/*
// make a zip file of everything
$zip = new ZipArchive;

if ($zip->open(storage_path('app/exports/' .$group->id . '/group.zip'), ZipArchive::CREATE) === TRUE)
{
if ($zip->open(storage_path('app/exports/' . $group->id . '/group.zip'), ZipArchive::CREATE) === TRUE) {
// add json
if ($zip->addFile(storage_path('app/exports/' .$group->id . '/group.json'), 'group.json'))
{
if ($zip->addFile(storage_path('app/exports/' . $group->id . '/group.json'), 'group.json')) {
$this->line('Added group.json dump to archive');
}
else
{
} else {
$this->error('Json dump could not be added to archive');
}

// handle groups files
$files = File::files(storage_path('app/groups/' . $group->id . '/files'));
foreach ($files as $file) {
$relativeNameInZipFile = basename($file);
if ($zip->addFile($file, 'files/' . $relativeNameInZipFile))
{
$this->line('Added ' . $relativeNameInZipFile . ' to group files export');
foreach ($group->files as $file) {
if ($zip->addFile($file->storagePath(), '/files/' . $file->id . '/' . basename($file->path))) {
$this->line('Added ' . $file->path . ' to group files export');
} else {
$this->error('Failed to add ' . $file->path . ' to group files export');
}
}

// handle groups cover
$files = File::files(storage_path('app/groups/' . $group->id));

foreach ($files as $file) {
$relativeNameInZipFile = basename($file);
$zip->addFile($file, $relativeNameInZipFile);
$zip->addFile($file, basename($file));
}

// handle groups users covers
foreach ($group->users as $user)
{
$zip->addFile(storage_path('app/users/' .$user->id . '/cover.jpg'), 'users/' . $user->id . '/cover.jpg');
$zip->addFile(storage_path('app/users/' .$user->id . '/thumbnail.jpg'), 'users/' . $user->id . '/thumbnail.jpg');
foreach ($group->users as $user) {
$zip->addFile(storage_path('app/users/' . $user->id . '/cover.jpg'), 'users/' . $user->id . '/cover.jpg');
$zip->addFile(storage_path('app/users/' . $user->id . '/thumbnail.jpg'), 'users/' . $user->id . '/thumbnail.jpg');
}

$zip->close();

$this->info('Group exported successfuly to ' . storage_path('app/exports/' .$group->id . '/group.zip'));
}
else
{
$this->error('Could not export group');
$this->info('Group exported successfuly to ' . storage_path('app/exports/' . $group->id . '/group.zip'));
} else {
$this->error('Could not create zip file');
}
*/
}
}
8 changes: 8 additions & 0 deletions app/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ public function addToStorage($uploaded_file)
}
}

/**
* Returns the complete storage path to this file
*/
public function storagePath()
{
return storage_path('app/') . $this->path;
}



}

0 comments on commit 232c559

Please sign in to comment.