#1 2023-03-30 17:52:34

gatoruss
Member
2020-06-09
5

Physical and Virtual Albums

I am trying to lean my way around piwigo v13.6.0, and I am hopeful that someone can confirm that my understanding of the following is correct.

I gather that folders containing photos can uploaded via ftp, and Piwigo will:

1.  Create a subdirectory ("New Subdir") in the "directories" folder with the same name as the uploaded folder.  The photos that were in the uploaded folder will be physically located in the New Subdir.

2.  Create a physical album (" New Physical Album"), which will contain the photos in the uploaded folder (New Physical Album will have same name as the uploaded folder).

It is my understanding that:

A.  Linking a photo with a album is the same as associating a photo with an album.

B.  The photos physically located in New Physical Album call be associated with (i) one or more virtual albums (as well as be in New Phyical Album) and/or (ii) a different physical album.

C.  Photos that have associated with only virtual albums can be associated with one or more physical albums.

Can someone confirm that I am understanding this correctly?

******************************

Environment:

• Piwigo 13.6.0 Check for upgrade
• Installed on 30 March 2023, 10 hours ago
• Operating system: Linux
• PHP: 7.4.33 (Show info)
• MySQL: 10.2.44-MariaDB-cll-lve
• Graphics Library: ImageMagick 7.1.0-20

Offline

 

#2 2023-03-31 19:16:54

erAck
Only trying to help
2015-09-06
2235

Re: Physical and Virtual Albums

Not really..

1. What "directories" folder? And why should Piwigo create a new subdirectory?

2. Sounds correct.

A. If you run a FTP Sync after linking files into physical directories.

B. No. You have either physical albums matching your directories, or virtual albums. Images in physical albums can't be associated with virtual albums, AFAIK. (not very sure about whether this changed, I don't have physical albums anymore for years).

C. No.

See also
https://piwigo.org/doc/doku.php?id=user … dd_picture
https://piwigo.org/doc/doku.php?id=user … management

You can convert physical albums to virtual albums using [extension by plg] Virtualize.


Running Piwigo at https://erack.net/gallery/

Offline

 

#3 2023-04-01 04:09:11

windracer
Member
St. Pete, FL
2014-12-28
619

Re: Physical and Virtual Albums

erAck wrote:

B. No. You have either physical albums matching your directories, or virtual albums. Images in physical albums can't be associated with virtual albums, AFAIK. (not very sure about whether this changed, I don't have physical albums anymore for years).

I'm pretty sure you can associate a physical photo with a virtual album (in addition to the physical album it exists in).

Offline

 

#4 2023-04-03 15:40:49

gatoruss
Member
2020-06-09
5

Re: Physical and Virtual Albums

erAck wrote:

1. What "directories" folder? And why should Piwigo create a new subdirectory?

I am sorry.  I meant the "galleries" folder.

windracer wrote:

I'm pretty sure you can associate a physical photo with a virtual album (in addition to the physical album it exists in).

This has been my experience from playing  around with my piwigo installation:

I can associate photos in a physical album with virtual albums and other physical albums and I can associate photos not in a physical album with physical albums.

The above being the case, if I use FTP upload and create new physical albu., what is the advantage of "virtualizing"?

Offline

 

#5 2023-04-03 17:24:20

windracer
Member
St. Pete, FL
2014-12-28
619

Re: Physical and Virtual Albums

Personally, I only use physical albums because I like maintaining a specific folder/sub-folder structure for my photos (everything under "galleries" which contains symlinks out to my NAS, but that's a different discussion) with the original filenames.

Virtual albums are just that ... virtual. All of your photos will be under the "uploads" folder (with generated filenames, sorted in folders by upload date). I guess that's easier to manage for most folks since you can just upload photos to your site, not care really where they are or what they're named, but still have them appear in one-to-many virtual albums. Less maintenance on the file system side.

Offline

 

#6 2023-04-04 16:32:45

beepro
Member
2021-09-05
61

Re: Physical and Virtual Albums

for my main sites I have deleted my upload dir files and converted to only physical albums. this makes it easier to find images.  but it is more work, create dir under cpanel, upload files, then synchronize on piwigo. 

for smaller sites I am using the virual album because not too many files anyway and it is easier to upload.

Offline

 

#7 2023-04-07 15:12:26

neon
Member
2023-03-27
54

Re: Physical and Virtual Albums

For my family photo collection, I use both physical and virtual albums.

All physical albums are folders, mounted under the "Original Photos" folder with read-only access.

BTW, this was my reason to choose Piwigo: I wanted to be absolutely sure the program can not in any way modify my photos and folder structure, that I built over decades; but at the same time be able to add whatever tags, comments, etc. and create whatever needed structure of virtual albums.

So, apart from this "Original Photos", I have dozens of virtual albums with selections of photos from physical albums. Works exactly as you would dream ;)

Offline

 

#8 2025-02-28 18:38:49

MHkaserz
Member
2025-02-28
6

Re: Physical and Virtual Albums

I might be late, but maybe someone stumbles on this, who felt as defeated as I did for a whole day, or maybe longer, anyway... I solved the upload issue mention above via a script that runs regularly, it handles everything automatically.

To reiterate the use case, you want family members to upload to their own (potentially private) folders, but all uploaded files go to one blob of a folder that defies your physical album structure.

