summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/exif/helpers/exif.php17
-rw-r--r--modules/exif/helpers/exif_event.php3
-rw-r--r--modules/exif/helpers/exif_installer.php6
-rw-r--r--modules/exif/helpers/exif_task.php39
-rw-r--r--modules/exif/models/exif_record.php21
5 files changed, 67 insertions, 19 deletions
diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php
index ee128353..55877140 100644
--- a/modules/exif/helpers/exif.php
+++ b/modules/exif/helpers/exif.php
@@ -22,10 +22,12 @@
* This is the API for handling exif data.
*/
class exif_Core {
-
+
protected static $exif_keys;
-
+
public static function extract($item) {
+ ORM::factory("exif_key")->where("item_id", $item->id)->delete_all();
+
// Only try to extract EXIF from photos
if ($item->is_photo() && $item->mime_type == "image/jpeg") {
require_once(MODPATH . "exif/lib/exif.php");
@@ -57,6 +59,13 @@ class exif_Core {
}
}
}
+
+ $record = ORM::factory("exif_record")->where("item_id", $item->id)->find();
+ if (!$record->loaded) {
+ $record->item_id = $item->id;
+ }
+ $record->dirty = 0;
+ $record->save();
}
public static function get($item, $summary=true) {
@@ -71,10 +80,10 @@ class exif_Core {
foreach ($keys as $key) {
$exif[] = array("caption" => $definitions[$key->name][2], "value" => $key->value);
}
-
+
return $exif;
}
-
+
private static function _keys() {
if (!isset(self::$exif_keys)) {
diff --git a/modules/exif/helpers/exif_event.php b/modules/exif/helpers/exif_event.php
index ac627b11..bc34d63d 100644
--- a/modules/exif/helpers/exif_event.php
+++ b/modules/exif/helpers/exif_event.php
@@ -26,5 +26,8 @@ class exif_event_Core {
ORM::factory("exif_key")
->where("item_id", $item->id)
->delete_all();
+ ORM::factory("exif_info")
+ ->where("item_id", $item->id)
+ ->delete_all();
}
}
diff --git a/modules/exif/helpers/exif_installer.php b/modules/exif/helpers/exif_installer.php
index a008581d..791cd4a6 100644
--- a/modules/exif/helpers/exif_installer.php
+++ b/modules/exif/helpers/exif_installer.php
@@ -32,6 +32,12 @@ class exif_installer {
PRIMARY KEY (`id`),
UNIQUE KEY(`item_id`, `summary`, `name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ $db->query("CREATE TABLE IF NOT EXISTS `exif_records` (
+ `id` int(9) NOT NULL auto_increment,
+ `item_id` int(9) NOT NULL,
+ `dirty` BOOLEAN default 1,
+ PRIMARY KEY (`id`))
+ ENGINE=InnoDB DEFAULT CHARSET=utf8;");
module::set_version("exif", 1);
}
}
diff --git a/modules/exif/helpers/exif_task.php b/modules/exif/helpers/exif_task.php
index f430d185..82d78f4c 100644
--- a/modules/exif/helpers/exif_task.php
+++ b/modules/exif/helpers/exif_task.php
@@ -19,12 +19,28 @@
*/
class exif_task_Core {
static function available_tasks() {
+ $db = Database::instance();
+
+ // Delete extra exif_records
+ $db->query(
+ "DELETE `exif_records`.* FROM `exif_records` " .
+ "LEFT JOIN `items` ON (`exif_records`.`item_id` = `items`.`id`) " .
+ "WHERE `items`.`id` IS NULL");
+
+ // Insert missing exif_records
+ $db->query(
+ "INSERT INTO `exif_records`(`item_id`) (" .
+ " SELECT `items`.`id` FROM `items` " .
+ " LEFT JOIN `exif_records` ON (`exif_records`.`item_id` = `items`.`id`) " .
+ " WHERE `exif_records`.`id` IS NULL)");
+
list ($remaining, $total, $percent) = self::_get_stats();
return array(Task_Definition::factory()
->callback("exif_task::extract_exif")
->name(t("Extract EXIF data"))
- ->description($remaining ?
- sprintf(t("EXIF data is available for %d%% of the images"), $percent)
+ ->description($remaining
+ ? t("%percent% of your photos need to be scanned for EXIF data",
+ array("percent" => $percent))
: t("EXIF data is up-to-date"))
->severity($remaining ? log::WARNING : log::SUCCESS));
}
@@ -33,9 +49,8 @@ class exif_task_Core {
$completed = $task->get("completed", 0);
$work = ORM::factory("item")
- ->join("exif_keys", "items.id", "item_id", "LEFT")
- ->where("items.type", "photo")
- ->where("exif_keys.id", null)
+ ->join("exif_records", "items.id", "exif_records.item_id")
+ ->where("exif_records.dirty", 1)
->find();
exif::extract($work);
$completed++;
@@ -55,15 +70,9 @@ class exif_task_Core {
}
private static function _get_stats() {
- $exif_count = ORM::factory("exif_key")
- ->select("DISTINCT item_id")
- ->find_all()
- ->count();
-
- $items_count = ORM::factory("item")
- ->where("type", "photo")
- ->count_all();
- return array($exif_count - $items_count, $items_count,
- round(100 * ($exif_count / $items_count)));
+ $missing_exif = ORM::factory("exif_record")->where("dirty", 1)->count_all();
+ $total_items = ORM::factory("item")->count_all();
+ return array($missing_exif, $total_items,
+ round(100 * (($total_items - $missing_exif) / $total_items)));
}
}
diff --git a/modules/exif/models/exif_record.php b/modules/exif/models/exif_record.php
new file mode 100644
index 00000000..380b3799
--- /dev/null
+++ b/modules/exif/models/exif_record.php
@@ -0,0 +1,21 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class Exif_Record_Model extends ORM {
+}