-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+Console Command +Export DataTypeTemplate +Export AllDataTypesTemplate
- Loading branch information
Showing
18 changed files
with
1,516 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
vendor/* | ||
.php-cs-fixer.cache | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace Joy\VoyagerImport\Actions; | ||
|
||
use Joy\VoyagerImport\Imports\DataTypeImport; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Gate; | ||
use Illuminate\Support\Str; | ||
use TCG\Voyager\Actions\AbstractAction; | ||
use TCG\Voyager\Facades\Voyager; | ||
use Maatwebsite\Excel\Excel; | ||
|
||
class ImportAction extends AbstractAction | ||
{ | ||
/** | ||
* Optional File Name | ||
*/ | ||
protected $fileName; | ||
|
||
/** | ||
* Optional Reader Type | ||
*/ | ||
protected $readerType; | ||
|
||
public function getTitle() | ||
{ | ||
return 'Import'; | ||
} | ||
|
||
public function getIcon() | ||
{ | ||
return 'voyager-upload'; | ||
} | ||
|
||
public function getPolicy() | ||
{ | ||
return 'write'; | ||
} | ||
|
||
public function getAttributes() | ||
{ | ||
return [ | ||
'class' => 'btn btn-sm btn-primary', | ||
]; | ||
} | ||
|
||
public function getDefaultRoute() | ||
{ | ||
// return route('my.route'); | ||
} | ||
|
||
public function shouldActionDisplayOnDataType() | ||
{ | ||
return config('joy-voyager-import.enabled', true) !== false | ||
&& isInPatterns( | ||
$this->dataType->slug, | ||
config('joy-voyager-import.allowed_slugs', ['*']) | ||
) | ||
&& !isInPatterns( | ||
$this->dataType->slug, | ||
config('joy-voyager-import.not_allowed_slugs', []) | ||
); | ||
} | ||
|
||
public function massAction($ids, $comingFrom) | ||
{ | ||
// GET THE SLUG, ex. 'posts', 'pages', etc. | ||
$slug = $this->getSlug(request()); | ||
|
||
// GET THE DataType based on the slug | ||
$dataType = Voyager::model('DataType')->where('slug', '=', $slug)->first(); | ||
|
||
// Check permission | ||
Gate::authorize('browse', app($dataType->model_name)); | ||
|
||
$readerType = $this->readerType ?? config('joy-voyager-import.readerType', Excel::XLSX); | ||
$fileName = $this->fileName ?? ($dataType->slug . '.' . Str::lower($readerType)); | ||
|
||
return (new DataTypeImport( | ||
$dataType, | ||
array_filter($ids), | ||
request()->all(), | ||
))->import( | ||
$fileName, | ||
$readerType | ||
); | ||
} | ||
|
||
protected function getSlug(Request $request) | ||
{ | ||
if (isset($this->slug)) { | ||
$slug = $this->slug; | ||
} else { | ||
$slug = explode('.', $request->route()->getName())[1]; | ||
} | ||
|
||
return $slug; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Joy\VoyagerImport\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Storage; | ||
use Illuminate\Support\Str; | ||
use Joy\VoyagerImport\Imports\AllDataTypesImport as ExportsAllDataTypesExport; | ||
use Maatwebsite\Excel\Excel; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
class AllDataTypesImport extends Command | ||
{ | ||
protected $name = 'joy-import:all'; | ||
|
||
protected $description = 'Joy Voyager all DataTypes importer'; | ||
|
||
public function handle() | ||
{ | ||
$this->output->title('Starting import'); | ||
$this->importAllDataTypes( | ||
$this->option('disk'), | ||
$this->option('readerType') | ||
); | ||
$this->output->success('Import successful'); | ||
} | ||
|
||
protected function importAllDataTypes( | ||
string $disk = null, | ||
string $readerType = Excel::XLSX | ||
) { | ||
$path = 'public/imports/' . (($filePath ?? 'import-all') . '-' . date('YmdHis') . '.' . Str::lower($readerType)); | ||
|
||
$url = config('app.url') . Storage::disk($disk)->url($path); | ||
|
||
$this->output->info(sprintf( | ||
'Importing to >>' . PHP_EOL . 'path : %s' . PHP_EOL . 'url : %s', | ||
storage_path($path), | ||
$url | ||
)); | ||
|
||
(new ImportsAllDataTypesImport())->withOutput($this->output)->import( | ||
$path, | ||
$disk, | ||
$readerType | ||
); | ||
} | ||
|
||
/** | ||
* Get the console command options. | ||
* | ||
* @return array | ||
*/ | ||
protected function getOptions() | ||
{ | ||
return [ | ||
[ | ||
'disk', | ||
'd', | ||
InputOption::VALUE_OPTIONAL, | ||
'The disk to where you want to import', | ||
config('joy-voyager-import.disk') | ||
], | ||
[ | ||
'readerType', | ||
'w', | ||
InputOption::VALUE_OPTIONAL, | ||
'The readerType in which format you want to import', | ||
config('joy-voyager-import.readerType', 'Xlsx') | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Joy\VoyagerImport\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Storage; | ||
use Illuminate\Support\Str; | ||
use Joy\VoyagerImport\Exports\AllDataTypesTemplateExport as ExportsAllDataTypesTemplateExport; | ||
use Maatwebsite\Excel\Excel; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
class AllDataTypesTemplateExport extends Command | ||
{ | ||
protected $name = 'joy-import:all-export-templates'; | ||
|
||
protected $description = 'Joy Voyager all DataTypes templates exporter'; | ||
|
||
public function handle() | ||
{ | ||
$this->output->title('Starting export'); | ||
$this->exportAllDataTypes( | ||
$this->option('disk'), | ||
$this->option('writerType') | ||
); | ||
$this->output->success('Export successful'); | ||
} | ||
|
||
protected function exportAllDataTypes( | ||
string $disk = null, | ||
string $writerType = Excel::XLSX | ||
) { | ||
$path = 'public/imports/' . (($filePath ?? 'import-all') . '-' . date('YmdHis') . '.' . Str::lower($writerType)); | ||
|
||
$url = config('app.url') . Storage::disk($disk)->url($path); | ||
|
||
$this->output->info(sprintf( | ||
'Exporting to >>' . PHP_EOL . 'path : %s' . PHP_EOL . 'url : %s', | ||
storage_path($path), | ||
$url | ||
)); | ||
|
||
(new ExportsAllDataTypesTemplateExport())->withOutput($this->output)->store( | ||
$path, | ||
$disk, | ||
$writerType | ||
); | ||
} | ||
|
||
/** | ||
* Get the console command options. | ||
* | ||
* @return array | ||
*/ | ||
protected function getOptions() | ||
{ | ||
return [ | ||
[ | ||
'disk', | ||
'd', | ||
InputOption::VALUE_OPTIONAL, | ||
'The disk to where you want to export', | ||
config('joy-voyager-export.disk') | ||
], | ||
[ | ||
'writerType', | ||
'w', | ||
InputOption::VALUE_OPTIONAL, | ||
'The writerType in which format you want to export', | ||
config('joy-voyager-export.writerType', 'Xlsx') | ||
], | ||
]; | ||
} | ||
} |
Oops, something went wrong.