This script allows new albums to be created but it can be edited such that if a physical album is not found, the operation is skipped.

Anyway... here it is:

==============================================================
```
#!/bin/bash

# run this next to ./galleries and ./upload ideally that are bound to the docker container
# otherwise you'd need to fiddle with some stuff mainly the query in line 27

# this assumes the mysql DB is inside a docker container, otherwise you'd need to edit line 23

# Configuration
db_user="<DB_USER>"
db_pass="<DB_PASSWORD>"
db_name="<DB_NAME>"
base_dir="./galleries"
log_file="./move_log.txt"
db_container="<DB_CONTAINER_NAME>"

# Function to log messages
log_message() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$log_file"
}

# Function to execute SQL queries
run_sql() {
    docker exec $db_container mysql -u "$db_user" -p"$db_pass" -D "$db_name" -se "$1"
}

# Fetch all images with path like "./upload/%"
images=$(run_sql "SELECT images.id, images.file, images.path, images.storage_category_id, GROUP_CONCAT(parent_albums.name ORDER BY parent_albums.id SEPARATOR '/') AS full_virtual_path FROM piwigo_images AS images JOIN piwigo_image_category AS ic ON images.id = ic.image_id JOIN piwigo_categories AS albums ON ic.category_id = albums.id JOIN piwigo_categories AS parent_albums ON FIND_IN_SET(parent_albums.id, albums.uppercats) WHERE path LIKE './upload/%' GROUP BY images.id")

# Loop through each image and process it
while IFS=$'\t' read -r file_id file_name file_path storage_cat_id target_path; do
    log_message "Processing $file_path"

    # Get source directory info
    source_dir=$(dirname "$file_path")
      old_file_name=$(basename "$file_path" | sed 's/\.[^.]*$//')
      log_message "Old filename: $old_file_name"
    log_message "Source directory: $source_dir"

    # Get target category (physical album)
    read -r target_cat_id <<< $(run_sql "SELECT category_id FROM piwigo_image_category WHERE image_id=$file_id LIMIT 1")
    read -r target_cat_name target_cat_path <<< $(run_sql "SELECT name, dir FROM piwigo_categories WHERE id=$target_cat_id")

    target_full_path="$base_dir/$target_path/$file_name"
    log_message "Moving file from $file_path to $target_full_path"

    # Check if target directory exists, create if not
    if [ ! -d "$base_dir/$target_path" ]; then
        mkdir -p "$base_dir/$target_path"
        chmod 755 "$base_dir/$target_path"
        log_message "Created target directory $base_dir/$target_path"
    fi

    # Move the file
    if mv "$file_path" "$target_full_path"; then
        chmod +x "$target_full_path"
       
        # Update database with new file path
        run_sql "UPDATE piwigo_images SET file='$(basename "$target_full_path")', path='$target_full_path', storage_category_id=$target_cat_id WHERE id=$file_id"
        run_sql "DELETE FROM piwigo_image_category WHERE image_id=$file_id AND category_id=$storage_cat_id"
        run_sql "INSERT INTO piwigo_image_category (image_id, category_id) VALUES ($file_id, $target_cat_id)"
       
        log_message "Successfully moved $file_name to $target_full_path"
    else
        log_message "ERROR: Failed to move $file_name. Check permissions."
        continue
    fi

    # Move Representative (if exists)
    rep_ext=$(run_sql "SELECT representative_ext FROM piwigo_images WHERE id=$file_id")
    log_message "Representative extension: $rep_ext"
    if [ -n "$rep_ext" ]; then
        source_rep_path="./$source_dir/pwg_representative/$old_file_name.$rep_ext"
        target_rep_path="$base_dir/$target_path/pwg_representative/${file_name%.*}.$rep_ext"

        if [ -f "$source_rep_path" ]; then
            if [ ! -d "$base_dir/$target_path/pwg_representative" ]; then
                mkdir -p "$base_dir/$target_path/pwg_representative"
            fi

            if mv "$source_rep_path" "$target_rep_path"; then
                chmod +x "$target_rep_path"
                log_message "Moved representative image to $target_rep_path"
            else
                log_message "ERROR: Failed to move representative image."
            fi
        fi
    fi

    # Cleanup empty directories
    rmdir --ignore-fail-on-non-empty "$source_dir" 2>/dev/null && log_message "Removed empty source folder $source_dir"

    log_message "Move operation completed for image ID $file_id"
done <<< "$images"

log_message "All move operations completed."
```
==============================================================

Credit: Myself and it was supported by the "move to physical album" extension
(without it I was lost as to what to do in the DB)

HAPPY HACKING!

Offline

 

#9 2025-03-02 02:40:35

MHkaserz
Member
2025-02-28
6

Re: Physical and Virtual Albums

Somethings to improve about the script:

The query can simply track every moved file (not just uploaded ones) by checking that
`CONCAT(BASE_DIR, full_virtual_path, '/', images.file) <> images.path`

BASE_DIR is normally ./galleries/

You can also add this block after the query to avoid filling the log with unnecessary error messages when there is nothing to process

if [ -z "$images" ]; then
    log_message "No images were uploaded/moved. Exiting script."
    exit 0
fi

Last edited by MHkaserz (2025-03-02 02:43:44)

Offline

 

Board footer

Powered by FluxBB

github linkedin newsletter Piwigo.org © 2002-2026 · Contact