Updated VideoMove
This commit is contained in:
parent
4adf66c318
commit
99ca07201e
@ -3,13 +3,9 @@
|
|||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
||||||
|
|
||||||
class CatalogDump extends Command
|
class CatalogDump extends Command
|
||||||
{
|
{
|
||||||
// Our photo object
|
|
||||||
private $o = NULL;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
*
|
||||||
|
53
app/Console/Commands/CatalogMove.php
Normal file
53
app/Console/Commands/CatalogMove.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||||
|
|
||||||
|
use App\Jobs\VideoMove;
|
||||||
|
|
||||||
|
class CatalogMove extends Command
|
||||||
|
{
|
||||||
|
use DispatchesJobs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'catalog:move {type : Photo | Video }';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Trigger Moves';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$class = 'App\Models\\'.$this->argument('type');
|
||||||
|
|
||||||
|
if (! class_exists($class))
|
||||||
|
abort(500,sprintf('No class [%s]',$this->argument('type')));
|
||||||
|
|
||||||
|
foreach ($class::where('filename','LIKE','%INCOMING%')->get() as $o) {
|
||||||
|
if ($o->scanned AND ! $o->duplicate AND ! $o->remove AND ($x=$o->moveable()) === TRUE) {
|
||||||
|
$this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (strtolower($this->argument('type'))) {
|
||||||
|
case 'video':
|
||||||
|
$this->dispatch((new VideoMove($o))->onQueue('move'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,39 +12,39 @@ class PhotoMove extends Command
|
|||||||
{
|
{
|
||||||
use Files;
|
use Files;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'photo:move
|
protected $signature = 'photo:move
|
||||||
{--file= : Photo File}
|
{--file= : Photo File}
|
||||||
{--id= : Photo ID}';
|
{--id= : Photo ID}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Moves Photos to their new location';
|
protected $description = 'Moves Photos to their new location';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
if ($this->option('file')) {
|
if ($this->option('file')) {
|
||||||
$po = Photo::notRemove()->notDuplicate()->where('filename',Photo::path($this->option('file')));
|
$po = Photo::notRemove()->notDuplicate()->where('filename',Photo::path($this->option('file')));
|
||||||
|
|
||||||
@ -88,11 +88,11 @@ class PhotoMove extends Command
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ($x > 0)
|
if ($x > 0)
|
||||||
$this->warn(sprintf('Unable to move (%s) [%s] to [%s], moveable returned (%s)',$o->id,$o->file_path(),$o->file_path(FALSE,TRUE),$x));
|
$this->warn(sprintf('Unable to move (%s) [%s] to [%s], movable returned (%s)',$o->id,$o->file_path(),$o->file_path(FALSE,TRUE),$x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$bar->advance();
|
$bar->advance();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,115 +2,101 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use DB;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Log;
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use App\Model\Video;
|
|
||||||
|
use App\Traits\Files;
|
||||||
|
use App\Models\Video;
|
||||||
|
|
||||||
class VideoMove extends Command
|
class VideoMove extends Command
|
||||||
{
|
{
|
||||||
use \App\Traits\Files;
|
use Files;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'video:move
|
protected $signature = 'video:move
|
||||||
{--file= : Video File}
|
{--file= : Video File}
|
||||||
{--id= : Video ID}';
|
{--id= : Video ID}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Moves Videos to their new location';
|
protected $description = 'Moves Videos to their new location';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
if ($this->option('file'))
|
|
||||||
{
|
{
|
||||||
$vo = Video::notRemove()->notDuplicate()->where('filename',Video::path($this->option('file')));
|
parent::__construct();
|
||||||
}
|
|
||||||
elseif ($this->option('id'))
|
|
||||||
{
|
|
||||||
$vo = Video::notRemove()->notDuplicate()->where('id',$this->option('id'));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$vo = Video::notRemove()->notDuplicate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $vo)
|
/**
|
||||||
exit;
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
if ($this->option('file')) {
|
||||||
|
$vo = Video::notRemove()->notDuplicate()->where('filename',Video::path($this->option('file')));
|
||||||
|
|
||||||
// Show a progress bar
|
} elseif ($this->option('id')) {
|
||||||
$bar = $this->output->createProgressBar($vo->count());
|
$vo = Video::notRemove()->notDuplicate()->where('id',$this->option('id'));
|
||||||
$bar->setFormat("%current%/%max% [%bar%] %percent:3s%% (%memory%) (%remaining%) ");
|
|
||||||
$bar->setRedrawFrequency(100);
|
|
||||||
|
|
||||||
$vo->chunk(1,function($video) use ($bar) {
|
} else {
|
||||||
while ($o = $video->shift())
|
$vo = Video::notRemove()->notDuplicate();
|
||||||
{
|
|
||||||
if (($x = $o->moveable()) === TRUE) {
|
|
||||||
Log::info(sprintf('%s: Moving (%s)[%s]',__METHOD__,$o->id,$o->filename));
|
|
||||||
|
|
||||||
$fs = $o->file_size();
|
|
||||||
$ft = $o->file_date('m');
|
|
||||||
if ($this->makeParentDir(dirname($o->file_path(FALSE,TRUE))) AND copy($o->file_path(),$o->file_path(FALSE,TRUE)))
|
|
||||||
{
|
|
||||||
// If the copy worked, remove the original.
|
|
||||||
if (file_exists($o->file_path(FALSE,TRUE)) AND $fs === filesize($o->file_path(FALSE,TRUE)))
|
|
||||||
{
|
|
||||||
touch($o->file_path(FALSE,TRUE),$ft);
|
|
||||||
unlink($o->file_path());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert the path to a relative one.
|
|
||||||
$o->filename = $o->file_path(TRUE,TRUE);
|
|
||||||
|
|
||||||
// @todo If the DB update failed, move it back.
|
|
||||||
if (! $o->save()) # AND ! rename($path,$o->file_path()))
|
|
||||||
{
|
|
||||||
$this->error(sprintf('Save after rename failed for (%s)',$o->id));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->error(sprintf('Rename failed for (%s)',$o->id));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
chmod($o->file_path(),0444);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($x > 0) {
|
|
||||||
$this->warn(sprintf('Unable to move (%s) [%s] to [%s], moveable returned (%s)',$o->id,$o->file_path(),$o->file_path(FALSE,TRUE),$x));
|
|
||||||
if ($x == 1 AND $v = Video::where('filename',$o->file_path(TRUE,TRUE))->first())
|
|
||||||
$this->warn(sprintf('File is id (%s) [%s]',$v->file_path(),$v->id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$bar->advance();
|
if (! $vo)
|
||||||
});
|
exit;
|
||||||
}
|
|
||||||
|
// Show a progress bar
|
||||||
|
$bar = $this->output->createProgressBar($vo->count());
|
||||||
|
$bar->setFormat("%current%/%max% [%bar%] %percent:3s%% (%memory%) (%remaining%) ");
|
||||||
|
$bar->setRedrawFrequency(100);
|
||||||
|
|
||||||
|
$vo->chunk(1,function($video) use ($bar) {
|
||||||
|
while ($o = $video->shift()) {
|
||||||
|
if (($x = $o->moveable()) === TRUE) {
|
||||||
|
Log::info(sprintf('%s: Moving (%s)[%s]',__METHOD__,$o->id,$o->filename));
|
||||||
|
|
||||||
|
if ($this->makeParentDir(dirname($o->file_path(FALSE,TRUE))) AND rename($o->file_path(),$o->file_path(FALSE,TRUE))) {
|
||||||
|
// Convert the path to a relative one.
|
||||||
|
$o->filename = $o->file_path(TRUE,TRUE);
|
||||||
|
|
||||||
|
// @todo If the DB update failed, move it back.
|
||||||
|
if (! $o->save()) # AND ! rename($path,$o->file_path()))
|
||||||
|
{
|
||||||
|
$this->error(sprintf('Save after rename failed for (%s)',$o->id));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->error(sprintf('Rename failed for (%s)',$o->id));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
chmod($o->file_path(),0444);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if ($x > 0) {
|
||||||
|
$this->warn(sprintf('Unable to move (%s) [%s] to [%s], movable returned (%s)',$o->id,$o->file_path(),$o->file_path(FALSE,TRUE),$x));
|
||||||
|
|
||||||
|
if ($x == 1 AND $v = Video::where('filename',$o->file_path(TRUE,TRUE))->first())
|
||||||
|
$this->warn(sprintf('File is id (%s) [%s]',$v->file_path(),$v->id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$bar->advance();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user