General improvements

This commit is contained in:
Deon George 2015-06-04 14:25:58 +10:00
parent 9359564ea8
commit c88d289e82
4 changed files with 40 additions and 13 deletions

View File

@ -19,21 +19,22 @@ class Controller_Photo extends Controller_TemplateDefault {
// Update the current posted photos.
if ($this->request->post())
foreach ($this->request->post('process') as $pid) {
if (! Arr::get($this->request->post('remove'),$pid,FALSE))
continue;
$po = ORM::factory('Photo',$pid);
$po->remove = Arr::get($this->request->post('remove'),$pid);
$po->save();
// If the photo is not marked as remove, or flagged, dont do it.
if (! $po->loaded() OR $po->flag OR ! $po->remove)
continue;
if (! is_writable(dirname($po->file_path())))
$output .= sprintf('Dont have write permissions on %s',dirname($po->file_path()));
$output .= sprintf('Removing %s (%s)',$po->id,$po->file_path());
// Delete it
if (unlink($po->file_path()))
$po->delete();
}
$p = ORM::factory('Photo');
@ -68,7 +69,7 @@ class Controller_Photo extends Controller_TemplateDefault {
'File Modified'=>array('key'=>'date_file("m",TRUE)'),
'File Created'=>array('key'=>'date_file("c",TRUE)'),
'Filename'=>array('key'=>'file_path(TRUE,FALSE)'),
'Proposed Name'=>array('key'=>'path()'),
'Filesize'=>array('key'=>'file_size()'),
'Width'=>array('key'=>'width'),
'Height'=>array('key'=>'height'),
'Orientation'=>array('key'=>'orientation'),
@ -125,7 +126,11 @@ class Controller_Photo extends Controller_TemplateDefault {
$po->remove = Arr::get($this->request->post('remove'),$pid);
$po->flag = Arr::get($this->request->post('flag'),$pid);
if ($po->changed())
$output .= HTML::anchor(URL::link('','photo/duplicate/'.$po->id),$po->id).' updated.<br/>';
$po->save();
}
$p = ORM::factory('Photo');
@ -167,7 +172,7 @@ class Controller_Photo extends Controller_TemplateDefault {
'File Modified'=>array('key'=>'date_file("m",TRUE)'),
'File Created'=>array('key'=>'date_file("c",TRUE)'),
'Filename'=>array('key'=>'file_path(TRUE,FALSE)'),
'Proposed Name'=>array('key'=>'file_path(TRUE,TRUE)'),
'Filesize'=>array('key'=>'file_size()'),
'Width'=>array('key'=>'width'),
'Height'=>array('key'=>'height'),
'Orientation'=>array('key'=>'orientation'),

View File

@ -51,11 +51,24 @@ class Model_Photo extends ORM {
}
public function file_path($short=FALSE,$new=FALSE) {
$file = $new ? sprintf('%s_%03s.%s',date('Y/m/d-His',$this->date_taken),$this->subsectime,$this->type()) : $this->filename;
$file = $this->filename;
if ($new)
$file = sprintf('%s.%s',((is_null($this->date_taken) OR ! $this->date_taken)
? sprintf('UNKNOWN/%07s',$this->file_path_id())
: sprintf('%s_%03s',date('Y/m/d-His',$this->date_taken),$this->subsectime).($this->subsectime ? '' : sprintf('-%05s',$this->id))),$this->type());
return (($short OR preg_match('/^\//',$file)) ? '' : $this->_path.DIRECTORY_SEPARATOR).$file;
}
public function file_path_id($sep=3,$depth=9) {
return trim(chunk_split(sprintf("%0{$depth}s",$this->id),$sep,'/'),'/');
}
public function file_size() {
return filesize($this->file_path());
}
public function gps(array $coordinate,$hemisphere) {
if (! $coordinate OR ! $hemisphere)
return NULL;
@ -99,7 +112,7 @@ class Model_Photo extends ORM {
public function io($attr=NULL) {
if (is_nulL($this->_io))
$this->_io = new Imagick($this->_path.DIRECTORY_SEPARATOR.$this->filename);
$this->_io = new Imagick($this->file_path());
return is_null($attr) ? $this->_io : $this->_io->getImageProperty($attr);
}
@ -114,13 +127,16 @@ class Model_Photo extends ORM {
if ($po->loaded() OR file_exists($path) OR ! File::ParentDirExist(dirname($path),TRUE))
return FALSE;
if (rename($this->file_path(FALSE,FALSE),$path)) {
if (rename($this->file_path(),$path)) {
// Convert the path to a relative one.
$this->filename = preg_replace(":^{$this->_path}/:",'',$path);
// If the DB update failed, move it back.
if (! $this->save() AND ! rename($path,$this->file_path()))
throw new Kohana_Exception('Error: Unable to move file, ID: :id, OLD: :oldname, NEW: :newname',
array(':id'=>$this->id,':oldname'=>$this->file_path(),':newname'=>$this->file_path()));
array(':id'=>$this->id,':oldname'=>$this->file_path(),':newname'=>$path));
chmod($this->file_path(),0444);
return TRUE;
}

View File

@ -1,7 +1,7 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Mark all accounts that have no outstanding invoices and active services as disabled.
* Import photo to the database
*
* @package Photo
* @category Tasks
@ -10,6 +10,10 @@
* @license http://dev.leenooks.net/license.html
*/
class Task_Photo_Import extends Minion_Task {
private $_accepted = array(
'jpg',
);
protected $_options = array(
'file'=>NULL, // Photo File to Import
'verbose'=>FALSE, // Photo File to Import
@ -22,10 +26,13 @@ class Task_Photo_Import extends Minion_Task {
if (preg_match('/@__thumb/',$params['file']) OR preg_match('/\/._/',$params['file']))
return sprintf("Ignoring file [%s]\n",$params['file']);
if (! in_array(strtolower(pathinfo($params['file'],PATHINFO_EXTENSION)),$this->_accepted))
return sprintf("Ignoring file [%s]\n",$params['file']);
$po = ORM::factory('Photo',array('filename'=>$params['file']));
if (! $po->loaded())
$po->filename = $params['file'];
$po->filename = realpath($params['file']);
$po->date_taken = $this->dbcol(strtotime($po->io('exif:DateTime')));
$po->signature = $this->dbcol($po->io()->getImageSignature());

View File

@ -21,7 +21,6 @@ class Task_Photo_Move extends Minion_Task {
} else {
$p = ORM::factory('Photo')
->where('date_taken','is not',NULL)
->where_open()
->where('remove','!=',TRUE)
->or_where('remove','is',NULL)