Commit c6454958 authored by Jonny Bradley's avatar Jonny Bradley
Browse files

[KIL] imagegallery: Remove image galleries

parent a16659d9
Pipeline #318623100 passed with stages
in 7 minutes and 33 seconds
<?php
// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
// This script may only be included - so its better to die if called directly.
if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) !== false) {
header('location: index.php');
exit;
}
$imagegallib = TikiLib::lib('imagegal');
if (isset($_REQUEST['galfeatures'])) {
// Check for last character being a / or a \
// My next commit is to create a clas to put this code into
// TODO Do not modify $_REQUEST variable directly
if (substr($_REQUEST['gal_use_dir'], -1) != '\\'
&& substr($_REQUEST['gal_use_dir'], -1) != '/'
&& $_REQUEST['gal_use_dir'] != ''
) {
$_REQUEST['gal_use_dir'] .= '/';
}
if (substr($_REQUEST['gal_batch_dir'], -1) != '\\'
&& substr($_REQUEST['gal_batch_dir'], -1) != '/'
&& $_REQUEST['gal_batch_dir'] != ''
) {
$_REQUEST['gal_batch_dir'] .= '/';
}
}
//*** begin state-changing actions
if (isset($_POST['rmvorphimg']) && $access->checkCsrf(true)) {
$adminlib->remove_orphan_images();
Feedback::success(tra('Orphan images successfully removed'));
}
if (isset($_POST['mvimg']) && isset($_POST['move_gallery']) && $access->checkCsrf()) {
if (($_POST['mvimg'] == 'to_fs' && $prefs['gal_use_db'] == 'n')
|| ($_POST['mvimg'] == 'to_db' && $prefs['gal_use_db'] == 'y')
) {
$mvresult = $imagegallib->move_gallery_store($_POST['move_gallery'], $_POST['mvimg']);
$mvmsg = sprintf(tra('moved %d images, %d errors occurred.'), $mvresult['moved_images'], $mvresult['errors']);
if ($mvresult['timeout']) {
$mvmsg .= ' ' . tra('a timeout occurred. Hit the reload button to move the rest');
}
Feedback::note($mvmsg);
}
}
//*** end state-changing actions
$galleries = $imagegallib->list_visible_galleries(0, -1, 'name_desc', 'admin', '');
$smarty->assign_by_ref('galleries', $galleries['data']);
$smarty->assign('max_img_upload_size', $imagegallib->max_img_upload_size());
......@@ -77,13 +77,6 @@ function activated_features()
}
break;
case 'galleries':
if (isset($prefs['feature_galleries']) and $prefs['feature_galleries'] == 'y') {
$activated_features[] = 'galleries';
$activated_features[] = 'images';
}
break;
case 'trackers':
if (isset($prefs['feature_trackers']) and $prefs['feature_trackers'] == 'y') {
$activated_features[] = 'trackers';
......
......@@ -315,15 +315,6 @@ faqs:
- admin_faqs
- suggest_faq
- view_faqs
'image galleries':
- admin_galleries
- assign_perm_image_gallery
- batch_upload_image_dir
- batch_upload_images
- create_galleries
- list_image_galleries
- upload_images
- view_image_gallery
media:
- admin_kaltura
- list_videos
......
......@@ -1664,12 +1664,6 @@ INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `s
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'o','Received Pages','tiki-received_pages.php',245,'feature_wiki,feature_comm','tiki_p_view,tiki_p_admin_received_pages','',0);
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'o','Structures','tiki-admin_structures.php',250,'feature_wiki,feature_wiki_structure','tiki_p_view','',0);
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'o','Mind Map','tiki-mindmap.php',255,'feature_wiki_mindmap','tiki_p_view','',0);
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'s','Image Galleries','tiki-galleries.php',300,'feature_galleries','tiki_p_view_image_gallery','',0);
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'o','Galleries','tiki-galleries.php',305,'feature_galleries','tiki_p_list_image_galleries','',0);
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'o','Rankings','tiki-galleries_rankings.php',310,'feature_galleries,feature_gal_rankings','tiki_p_list_image_galleries','',0);
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'o','Upload Image','tiki-upload_image.php',315,'feature_galleries','tiki_p_upload_images','',0);
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'o','Directory Batch','tiki-batch_upload.php',318,'feature_galleries,feature_gal_batch','tiki_p_batch_upload','',0);
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'o','System Gallery','tiki-list_gallery.php?galleryId=0',320,'feature_galleries','tiki_p_admin_galleries','',0);
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'s','Articles','tiki-view_articles.php',350,'feature_articles','tiki_p_read_article','',0);
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'s','Articles','tiki-view_articles.php',350,'feature_articles','tiki_p_articles_read_heading','',0);
INSERT INTO `tiki_menu_options` (`menuId`, `type`, `name`, `url`, `position`, `section`, `perm`, `groupname`, `userlevel`) VALUES (42,'o','Articles Home','tiki-view_articles.php',355,'feature_articles','tiki_p_read_article','',0);
......@@ -3464,7 +3458,6 @@ INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES(
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-browse_categories.php\\?parentId=(\\d+)', 'cat$1', 'category', 'feature_categories');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-view_blog.php\\?blogId=(\\d+)', 'blog$1', 'blog', 'feature_blogs');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-view_blog_post.php\\?postId=(\\d+)', 'blogpost$1', 'blogpost', 'feature_blogs');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-browse_image.php\\?imageId=(\\d+)', 'browseimage$1', 'image', 'feature_galleries');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-directory_browse.php\\?parent=(\\d+)', 'directory$1', 'directory', 'feature_directory');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-view_faq.php\\?faqId=(\\d+)', 'faq$1', 'faq', 'feature_faqs');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`, `order`) VALUES('tiki-download_file.php\\?fileId=(\\d+)', 'dl$1', 'file', 'feature_file_galleries', 10);
......@@ -3472,9 +3465,6 @@ INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES(
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-download_file.php\\?fileId=(\\d+)&amp;display', 'display$1', 'display', 'feature_file_galleries');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-download_file.php\\?fileId=(\\d+)&amp;preview', 'preview$1', 'preview', 'feature_file_galleries');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-view_forum.php\\?forumId=(\\d+)', 'forum$1', 'forum', 'feature_forums');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-browse_gallery.php\\?galleryId=(\\d+)', 'gallery$1', 'gallery', 'feature_galleries');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('show_image.php\\?id=(\\d+)', 'image$1', 'image', 'feature_galleries');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('show_image.php\\?id=(\\d+)&scalesize=(\\d+)', 'imagescale$1/$2', 'image', 'feature_galleries');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-newsletters.php\\?nlId=(\\d+)', 'newsletter$1', 'newsletter', 'feature_newsletters');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-take_quiz.php\\?quizId=(\\d+)', 'quiz$1', 'quiz', 'feature_quizzes');
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`) VALUES('tiki-take_survey.php\\?surveyId=(\\d+)', 'survey$1', 'survey', 'feature_surveys');
......@@ -3498,7 +3488,6 @@ INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`, `order`
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`, `order`) VALUES('tiki-list_faqs.php', 'faqs', '', 'feature_faqs', 200);
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`, `order`) VALUES('tiki-file_galleries.php', 'files', '', 'feature_file_galleries', 200);
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`, `order`) VALUES('tiki-forums.php', 'forums', '', 'feature_forums', 200);
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`, `order`) VALUES('tiki-galleries.php', 'galleries', '', 'feature_galleries', 200);
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`, `order`) VALUES('tiki-login_scr.php', 'login', '', '', 200);
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`, `order`) VALUES('tiki-my_tiki.php', 'my', '', '', 200);
INSERT INTO `tiki_sefurl_regex_out` (`left`, `right`, `type`, `feature`, `order`) VALUES('tiki-newsletters.php', 'newsletters', 'newsletter', 'feature_newsletters', 200);
......
......@@ -575,6 +575,15 @@ class CheckSchemaUpgrade
$dbConnection->exec("ALTER TABLE `tiki_actionlog_conf` AUTO_INCREMENT = 1");
$dbConnection->exec("INSERT INTO `tiki_actionlog_conf` SELECT * FROM `tiki_actionlog_conf_tmp`");
$dbConnection->exec("DROP TABLE `tiki_actionlog_conf_tmp`");
// reload tiki_sefurl_regex_out in the upgraded tiki to account for the case where an old entry is removed
$dbConnection->exec("CREATE TABLE `tiki_sefurl_regex_out_tmp` AS SELECT * FROM `tiki_sefurl_regex_out` ORDER BY `order`, `id`");
$dbConnection->exec("ALTER TABLE `tiki_sefurl_regex_out_tmp` CHANGE COLUMN id id int NULL");
$dbConnection->exec("UPDATE `tiki_sefurl_regex_out_tmp` SET id=NULL");
$dbConnection->exec("DELETE FROM `tiki_sefurl_regex_out`");
$dbConnection->exec("ALTER TABLE `tiki_sefurl_regex_out` AUTO_INCREMENT = 1");
$dbConnection->exec("INSERT INTO `tiki_sefurl_regex_out` SELECT * FROM `tiki_sefurl_regex_out_tmp`");
$dbConnection->exec("DROP TABLE `tiki_sefurl_regex_out_tmp`");
}
/**
......@@ -589,7 +598,7 @@ class CheckSchemaUpgrade
$argv = $GLOBALS['argv'];
$fakeArgv = [
$argv[0],
sprintf('--server1=%s:%s@%s', $this->oldDb['user'], $this->oldDb['pass'], $this->oldDb['host']),
sprintf('--server1=%s:%s@%s', $this->oldDb['user'], $this->oldDb['pass'], $this->oldDb['host']),
sprintf('--server2=%s:%s@%s', $this->newDb['user'], $this->newDb['pass'], $this->newDb['host']),
'--type=all',
'--include=all',
......
<?php
// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
//if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
// header("location: index.php");
// exit;
//}
/**
* One day this will be an installer upgrade script
*
* @param $installer
*/
function upgrade_2017mmdd_migrate_image_galleries_tiki($installer)
{
$filegallib = TikiLib::lib('filegal');
$attributelib = TikiLib::lib('attribute');
$tikiGalleries = TikiDb::get()->table('tiki_galleries');
$tikiGalleriesScales = TikiDb::get()->table('tiki_galleries_scales');
$tikiImages = TikiDb::get()->table('tiki_images');
$tikiImagesData = TikiDb::get()->table('tiki_images_data');
$galleryIdMap = [];
if ($tikiImages->fetchCount([])) {
$rootFileGalleryId = $filegallib->replace_file_gallery([
'name' => tra('Migrated Image Galleries'),
'description' => tra('Converted image galleries from version created by Tiki 17'),
]);
foreach ($tikiGalleries->fetchAll() as $gallery) {
$gallery['sort_mode'] = $gallery['sortorder'] . '_' . $gallery['sortdirection'];
$oldGalleryId = $gallery['galleryId'];
$gallery['galleryId'] = 0; // we want a new one
if ($gallery['parentgallery'] < 0 || empty($galleryIdMap[$gallery['parentgallery']])) {
$gallery['parentId'] = $rootFileGalleryId;
} else {
$gallery['parentId'] = $galleryIdMap[$gallery['parentgallery']];
}
$gallery['show_name'] = $gallery['showname'];
$gallery['show_id'] = $gallery['showimageid'];
$gallery['show_description'] = $gallery['showdescription'];
$gallery['show_author'] = $gallery['showuser']; // TODO something about creator?
$gallery['show_hits'] = $gallery['showhits'];
if ($gallery['show_name'] === 'y' && $gallery['show_filename'] === 'y') {
$gallery['show_name'] = 'a';
} elseif ($gallery['show_filename'] === 'y') {
$gallery['show_name'] = 'f';
} else {
$gallery['show_name'] = 'n';
}
unset(
$gallery['geographic'],
$gallery['theme'],
$gallery['rowImages'],
$gallery['thumbSizeX'],
$gallery['thumbSizeY'],
$gallery['sortorder'],
$gallery['sortdirection'],
$gallery['galleryimage'], // TODO something?
$gallery['parentgallery'],
$gallery['showname'],
$gallery['showimageid'],
$gallery['showdescription'],
$gallery['showcreated'],
$gallery['showuser'],
$gallery['showhits'],
$gallery['showxysize'],
$gallery['showfilesize'],
$gallery['showname'],
$gallery['showfilename'],
$gallery['defaultscale'], // TODO something?
$gallery['showcategories']
);
$fileGalleryId = $filegallib->replace_file_gallery($gallery);
$galleryIdMap[$oldGalleryId] = $fileGalleryId;
$images = $tikiImages->fetchAll([], ['galleryId' => $oldGalleryId]);
foreach ($images as $image) {
$imageData = $tikiImagesData->fetchAll([], [
'type' => 'o', // not thumbnails
'imageId' => $image['imageId'],
]);
$image = array_merge($imageData[0], $image);
$image['galleryId'] = $fileGalleryId;
$file = new Tiki\FileGallery\File([
'galleryId' => $image['galleryId'],
'description' => $image['description'],
'user' => $image['user'],
'author' => $image['user'],
'created' => $image['created'],
]);
$fileId = $file->replace($image['data'], $image['filetype'], $image['name'], $image['filename'], $image['xsize'], $image['ysize']);
TikiLib::lib('geo')->set_coordinates(
'file',
$fileId,
[
'lon' => $image['lon'],
'lat' => $image['lat'],
]
);
// add the old imageId as an attribute for future use in the img plugin
$attributelib->set_attribute('file', $fileId, 'tiki.file.imageid', $image['imageId']);
}
}
}
}
include_once('tiki-setup.php');
$installer = Installer::getInstance();
upgrade_2017mmdd_migrate_image_galleries_tiki($installer);
DELETE FROM `tiki_modules`
WHERE `name` = 'last_image_galleries'
OR `name` = 'last_images'
OR `name` = 'random_images'
OR `name` = 'top_image_galleries'
OR `name` = 'top_images'
OR `name` = 'user_image_galleries'
;
DELETE FROM `tiki_menu_options`
WHERE (`menuId` = '42') AND (`section` LIKE '%feature_galleries%');
DELETE FROM `tiki_sefurl_regex_out` WHERE `feature` = 'feature_galleries';
......@@ -44,8 +44,6 @@ class AvatarLib extends TikiLib
/** @var UserPrefsLib $userprefslib */
$userprefslib = TikiLib::lib('userprefs');
/** @var ImageGalsLib $imagegallib */
$imagegallib = TikiLib::lib('imagegal');
if (empty($userwatch)) {
$userwatch = $user;
......@@ -115,8 +113,7 @@ class AvatarLib extends TikiLib
imagefill($t, 0, 0, $trans_colour);
imagecopyresampled($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y);
} else {
$t = imagecreate($tw, $ty);
$imagegallib->ImageCopyResampleBicubic($t, $img, 0, 0, 0, 0, $tw, $ty, $size_x, $size_y);
// TODO ImageGalleryRemoval23.x - replace imagick if no GD
}
// CHECK IF THIS TEMP IS WRITEABLE OR CHANGE THE PATH TO A WRITEABLE DIRECTORY
$tmpfname = tempnam($prefs['tmpDir'], "TMPIMG");
......
......@@ -344,7 +344,7 @@ class TikiCalendarLib extends CalendarLib
function getTikiItems($with_infos = true)
{
global $prefs;
global $tiki_p_view, $tiki_p_view_image_gallery, $tiki_p_read_article;
global $tiki_p_view, $tiki_p_read_article;
global $tiki_p_read_blog, $tiki_p_forum_read, $tiki_p_view_directory;
global $tiki_p_view_file_gallery, $tiki_p_view_faqs, $tiki_p_take_quiz;
global $tiki_p_view_trackers, $tiki_p_take_survey, $tiki_p_subscribe_newsletters;
......@@ -356,12 +356,6 @@ class TikiCalendarLib extends CalendarLib
'right' => "$tiki_p_view"
],
'gal' => [
'label' => tra('Image Gallery'),
'feature' => '' . $prefs['feature_galleries'],
'right' => "$tiki_p_view_image_gallery"
],
'art' => [
'label' => tra('Articles'),
'feature' => '' . $prefs['feature_articles'],
......
......@@ -1364,7 +1364,6 @@ class CategLib extends ObjectLib
"faq" => "faq",
"fgal" => "file gallery",
"forum" => "forum",
"igal" => "image gallery",
"newsletter" => "newsletter",
"poll" => "poll",
"quiz" => "quiz",
......
......@@ -2772,9 +2772,6 @@ class Comments extends TikiLib
case 'file gallery':
$href = 'tiki-list_file_gallery.php?galleryId=';
break;
case 'image gallery':
$href = 'tiki-browse_gallery.php?galleryId=';
break;
case 'poll':
$href = 'tiki-poll_results.php?pollId=';
break;
......
......@@ -82,15 +82,6 @@ class TikiObject extends Type
}
break;
case 'gallery':
$galleries = $tikilib->list_galleries(0, -1, 'name_desc');
foreach ($galleries['data'] as $gallery) {
$objects[$gallery['galleryId']] = $gallery['name'];
}
break;
case 'wiki page':
$pages = $tikilib->list_pages(0, -1, 'pageName_asc');
......
<?php
// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
/**
* Class for image_gallery_changed events
*/
class Reports_Send_EmailBuilder_ImageGalleryChanged extends Reports_Send_EmailBuilder_Abstract
{
public function getTitle()
{
return tr('Image galleries changed:');
}
public function getOutput(array $change)
{
$base_url = $change['data']['base_url'];
if (empty($change['data']['action'])) {
$output = $change['data']['user'] . ' ' . tra('changed the picture gallery') .
" <a href=\"{$base_url}tiki-browse_gallery.php?galleryId=" .
$change['data']['galleryId'] . "&offset=0&sort_mode=created_desc\">" . $change['data']['galleryName'] . '</a>.';
} elseif ($change['data']['action'] == 'upload image') {
$output = '<u>' . $change['data']['user'] . '</u> ' . tra('uploaded the picture') .
" <a href=\"{$base_url}tiki-browse_image.php?imageId=" . $change['data']['imageId'] . "\">" .
$change['data']['imageName'] . '</a> ' . tra('onto') .
" <a href=\"{$base_url}tiki-browse_gallery.php?galleryId=" .
$change['data']['galleryId'] . "&offset=0&sort_mode=created_desc\">" . $change['data']['galleryName'] . '</a>.';
} elseif ($change['data']['action'] == "remove image") {
$output = '<u>' . $change['data']['user'] . '</u> ' . tra('removed the picture') .
" <a href=\"{$base_url}tiki-browse_image.php?imageId=" . $change['data']['imageId'] . "\">" .
$change['data']['imageName'] . '</a> ' . tra('from') .
" <a href=\"{$base_url}tiki-browse_gallery.php?galleryId=" . $change['data']['galleryId'] .
"&offset=0&sort_mode=created_desc\">" . $change['data']['galleryName'] . '</a>.';
}
return $output;
}
}
......@@ -41,16 +41,6 @@ class Sections
'itemObjectType' => 'file',
'commentsFeature' => 'feature_file_galleries_comments',
],
// tra('Image Gallery')
// tra('Image')
'galleries' => [
'feature' => 'feature_galleries',
'key' => 'galleryId',
'itemkey' => 'imageId',
'objectType' => 'image gallery',
'itemObjectType' => 'image',
'commentsFeature' => 'feature_image_galleries_comments',
],
// tra('Forum')
// tra('Forum Post')
'forums' => [
......
<?php
// (c) Copyright by authors of the Tiki Wiki/CMS/Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
namespace Tiki\Files;
use ImageGalsLib;
use TikiLib;
/**
* Allows to analyse the images from image gallery, to see if they exist and are stored in the right place
*/
class CheckImageGallery extends AbstractCheckGallery
{
/**
* Process the analyses for Image Galleries
*
* @return array
*/
public function analyse()
{
$imagesPerQuery = 100;
$usesDatabase = $this->areFilesStoredInDatabase();
$galleryPath = $this->getPathOnDisk();
$filesCountTotal = 0;
$filesInDbCount = 0;
$filesInDiskCount = 0;
$filesToCheckOnDisk = [];
$galleryList = $this->getGalleryIdList();
foreach ($galleryList as $gallery) {
$offset = 0;
do {
list($imageList, $filesCount) = $this->getImageList($gallery, $offset, $imagesPerQuery);
foreach ($imageList as $image) {
if ($image['path']) {
$filesInDiskCount++;
$filesToCheckOnDisk[] = [
'id' => $image['imageId'],
'name' => $image['path'],
'path' => $galleryPath,
'size' => $image['filesize'],
];
} else {
$filesInDbCount++;
}
}
$offset += $imagesPerQuery;
$filesCountTotal += count($imageList);
} while (count($imageList) == $imagesPerQuery);
}
$filesOnDisk = $this->listFilesInDirectory($galleryPath);
list($missing, $mismatch, $unknown) = $this->matchFileList($filesToCheckOnDisk, $filesOnDisk, ['.thumb']);
return [
'usesDatabase' => $usesDatabase,
'path' => [$galleryPath],
'mixedLocation' => ($filesInDbCount !== 0 && $filesInDiskCount !== 0) ? true : false,
'count' => $filesCountTotal,
'countFilesDb' => $filesInDbCount,
'countFilesDisk' => $filesInDiskCount,
'issueCount' => count($missing) + count($mismatch) + count($unknown),
'missing' => $missing,
'mismatch' => $mismatch,
'unknown' => $unknown,
];
}
/**
* The the list of Ids for galleries
*
* @return array
*/
protected function getGalleryIdList()
{
/** @var ImageGalsLib $imageGalleryLib */
$imageGalleryLib = TikiLib::lib('imagegal');
$galleryList = $imageGalleryLib->list_galleries(0, -1, 'name_desc', 'admin');
$galleryIdList = array_map(
function ($item) {
return $item['galleryId'];
},
$galleryList['data']
);
return $galleryIdList;
}
/**
* Get the list of images for a given gallery
*
* @param int $gallery
* @param int $offset
* @param int $imagesPerQuery
* @return array
*/
protected function getImageList($gallery, $offset, $imagesPerQuery)
{
/** @var ImageGalsLib $imageGalleryLib */
$imageGalleryLib = TikiLib::lib('imagegal');
$imageList = $imageGalleryLib->list_images($offset, $imagesPerQuery, '', '', $gallery);
return [$imageList['data'], $imageList['cant']];
}
/**
* Checks if the configuration is to store files in DB or disk
*
* @return bool
*/
protected function areFilesStoredInDatabase()
{
global $prefs;
$usesDatabase = true;
if ($prefs['gal_use_db'] != 'y') {
$usesDatabase = false;
}
return $usesDatabase;
}
/**
* Returns where to store files on disk
*
* @return string
*/
protected function getPathOnDisk()
{
global $prefs;
return $prefs['gal_use_dir'];
}
}
......@@ -221,14 +221,8 @@ class Tracker_Field_Image extends Tracker_Field_File