option('file')) { $vo = Video::notRemove()->notDuplicate()->where('filename',Video::path($this->option('file'))); } elseif ($this->option('id')) { $vo = Video::notRemove()->notDuplicate()->where('id',$this->option('id')); } else { $vo = Video::notRemove()->notDuplicate(); } 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)); $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(); }); } }