Enabled move and queue processing

This commit is contained in:
Deon George
2016-06-29 14:04:02 +10:00
parent 4c317a811c
commit 3361427c75
8 changed files with 201 additions and 92 deletions

View File

@@ -19,6 +19,32 @@ class Photo extends Model
8=>-90,
];
/**
* Photo's NOT pending removal.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeNotRemove($query)
{
return $query->where(function($query) {
$query->where('remove','!=',TRUE)
->orWhere('remove','=',NULL);
});
}
/**
* Photo's NOT duplicate.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeNotDuplicate($query)
{
return $query->where(function($query) {
$query->where('duplicate','!=',TRUE)
->orWhere('duplicate','=',NULL);
});
}
public function date_taken() {
return $this->date_taken ? (date('Y-m-d H:i:s',$this->date_taken).($this->subsectime ? '.'.$this->subsectime : '')) : 'UNKNOWN';
}
@@ -65,7 +91,7 @@ class Photo extends Model
/**
* Calculate the GPS coordinates
*/
public function latlon(array $coordinate,$hemisphere) {
public static function latlon(array $coordinate,$hemisphere) {
if (! $coordinate OR ! $hemisphere)
return NULL;
@@ -89,6 +115,37 @@ class Photo extends Model
return round($sign*($degrees+$minutes/60+$seconds/3600),$degrees > 100 ? 3 : 4);
}
/**
* Determine if a file is moveable
*
* useID boolean Determine if the path is based on the the ID or date
*/
public function moveable() {
// If the source and target are the same, we dont need to move it
if ($this->file_path() == $this->file_path(FALSE,TRUE))
return FALSE;
// If there is already a file in the target.
// @todo If the target file is to be deleted, we could move this file
if (file_exists($this->file_path(FALSE,TRUE)))
return 1;
// Test if the source is readable
if (! is_readable($this->file_path()))
return 2;
// Test if the dir is writable (so we can remove the file)
if (! is_writable(dirname($this->file_path())))
return 3;
// Test if the target dir is writable
// @todo The target dir may not exist yet, so we should check that a parent exists and is writable.
if (! is_writable(dirname($this->file_path(FALSE,TRUE))))
return 4;
return TRUE;
}
/**
* Rotate the image
*
@@ -101,6 +158,10 @@ class Photo extends Model
return $imo->getImageBlob();
}
public static function path($path) {
return preg_replace('/^\//','',str_replace(config('photo.dir'),'',$path));
}
/**
* Determine if the image should be moved
*/