Tommy 碎碎念

Tommy Wu's blog

« 上一篇 | 下一篇 »

避免 Gallery 3 的 server_add 模組新增項目時, 把存放的那目錄也建立成一個相簿
post by tommy @ 15 十二月, 2011 13:42

Gallery 3 與 Gallery 2 一樣, 也提供了一個 serveradd 模組, 讓我們直接由 server 上頭某個目錄來新增項目, 不過.... 在使用上感覺有點怪怪的.

舉例來說, 如果我們提供使用者一個 /home/tommy/tommy_gallery 的目錄, 讓 tommy 這位使用者用 ftp 上傳照片或影片, 接著他就可以選擇用這個方法把這些照片或影片放入 Gallery 中. 這時, 畫面會出現這個目錄, 如果點兩下會顯示底下的檔案與目錄 (目錄會被視為子相簿), 使用者可以選取要匯入的檔案或目錄.

依據我的習慣, 我通常會直接選擇整個目錄匯入 (畢竟檔案是我上傳的, 要放什麼應該在上傳時就處理好), 但是... 在目前 serveradd 這個模組中, 如果直接選擇 tommy_gallery 這個目錄, 會變成先產生 tommy_gallery 這個相簿, 然後再把底下的檔案或目錄放到這個相簿之中. 不過... 我直覺的認為, 確應該是把這目錄底下的檔案或目錄, 放到我執行 serveradd 這動作時所在的相簿內.

如果要避免這樣子處理, 變成我不能直接選擇該目錄, 而是要點開那目錄後, 對於底下的檔案與目錄一個個去點選, 這樣一樣, 如果有上百個檔案要同時匯入, 就變的很麻煩了.

這個修正就是為了解決這個問題, 會不把在 server_add 中指定的目錄也當成相簿來產生新的相簿:

--- gallery3.orig/modules/server_add/controllers/server_add.php  2011-05-25 12:04:04.000000000 +0800
+++ gallery3/modules/server_add/controllers/server_add.php 2011-12-15 13:14:37.081699983 +0800
@@ -179,7 +179,14 @@
$child_entry = ORM::factory("server_add_entry");
$child_entry->task_id = $task->id;
$child_entry->path = $child_path;
- $child_entry->parent_id = $entry->id; // null if the parent was a staging dir
+ // twu2 begin
+ // we don't want to create a new album for server_add root path
+ if (array_key_exists(pathinfo($child_path, PATHINFO_DIRNAME), $paths))
+ $child_entry->parent_id = NULL;
+ else
+ $child_entry->parent_id = $entry->id; // null if the parent was a staging dir
+ //$child_entry->parent_id = $entry->id; // null if the parent was a staging dir
+ // twu2 end
$child_entry->is_directory = is_dir($child_path);
$child_entry->save();
}
@@ -211,6 +218,10 @@
$completed_files = $task->get("completed_files", 0);
$total_files = $task->get("total_files");
 
+ // twu2 begin
+ // we need to check this later
+ $paths = unserialize(module::get_var("server_add", "authorized_paths"));
+ // twu2 end
// Ordering by id ensures that we add them in the order that we created the entries, which
// will create albums first. Ignore entries which already have an Item_Model attached,
// they're done.
@@ -243,6 +254,10 @@
$name = basename($entry->path);
$title = item::convert_filename_to_title($name);
if ($entry->is_directory) {
+ // twu2 begin
+ // dont add root path as a new album
+ if (!array_key_exists($entry->path, $paths)) {
+ // twu2 end
$album = ORM::factory("item");
$album->type = "album";
$album->parent_id = $parent->id;
@@ -253,6 +268,11 @@
$album->sort_column = $parent->sort_column;
$album->save();
$entry->item_id = $album->id;
+ // twu2 begin
+ }
+ else
+ $entry->item_id = 0;
+ // twu2 end
} else {
try {
$extension = strtolower(pathinfo($name, PATHINFO_EXTENSION));

這樣子處理方式, 會比較貼近我目前所需要的用法.

Del.icio.us Furl HEMiDEMi Technorati MyShare
commons icon [1] Re:避免 Gallery 3 的 server_add 模組新增項目時, 把存放的那目錄也建立成一個相簿 [ 回覆 ]

請問 Tommy:
我在 linux 上,使用server add 模組上傳,他總是把第一個目錄的相片傳完後就停了,其他目錄會建立成相簿,可是照片都沒傳,log 有紀錄 ORM Validation has failed for items model
本來懷疑是 memory, file size, ulimit 的限制,可是放很大了都沒解決

不知您有沒遇過

謝謝

commons icon [2] Re:避免 Gallery 3 的 server_add 模組新增項目時, 把存放的那目錄也建立成一個相簿 [ 回覆 ]

之前測的時候好像是正常的. (有試過每個目錄只放幾個檔案嗎?)
目前沒用 Gallery3, 還是用 Gallery2.

commons icon [3] Re:避免 Gallery 3 的 server_add 模組新增項目時, 把存放的那目錄也建立成一個相簿 [ 回覆 ]

tommy 好:
這個問題發生在一個很大的 folder 上,近1T
裡面第一個目錄只有一層,那一個目錄有200多個檔,傳完後,其他目錄結構都會被建成相簿,但照片完全沒傳

有試過其他比較小的 folder,都有多層目錄,檔案也不少,沒有這問題

有看過國外文章討論 ORM validation 錯誤是更新到 3.0.4 才發生的,可是我是全新安裝的

真的很怪

謝謝您

commons icon [4] Re:避免 Gallery 3 的 server_add 模組新增項目時, 把存放的那目錄也建立成一個相簿 [ 回覆 ]

好像真的是3.0.4的問題,剛灌一個3.0.2就正常

commons icon [5] Re:避免 Gallery 3 的 server_add 模組新增項目時, 把存放的那目錄也建立成一個相簿 [ 回覆 ]

請問 Tommy

有沒有辦法把照片直接傳上server的某個空間(目錄)
然後用 ln -s 連結到 gallery/var/albums 下面
而不透過 gallery 上傳介面,然後叫 gallery 自己去 update 照片檔和資料庫之間的連結資訊?

謝謝

迴響
暱稱:
標題:
個人網頁:
電子郵件:
authimage

迴響

  

Bad Behavior 已經阻擋了 57 個過去 7 天試圖闖關的垃圾迴響與引用。
Power by LifeType. Template design by JamesHuang. Valid XHTML and CSS