addItemToAlbum seems to work but nothing appears in album or db

aldoogy

Joined: 2007-07-16
Posts: 7
Posted: Wed, 2007-08-01 16:04

Hi,
I'm still doing my Gallery2 -> myEmApp integration - have got quite good results so far thanks to the docs and the help from this forum (Valiant). So here goes with my next question.

I have been building an addItemToAlbum function in my emApp (based on CodeIgniter) and I am using the Gallery2 remote module as a reference for how to add an album item.

But when I add my item using addItemToAlbum with the following arguments

filepath : C:/dev/projects/S/webroot/uploads/800px-Troll11.JPG
itemName : 800px-Troll11
title :
summary :
description :
mimeType : image/JPG
id : 10

a var_dump of the created item shows this

object(GalleryPhotoItem)#37 (25) {
  ["width"]=>
  int(0)
  ["height"]=>
  int(0)
  ["mimeType"]=>
  string(9) "image/JPG"
  ["size"]=>
  int(175585)
  ["canContainChildren"]=>
  int(0)
  ["description"]=>
  string(0) ""
  ["keywords"]=>
  NULL
  ["ownerId"]=>
  int(6)
  ["renderer"]=>
  NULL
  ["summary"]=>
  string(0) ""
  ["title"]=>
  string(0) ""
  ["viewedSinceTimestamp"]=>
  int(1185978617)
  ["originationTimestamp"]=>
  int(1185978617)
  ["pathComponent"]=>
  string(13) "800px-Troll11"
  ["parentId"]=>
  int(10)
  ["id"]=>
  int(25)
  ["creationTimestamp"]=>
  int(1185978617)
  ["isLinkable"]=>
  int(1)
  ["linkId"]=>
  NULL
  ["linkedEntity"]=>
  NULL
  ["modificationTimestamp"]=>
  int(1185978617)
  ["serialNumber"]=>
  int(1)
  ["entityType"]=>
  string(16) "GalleryPhotoItem"
  ["onLoadHandlers"]=>
  NULL
  ["_persistentStatus"]=>
  array(2) {
    ["flags"]=>
    int(0)
    ["originalValue"]=>
    array(23) {
      ["width"]=>
      int(0)
      ["height"]=>
      int(0)
      ["mimeType"]=>
      string(9) "image/JPG"
      ["size"]=>
      int(175585)
      ["canContainChildren"]=>
      int(0)
      ["description"]=>
      string(0) ""
      ["keywords"]=>
      NULL
      ["ownerId"]=>
      int(6)
      ["renderer"]=>
      NULL
      ["summary"]=>
      string(0) ""
      ["title"]=>
      string(0) ""
      ["viewedSinceTimestamp"]=>
      int(1185978617)
      ["originationTimestamp"]=>
      int(1185978617)
      ["pathComponent"]=>
      string(13) "800px-Troll11"
      ["parentId"]=>
      int(10)
      ["id"]=>
      int(25)
      ["creationTimestamp"]=>
      int(1185978617)
      ["isLinkable"]=>
      int(1)
      ["linkId"]=>
      NULL
      ["modificationTimestamp"]=>
      int(1185978617)
      ["serialNumber"]=>
      int(1)
      ["entityType"]=>
      string(16) "GalleryPhotoItem"
      ["onLoadHandlers"]=>
      NULL
    }
  }
}

But nothing appears in the parent album and I can't see anything in the DB either.
The width and height are showing up as 0 - is this the clue that something has gone wrong earlier in the code ? Or do I have to commit the item ? Also should thumbs be created automatically if I have set the parent Album to create thumbs ?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2007-08-01 16:50

don't forget to commit your transaction at the end with GalleryEmbed::done();
and don't forget to check the return values of all API methods.

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
aldoogy

Joined: 2007-07-16
Posts: 7
Posted: Thu, 2007-08-02 11:01

I tried GalleryEmbed::done();

Still no joy - I think I'm checking all return values - and it's not throwing any errors . . . ?

This width and height thing is still bothering me because the file is not 0x0 (it is something like 800x700).

I noticed the one thing I have not implemented from the remote module addDataItem function is the $gallery->platform->move_uploaded_file().

My emApp handles the file upload - so do I need to make sure the uploaded file is moved to $gallery->getConfig('data.gallery.tmp') directory before trying to do addItemToAlbum ?

Now if that is the problem then I am also having trouble finding how to access ->getConfig('data.gallery.tmp'); via CoreApi.

Thanks in advance for your help.

UPDATE :
I've changed my emApp to move the uploaded images to the g2data folder and now things are starting to happen (although maybe some of the other changes have helped also). But still no thumbs or full size image either but I am able to download the image. To me this suggests the system doesn't think this is a jpg image or I need to do something else to create the thumbs and main image size, any clues ?

UPDATE:

Just found this in the API docs - applyDerivativePreferences - will give it a go.

 
aldoogy

Joined: 2007-07-16
Posts: 7
Posted: Thu, 2007-08-02 13:35

OK Finally sussed it out.
The reason it was not working was because the mime type was wrong -
I looked in the gallery admin and could see my uploaded photos - but no thumbs or images (only download option). Then I saw a message saying that Gallery could not find a graphics toolkit that was able to process this file type. That was when it became very clear that the problem was definitely a mime type / file type detection problem.

I was trying to manually build the mime type based on the extension - instead I opted for using the API helper functions like so

$extension = GalleryUtilities::getFileExtension($itemName);
list ($ret, $mimeType) = GalleryCoreApi::convertExtensionToMime($extension);
if ($ret) 
{
    return $ret;
}

Then it all started working beautifully. Image sizes started showing up correctly as well.