dont use numRows and fix some of the gallary hooks
This commit is contained in:
parent
1d88ab57ec
commit
d8d2939668
|
@ -102,9 +102,9 @@ function handleGetGallery($path) {
|
||||||
|
|
||||||
while ($r = $result->fetchRow()) {
|
while ($r = $result->fetchRow()) {
|
||||||
$album_name = $r['album_name'];
|
$album_name = $r['album_name'];
|
||||||
$tmp_res = OC_Gallery_Photo::find($r['album_id']);
|
$size=OC_Gallery_Album::getAlbumSize($r['album_id']);
|
||||||
|
|
||||||
$a[] = array('name' => utf8_encode($album_name), 'numOfItems' => min($tmp_res->numRows(), 10));
|
$a[] = array('name' => utf8_encode($album_name), 'numOfItems' => min($size, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = OC_Gallery_Photo::find($album_details['album_id']);
|
$result = OC_Gallery_Photo::find($album_details['album_id']);
|
||||||
|
|
|
@ -107,6 +107,13 @@ class OC_Gallery_Album {
|
||||||
rename($thumbpath.$oldname.'.png', $thumbpath.$newname.'.png');
|
rename($thumbpath.$oldname.'.png', $thumbpath.$newname.'.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getAlbumSize($id){
|
||||||
|
$sql = 'SELECT COUNT(*) as size FROM *PREFIX*gallery_photos WHERE album_id = ?';
|
||||||
|
$stmt = OC_DB::prepare($sql);
|
||||||
|
$result=$stmt->execute(array($id))->fetchRow();
|
||||||
|
return $result['size'];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -37,7 +37,7 @@ class OC_Gallery_Hooks_Handlers {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function directoryContainsPhotos($dirpath) {
|
private static function directoryContainsPhotos($dirpath) {
|
||||||
$dirhandle = opendir(OC::$CONFIG_DATADIRECTORY.$dirpath);
|
$dirhandle = OC_Filesystem::opendir($dirpath.'/');
|
||||||
if ($dirhandle != FALSE) {
|
if ($dirhandle != FALSE) {
|
||||||
while (($filename = readdir($dirhandle)) != FALSE) {
|
while (($filename = readdir($dirhandle)) != FALSE) {
|
||||||
if ($filename[0] == '.') continue;
|
if ($filename[0] == '.') continue;
|
||||||
|
@ -76,9 +76,9 @@ class OC_Gallery_Hooks_Handlers {
|
||||||
|
|
||||||
public static function removePhoto($params) {
|
public static function removePhoto($params) {
|
||||||
$path = $params[OC_Filesystem::signal_param_path];
|
$path = $params[OC_Filesystem::signal_param_path];
|
||||||
if (OC_Filesystem::is_dir($path) && self::directoryContainsPhotos($path)) {
|
if (OC_Filesystem::is_dir($path.'/') && self::directoryContainsPhotos($path)) {
|
||||||
if(!self::pathInRoot($path)) return;
|
if(!self::pathInRoot($path)) return;
|
||||||
OC_Gallery_Album::removeByPath($path.'/', OC_User::getUser());
|
OC_Gallery_Album::removeByPath($path, OC_User::getUser());
|
||||||
} elseif (self::isPhoto($path)) {
|
} elseif (self::isPhoto($path)) {
|
||||||
OC_Gallery_Photo::removeByPath($path);
|
OC_Gallery_Photo::removeByPath($path);
|
||||||
}
|
}
|
||||||
|
@ -87,11 +87,11 @@ class OC_Gallery_Hooks_Handlers {
|
||||||
public static function renamePhoto($params) {
|
public static function renamePhoto($params) {
|
||||||
$oldpath = $params[OC_Filesystem::signal_param_oldpath];
|
$oldpath = $params[OC_Filesystem::signal_param_oldpath];
|
||||||
$newpath = $params[OC_Filesystem::signal_param_newpath];
|
$newpath = $params[OC_Filesystem::signal_param_newpath];
|
||||||
if (OC_Filesystem::is_dir($newpath) && self::directoryContainsPhotos($newpath)) {
|
if (OC_Filesystem::is_dir($newpath.'/') && self::directoryContainsPhotos($newpath)) {
|
||||||
OC_Gallery_Album::changePath($oldpath, $newpath, OC_User::getUser());
|
OC_Gallery_Album::changePath($oldpath, $newpath, OC_User::getUser());
|
||||||
} elseif (!self::isPhoto($newpath)) {
|
} elseif (self::isPhoto($newpath)) {
|
||||||
$olddir = substr($oldpath, 0, strrpos($oldpath, '/'));
|
$olddir = dirname($oldpath);
|
||||||
$newdir = substr($newpath, 0, strrpos($newpath, '/'));
|
$newdir = dirname($newpath);
|
||||||
if ($olddir == '') $olddir = '/';
|
if ($olddir == '') $olddir = '/';
|
||||||
if ($newdir == '') $newdir = '/';
|
if ($newdir == '') $newdir = '/';
|
||||||
if (!self::isPhoto($newpath)) return;
|
if (!self::isPhoto($newpath)) return;
|
||||||
|
@ -101,25 +101,26 @@ class OC_Gallery_Hooks_Handlers {
|
||||||
$oldAlbumId;
|
$oldAlbumId;
|
||||||
if ($olddir == $newdir) {
|
if ($olddir == $newdir) {
|
||||||
// album changing is not needed
|
// album changing is not needed
|
||||||
$album = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
|
$albums = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
|
||||||
if ($album->numRows() == 0) {
|
$album = $albums->fetchRow();
|
||||||
$album = self::createAlbum($newdir);
|
if (!$album) {
|
||||||
|
$albums = self::createAlbum($newdir);
|
||||||
|
$album = $albums->fetchRow();
|
||||||
}
|
}
|
||||||
$album = $album->fetchRow();
|
|
||||||
$newAlbumId = $oldAlbumId = $album['album_id'];
|
$newAlbumId = $oldAlbumId = $album['album_id'];
|
||||||
} else {
|
} else {
|
||||||
$newalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $newdir);
|
$newalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $newdir);
|
||||||
$oldalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
|
$oldalbum = OC_Gallery_Album::find(OC_User::getUser(), null, $olddir);
|
||||||
|
|
||||||
if ($newalbum->numRows() == 0) {
|
if (!($newalbum = $newalbum->fetchRow())) {
|
||||||
$newalbum = self::createAlbum($newdir);
|
$newalbum = self::createAlbum($newdir);
|
||||||
|
$newalbum = $newalbum->fetchRow();
|
||||||
}
|
}
|
||||||
$newalbum = $newalbum->fetchRow();
|
$oldalbum = $oldalbum->fetchRow();
|
||||||
if ($oldalbum->numRows() == 0) {
|
if (!$oldalbum) {
|
||||||
OC_Gallery_Photo::create($newalbum['album_id'], $newpath);
|
OC_Gallery_Photo::create($newalbum['album_id'], $newpath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$oldalbum = $oldalbum->fetchRow();
|
|
||||||
$newAlbumId = $newalbum['album_id'];
|
$newAlbumId = $newalbum['album_id'];
|
||||||
$oldAlbumId = $oldalbum['album_id'];
|
$oldAlbumId = $oldalbum['album_id'];
|
||||||
|
|
||||||
|
|
|
@ -62,15 +62,15 @@ class OC_Gallery_Scanner {
|
||||||
|
|
||||||
$result = OC_Gallery_Album::find(OC_User::getUser(), /*$current_album['name']*/ null, $path);
|
$result = OC_Gallery_Album::find(OC_User::getUser(), /*$current_album['name']*/ null, $path);
|
||||||
// don't duplicate galleries with same path (bug oc-33)
|
// don't duplicate galleries with same path (bug oc-33)
|
||||||
if ($result->numRows() == 0 && count($current_album['images'])) {
|
if (!($albumId = $result->fetchRow()) && count($current_album['images'])) {
|
||||||
OC_Gallery_Album::create(OC_User::getUser(), $current_album['name'], $path);
|
OC_Gallery_Album::create(OC_User::getUser(), $current_album['name'], $path);
|
||||||
$result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']);
|
$result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']);
|
||||||
|
$albumId = $result->fetchRow();
|
||||||
}
|
}
|
||||||
$albumId = $result->fetchRow();
|
|
||||||
$albumId = $albumId['album_id'];
|
$albumId = $albumId['album_id'];
|
||||||
foreach ($current_album['images'] as $img) {
|
foreach ($current_album['images'] as $img) {
|
||||||
$result = OC_Gallery_Photo::find($albumId, $img);
|
$result = OC_Gallery_Photo::find($albumId, $img);
|
||||||
if ($result->numRows() == 0) {
|
if (!$result->fetchRow()) {
|
||||||
OC_Gallery_Photo::create($albumId, $img);
|
OC_Gallery_Photo::create($albumId, $img);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue