photo/application/classes/Task/Photo/Import.php

84 lines
2.6 KiB
PHP
Raw Normal View History

2014-07-09 03:04:56 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
2015-06-04 04:25:58 +00:00
* Import photo to the database
2014-07-09 03:04:56 +00:00
*
* @package Photo
* @category Tasks
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Task_Photo_Import extends Minion_Task {
2015-06-04 04:25:58 +00:00
private $_accepted = array(
'jpg',
);
2014-07-09 03:04:56 +00:00
protected $_options = array(
'file'=>NULL, // Photo File to Import
'verbose'=>FALSE, // Photo File to Import
);
protected function _execute(array $params) {
if (is_null($params['file']))
throw new Kohana_Exception('Missing filename, please use --file=');
if (preg_match('/@__thumb/',$params['file']) OR preg_match('/\/._/',$params['file']))
return sprintf("Ignoring file [%s]\n",$params['file']);
2015-06-04 04:25:58 +00:00
if (! in_array(strtolower(pathinfo($params['file'],PATHINFO_EXTENSION)),$this->_accepted))
return sprintf("Ignoring file [%s]\n",$params['file']);
2014-07-09 03:04:56 +00:00
$po = ORM::factory('Photo',array('filename'=>$params['file']));
if (! $po->loaded())
2015-06-04 04:25:58 +00:00
$po->filename = realpath($params['file']);
2014-07-09 03:04:56 +00:00
$po->date_taken = $this->dbcol(strtotime($po->io('exif:DateTime')));
$po->signature = $this->dbcol($po->io()->getImageSignature());
$po->make = $this->dbcol($po->io('exif:Make'));
$po->model = $this->dbcol($po->io('exif:Model'));
$po->height = $this->dbcol($po->io()->getImageheight());
$po->width = $this->dbcol($po->io()->getImageWidth());
$po->orientation = $this->dbcol($po->io()->getImageOrientation());
$po->subsectime = $this->dbcol($po->io('exif:SubSecTimeOriginal'));
$po->gps_lat = $this->dbcol($po->gps(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLatitude')),$po->io()->getImageProperty('exif:GPSLatitudeRef')));
$po->gps_lon = $this->dbcol($po->gps(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLongitude')),$po->io()->getImageProperty('exif:GPSLongitudeRef')));
try {
$po->thumbnail = $this->dbcol(exif_thumbnail($po->filename));
} catch (Exception $e) {
}
switch ($params['verbose']) {
case 1:
print_r($po->what_changed());
break;
case 2:
print_r($po->io()->getImageProperties());
break;
}
2015-05-15 04:12:10 +00:00
if ($po->list_duplicate()->find_all()->count())
2014-07-09 03:04:56 +00:00
$po->duplicate = '1';
if (! $po->changed())
return sprintf("Image [%s] already in DB: %s\n",$params['file'],$po->id);
$po->save();
if ($po->saved())
return sprintf("Image [%s] stored in DB: %s\n",$params['file'],$po->id);
return sprintf("Image [%s] processed in DB: %s\n",$params['file'],$po->id);
}
2015-05-15 04:12:10 +00:00
// Force the return of a string or NULL
2014-07-09 03:04:56 +00:00
private function dbcol($val,$noval=NULL) {
return $val ? (string)$val : $noval;
}
}
?>