Added Files Trait, added createParentDirs
This commit is contained in:
@@ -12,6 +12,8 @@ use App\Model\Tag;
|
||||
|
||||
class Import extends Command
|
||||
{
|
||||
use \App\Traits\Files;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
@@ -49,39 +51,9 @@ class Import extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// Make sure we got a directory or a file to import
|
||||
if (is_null($this->option('file')) AND is_null($this->option('dir')))
|
||||
abort(500,'Missing filename, please use --file= OR --dir=');
|
||||
|
||||
Log::info(sprintf('%s: Processing: %s',__METHOD__,($this->option('file') ? $this->option('file') : $this->option('dir'))));
|
||||
|
||||
$files = [];
|
||||
|
||||
if ($this->option('dir'))
|
||||
{
|
||||
// Remove our trailing slash from the directory.
|
||||
$dir = preg_replace('/\/$/','',$this->option('dir'));
|
||||
|
||||
// Exclude . & .. from the path.
|
||||
$files = array_diff(scandir($dir),array('.','..'));
|
||||
|
||||
}
|
||||
elseif ($this->option('file'))
|
||||
{
|
||||
$dir = dirname($this->option('file'));
|
||||
$files = array(basename($this->option('file')));
|
||||
}
|
||||
|
||||
// Determine if our dir is releative to where we store data
|
||||
$dir = Photo::path($dir);
|
||||
|
||||
// Add our path
|
||||
if ($dir)
|
||||
array_walk($files,function(&$value,$key,$path='') {
|
||||
if ($path) {
|
||||
$value = sprintf('%s/%s',$path,$value);
|
||||
}
|
||||
},$dir);
|
||||
$files = $this->getFiles(['dir'=>$this->option('dir'),'file'=>$this->option('file')]);
|
||||
if (! count($files))
|
||||
exit;
|
||||
|
||||
// Show a progress bar
|
||||
$bar = $this->output->createProgressBar(count($files));
|
||||
|
@@ -9,6 +9,8 @@ use App\Model\Photo;
|
||||
|
||||
class Move extends Command
|
||||
{
|
||||
use \App\Traits\Files;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
@@ -55,6 +57,9 @@ class Move extends Command
|
||||
$po = Photo::notRemove()->notDuplicate();
|
||||
}
|
||||
|
||||
if (! $po)
|
||||
exit;
|
||||
|
||||
// Show a progress bar
|
||||
$bar = $this->output->createProgressBar($po->count());
|
||||
$bar->setFormat("%current%/%max% [%bar%] %percent:3s%% (%memory%) (%remaining%) ");
|
||||
@@ -66,7 +71,7 @@ class Move extends Command
|
||||
if (($x = $po->moveable()) === TRUE) {
|
||||
Log::info(sprintf('%s: Moving (%s)[%s]',__METHOD__,$po->id,$po->filename));
|
||||
|
||||
if (rename($po->file_path(),$po->file_path(FALSE,TRUE)))
|
||||
if ($this->makeParentDir(dirname($po->file_path(FALSE,TRUE))) AND rename($po->file_path(),$po->file_path(FALSE,TRUE)))
|
||||
{
|
||||
// Convert the path to a relative one.
|
||||
$po->filename = $po->file_path(TRUE,TRUE);
|
||||
|
@@ -8,6 +8,8 @@ use App\Model\Photo;
|
||||
|
||||
class Update extends Command
|
||||
{
|
||||
use \App\Traits\Files;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
@@ -41,39 +43,9 @@ class Update extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// Make sure we got a directory or a file to import
|
||||
if (is_null($this->option('file')) AND is_null($this->option('dir')))
|
||||
abort(500,'Missing filename, please use --file= OR --dir=');
|
||||
|
||||
Log::info(sprintf('%s: Processing: %s',__METHOD__,($this->option('file') ? $this->option('file') : $this->option('dir'))));
|
||||
|
||||
$files = [];
|
||||
|
||||
if ($this->option('dir'))
|
||||
{
|
||||
// Remove our trailing slash from the directory.
|
||||
$dir = preg_replace('/\/$/','',$this->option('dir'));
|
||||
|
||||
// Exclude . & .. from the path.
|
||||
$files = array_diff(scandir($dir),array('.','..'));
|
||||
|
||||
}
|
||||
elseif ($this->option('file'))
|
||||
{
|
||||
$dir = dirname($this->option('file'));
|
||||
$files = array(basename($this->option('file')));
|
||||
}
|
||||
|
||||
// Determine if our dir is releative to where we store data
|
||||
$dir = Photo::path($dir);
|
||||
|
||||
// Add our path
|
||||
if ($dir)
|
||||
array_walk($files,function(&$value,$key,$path='') {
|
||||
if ($path) {
|
||||
$value = sprintf('%s/%s',$path,$value);
|
||||
}
|
||||
},$dir);
|
||||
$files = $this->getFiles(['dir'=>$this->option('dir'),'file'=>$this->option('file')]);
|
||||
if (! count($files))
|
||||
exit;
|
||||
|
||||
// Show a progress bar
|
||||
$bar = $this->output->createProgressBar(count($files));
|
||||
|
Reference in New Issue
Block a user