Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OCC comand add-photo-to-album #2172

Merged
merged 9 commits into from
Dec 13, 2023
Merged

Conversation

mchugh19
Copy link
Contributor

@mchugh19 mchugh19 commented Dec 4, 2023

Creates a simple CLI for creating an album and adding a photo file to an album.

# occ photos:albums:create xian "Picnic 2023"

# occ photos:albums:create --help
Description:
  Create a new album for a user

Usage:
  photos:albums:create [options] [--] <user> <album>

Arguments:
  user                     User to own album
  album                    Album name

Options:
  -l, --location=LOCATION  Set album location (optional) [default: ""]
# occ photos:albums:add xian "Picnic 2023" "Photos/2023/08/P1010138.JPG"

# occ photos:albums:add --help
Description:
  Add specified photo to album

Usage:
  photos:albums:add <user> <album> <file>

Arguments:
  user                  User owning the album
  album                 Album name
  file                  Path of file to add to the album. It must already be scanned and available in NextCloud. Example: Photos/picture1.jpg

@mchugh19
Copy link
Contributor Author

mchugh19 commented Dec 5, 2023

Not sure what you'd like for the UI. It seems like a couple of commands would be useful from OCC. Right now there's creating an album and adding pictures to it. This covers my main scripting use-cases, but if more features should be exposed to to occ, perhaps it makes sense to define if you'd like them in a single command file vs the multiple I have done here.

lib/Command/AlbumCreateCommand.php Outdated Show resolved Hide resolved
lib/Command/AlbumCreateCommand.php Outdated Show resolved Hide resolved
@artonge
Copy link
Collaborator

artonge commented Dec 5, 2023

The title is also misleading

Copy link
Collaborator

@artonge artonge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't see the other file, the title is not so misleading :)

lib/Command/AlbumAddCommand.php Outdated Show resolved Hide resolved
lib/Command/AlbumAddCommand.php Outdated Show resolved Hide resolved
lib/Command/AlbumAddCommand.php Outdated Show resolved Hide resolved
@mchugh19
Copy link
Contributor Author

mchugh19 commented Dec 5, 2023

I think I've addressed the comments and it's looking alright now.

@mchugh19 mchugh19 requested a review from artonge December 5, 2023 23:16
@artonge
Copy link
Collaborator

artonge commented Dec 6, 2023

Some CI steps are failing.

For php-cs, can you run:

composer run cs:fix

And then commit.

For DCO, can you run:

git rebase HEAD~8 --signoff

And then push.

@mchugh19
Copy link
Contributor Author

mchugh19 commented Dec 6, 2023

Thanks for the instruction, I've never worked in a php environment before.
I think this is done.

@artonge
Copy link
Collaborator

artonge commented Dec 6, 2023

You might have changed too many commits when running the DCO command :/

@mchugh19 mchugh19 force-pushed the occ-albumAdd branch 2 times, most recently from f127386 to 7b9c80e Compare December 6, 2023 19:16
@mchugh19
Copy link
Contributor Author

mchugh19 commented Dec 6, 2023

You might have changed too many commits when running the DCO command :/

Indeed! Alright, Nth time's the charm! DCO seems happy now, so I think this might be getting close.

lib/Album/AlbumMapper.php Outdated Show resolved Hide resolved
@mchugh19 mchugh19 requested a review from artonge December 7, 2023 18:33
Copy link
Collaborator

@artonge artonge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect 👍

@artonge artonge enabled auto-merge December 13, 2023 09:49
mchugh19 and others added 9 commits December 13, 2023 10:52
Signed-off-by: Christian McHugh <mchugh19@hotmail.com>
Signed-off-by: Christian McHugh <mchugh19@hotmail.com>
Signed-off-by: Christian McHugh <mchugh19@hotmail.com>
Signed-off-by: Christian McHugh <mchugh19@hotmail.com>
Co-authored-by: Louis <louis@chmn.me>
Signed-off-by: Christian McHugh <mchugh19@hotmail.com>
Signed-off-by: Christian McHugh <mchugh19@hotmail.com>
Signed-off-by: Christian McHugh <mchugh19@hotmail.com>
Signed-off-by: Christian McHugh <mchugh19@hotmail.com>
Signed-off-by: Christian McHugh <mchugh19@hotmail.com>
@artonge artonge merged commit 42764bc into nextcloud:master Dec 13, 2023
30 checks passed
Copy link
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the reviewing process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR reviewing process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

@RTechSn
Copy link

RTechSn commented Nov 26, 2024

Hey, for anyone stumbled upon this - I made a bash script for adding a whole folder to an album.

#!/bin/bash

# Define the Nextcloud data directory (adjust this path as necessary)
nextcloud_data="/mnt/nextcloud/data"

# Set the user that has permissions to access the Nextcloud files
www_data_user="www-data"

# Set the occ command
occ_command="php /var/www/nextcloud/occ"

# Check if the correct number of arguments is provided
if [ "$#" -ne 3 ]; then
    echo "Usage: $0 <username> <album_name> <relative_path>"
    echo "Example: $0 myname \"Summer 2023\" \"Photos/Summer2023\""
    exit 1
fi

# Assign arguments to variables for better readability
username=$1
album_name=$2
relative_path=$3


# Construct the full path to the target directory
target_directory="$nextcloud_data/$username/files/$relative_path"

# Check if the directory is accessible by attempting to list its contents as www-data user
if sudo -u "$www_data_user" ls "$target_directory" >/dev/null 2>&1; then

    # List all image files and add them to the album
    image_files=$(sudo -u "$www_data_user" find "$target_directory" -type f \( -name "*.jpg" -o -name "*.jpeg" -o -name "*.png" -o -name "*.gif" \) 2>/dev/null)

    # Check if any image files were found
    if [ -z "$image_files" ]; then
        echo "No image files found in directory: $target_directory"
        exit 0
    fi

    sudo -u "$www_data_user" $occ_command photos:albums:create "$username" "$album_name"

    while IFS= read -r file; do  # Use read to handle spaces correctly
        # Construct the relative path including subdirectory structure
        relative_file_path="${file#$nextcloud_data/$username/files/}"  # Remove base path to get relative path from user files directory

        # Output which file is being added
        echo "Adding: \"$relative_file_path\""

        # Add the file to the album using occ command
        sudo -u "$www_data_user" $occ_command photos:albums:add "$username" "$album_name" "$relative_file_path"
    done <<< "$image_files"


    echo "All image files added to album '$album_name' for user '$username'."
else
    echo "Permission denied or directory not found: $target_directory"
    exit 1
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants