SQL to add a new Album

philwild

Joined: 2006-07-25
Posts: 4
Posted: Tue, 2006-07-25 17:36

Hi,

I am new to gallery and am looking at automating the creation of a number of albums. I have been digging through the installation but am not familiar with php and am getting quite confused.

Does anyone know how to create a new album using sql rather than the interface?

Thanks

Phil

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2006-07-25 23:09

Please don't access the database yourself. Use the API instead.
Rationale:
- We maintain and version the API. You can rely on it. The data abstraction / representation of G2 can change at any time without us communicating it to anyone.
- The G2 SQL schema isn't very easy to understand. There's a single ID sequence and our object / relational mapping is not 1 class : 1 db table.

Please see documentation -> embedding and integration.

 
philwild

Joined: 2006-07-25
Posts: 4
Posted: Wed, 2006-07-26 01:23

Hi Valiant,

Thanks I'm looking throught the documentation now. I actually also looked last night as well.
I'm having trouble finding information related to creating albums. What should I be looking for?

Cheers

Phil

 
philwild

Joined: 2006-07-25
Posts: 4
Posted: Wed, 2006-07-26 02:17

I found it... Searching gave me too many hits to weed through but just browsing took me to:

http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryCoreApi.html#methodcreateAlbum

I now just need to figure out how to write something that I can run to create an album (needs to be a timed process so was planning on using a cron entry but not sure how I do this with php).

Cheers

Phil

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2006-07-26 09:36

php can be called from the command line. e.g. "php -f myphpscript.php", so that's the command you want to use in your crontab.

start your php script by including gallery2/embed.php, then call GalleryEmbed::init with fullInit => true. Then call GalleryCoreApi::createAlbum and finish it by calling GalleryEmbed::done();

 
philwild

Joined: 2006-07-25
Posts: 4
Posted: Wed, 2006-07-26 14:04

Hi Valiant,

I have to apologise upfront for looking stupid. This is the first bit of php I have ever written.
I have put together the below script and it runs without error (although I was expecting to see the value of ret printed out but it doesn't) yet I don't see any album created in gallery or inside the database. I have taken the 5 for the album owner by looking at field g_ownerid in the table xxx_Item.

What am I doing wrong.

<?php
include '/var/www/htdocs/gallery2/embed.php';
$ret = GalleryEmbed::init(array('fullInit' => true));
echo "$ret";
$ret = GalleryCoreApi::createAlbum(5,'test','test','test gallery','','key, tag');
echo "$ret";
$ret = GalleryEmbed::done();
echo "$ret";
?>

Perhaps I need to go into a little more detail.

I am using Joomla 1.0.10
I have a section that contains a number of categories.
Every time a new category in a particular section is created, I want to automatically create a new album (under the main gallery). This item is not to allow images to be uploaded, it will just house subalbums.
Every time a new content item is created in a category, I want to create a new subalbum in the categories album that will allow registered users to upload images to.

As I am not a programmer, nor very familiar with Joomla, I am detecting the creation of new categories and content items using a couple of sql code snippets that are run regularly against the joomla database. I know there would probably be a better way but so far up to this part is working.

Your help is very much appreciated.

Cheers

Phil

 
hokietoner

Joined: 2006-07-12
Posts: 4
Posted: Sun, 2006-07-30 03:19

I'm also trying to learn the gallery API, although I do know PHP. I'm confused by the createAlbum method as well. The first parameter is the ID of the parent album, not for the album owner. But I don't know how to find the ID of an album--I just want the ID of the root album. And what's the difference between name and title? Does name have to be unique?