mirror of
https://github.com/nullthoughts/laravel-data-sync.git
synced 2026-02-27 16:58:20 +00:00
Implements #7
This commit is contained in:
@@ -7,16 +7,19 @@ use Illuminate\Console\Command;
|
|||||||
|
|
||||||
class Sync extends Command
|
class Sync extends Command
|
||||||
{
|
{
|
||||||
protected $signature = 'data:sync {--path=}';
|
protected $signature = 'data:sync {--path=} {--model=}';
|
||||||
|
|
||||||
protected $description = 'Update Models with respective sync data files';
|
protected $description = 'Update Models with respective sync data files';
|
||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$path = $this->option('path');
|
$path = $this->option('path');
|
||||||
|
$model = $this->option('model');
|
||||||
|
|
||||||
$this->info('Updating Models with sync data files');
|
$this->info('Updating Models with sync data files');
|
||||||
(new Updater($path))->run();
|
|
||||||
|
(new Updater($path, $model))->run();
|
||||||
|
|
||||||
$this->comment('Data sync completed');
|
$this->comment('Data sync completed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,10 @@ class Updater
|
|||||||
*
|
*
|
||||||
* @param string|null $path
|
* @param string|null $path
|
||||||
*/
|
*/
|
||||||
public function __construct($path = null)
|
public function __construct($path = null, $model = null)
|
||||||
{
|
{
|
||||||
|
$directory = $this->getDirectory($path);
|
||||||
$this->files = $this->getFiles(
|
$this->files = $this->getFiles($directory, $model);
|
||||||
$this->getDirectory($path)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,8 +82,12 @@ class Updater
|
|||||||
* @param string $directory
|
* @param string $directory
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function getFiles(string $directory)
|
protected function getFiles(string $directory, string $model)
|
||||||
{
|
{
|
||||||
|
if($model) {
|
||||||
|
return $directory . '/' . $model . '.json';
|
||||||
|
}
|
||||||
|
|
||||||
return collect(File::files($directory))->map(function($path) {
|
return collect(File::files($directory))->map(function($path) {
|
||||||
return $path->getPathname();
|
return $path->getPathname();
|
||||||
})->toArray();
|
})->toArray();
|
||||||
|
|||||||
Reference in New Issue
Block a user