Hello!
I have a problem in my script with Gallery 2.2. The script works ok with Gallery 2.1
When my script creates album or adds item (image) to album the script does not write error messages, item or folder is created in gallery data folder, but it not displayed (information is not added to database).
Does anyone know what is the problem?
Posts: 32509
what script are you talking about?
it's hard to tell what's wrong if we don't know what script you're running...
--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage
Posts: 8
My code here: (Working in Gallery 2.1)
{File image1.jpg copying to album folder, but not display!}
$userid = 'user';
$image_name = 'file/image1.jpg';
$albumtext = 'text';
require_once ("gallery2/embed.php");
$embed = new GalleryEmbed;
$embed->init();
$gapi = new GalleryCoreApi;
list($ret,$usr) = GalleryCoreApi::fetchUserByUserName($userid);
$userid2 = $usr->getId();
list($ret,$rootid) = $gapi->getPluginParameter('module', 'core', 'id.rootAlbum');
list($status, $val) = $gapi->loadEntitiesById($rootid);
list ($ret, $childCounts) = $gapi->fetchChildItemIds($val);
$albumId = 0;
$found = 0;
$c = 0;
while (list($k,$v) = each ($childCounts)) {
$c++;
list($status, $album) = $gapi->loadEntitiesById($v);
$albomsdata[$c]['pathComponent'] = $album->pathComponent;
$albomsdata[$c]['id'] = $album->id;
list ($ret, $childCounts2) = $gapi->fetchChildItemIds($album);
while (list($k2,$v2) = each ($childCounts2)) {
$c++;
list($status, $album2) = $gapi->loadEntitiesById($v2);
//$albomsdata[$c]['pathComponent'] = $album->pathComponent."/".$album2->pathComponent;
$albomsdata[$c]['pathComponent'] = $album2->pathComponent;
$albomsdata[$c]['id'] = $album2->id;
}
}
foreach ($albomsdata as $data) {
if ($data['pathComponent'] == $albumname) {
//FINED MIME TYPE//
$ext = strtolower(substr($image_name, 1 + strrpos($image_name, ".")));
list ($ret, $mime_type) = $gapi->convertExtensionToMime($ext);
//---------------//
addItemToAlbum ($usr, $image_name, $image_name, $image_name, $albumtext, $albumtext, $mime_type, $data['id']);
}
}
function addItemToAlbum($userId,$fileName, $itemName, $title, $summary,$description, $mimeType, $albumId)
{
require_once ("gallery2/embed.php");
//passing in an album id lets make sure it exists
list ($ret, $album) = GalleryCoreApi::loadEntitiesById($albumId);
if ($ret && !($ret->getErrorCode() & ERROR_MISSING_OBJECT)) {
$msg = $ret->getAsText();
}
//write lock on album so we can add item
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($albumId);
//check for error
if ($ret) {
$msg = $ret->getAsText();
}
//using gallery core api to add the item
list($ret,$item) = GalleryCoreApi::addItemToAlbum($fileName,$itemName, $title, $summary,$description, $mimeType, $albumId);
if ($ret) {
$msg = $ret->getAsText();
}
//if item name exists add _ to it
if ($ret && $ret->getErrorCode() & ERROR_COLLISION) {
$itemName .= '_';
}
//save and release lock
$ret = $album->save();
list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($item->getId());
if ($ret) {
$msg = $ret->getAsText();
}
/* Set owner for item and permissions I just want users to comment and simple edit do whatever you want.. */
$item->setOwnerId($userId->getID());
if ($ret) {
$msg = $ret->getAsText();
}
$ret = $item->save();
if ($ret) {
$msg = $ret->getAsText();
}
//i want to return the item id to do other things with it
$itemId = $item->getId();
return $itemId;
}
Posts: 8
This is a simple sample. It adds user to Gallery 2.1, but it does not add user to Gallery 2.2
<?php
require "gallery2/embed.php";
$embed = new GalleryEmbed;
$embed->init();
$id = rand(999,9999);
$args[username] = "testuser".$id;
$args[fullname] = "Test user";
if ("userpass") {
$args[password] = "userpass";
}
$args[email] = $args[username]."@email.com";
$args[language] = 'en_US';
list($ret,$item) = $embed->createUser($id, $args);
if ($ret) {
echo $ret->getAsText();
}
list($ret,$item) = $embed->updateUser($id, $args);
if ($ret) {
echo $ret->getAsText();
}
echo $args[username];
?>
<br />ok