--- modules/reupload/ReuploadPhotoOption.inc 2007-11-20 03:45:20.000000000 +0000 +++ modules/reupload/ReuploadPhotoOption.inc 2007-10-20 03:50:01.000000000 +0000 @@ -1,9 +1,7 @@ - */ - -/** - * This controller will handle the reupload of a photo - * - * @package Reupload + * @version $Revision: 16994 $ */ class ReuploadPhotoOption extends ItemEditOption { @@ -40,26 +34,33 @@ global $gallery; $platform =& $gallery->getPlatform(); - $status = array(); - $error = array(); + $status = $error = array(); if (!empty($form['tmp_name']['reupload']) && !empty($form['size']['reupload'])) { $inputFileName = $form['tmp_name']['reupload']; list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'reupload'); if ($ret) { - return array($ret->wrap(__FILE__, __LINE__), null, null); + return array($ret, null, null); } if (!$platform->is_uploaded_file($inputFileName) || !$platform->file_exists($inputFileName)) { - return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER, __FILE__, __LINE__), - null, null); + return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER), null, null); + } + + list ($ret, $hasLinkedEntity) = $this->_hasLinkedEntity($item); + if ($ret) { + return array($ret, null, null); + } + if ($hasLinkedEntity) { + /* UI does not allow this */ + return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER), null, null); } list ($ret, $path) = $item->fetchPath(); if ($ret) { - return array($ret->wrap(__FILE__, __LINE__), null, null); + return array($ret, null, null); } /* @@ -68,31 +69,33 @@ */ list ($ret, $lockIds[]) = GalleryCoreApi::acquireReadLockParents($item->getId()); if ($ret) { - return array($ret->wrap(__FILE__, __LINE__), null, null); + return array($ret, null, null); } list ($ret, $lockIds[]) = GalleryCoreApi::acquireWriteLock($item->getId()); if ($ret) { - return array($ret->wrap(__FILE__, __LINE__), null, null); + return array($ret, null, null); + } + list ($ret, $item) = $item->refresh(); + if ($ret) { + GalleryCoreApi::releaseLocks($lockIds); + return array($ret, null, null); } /* take backup first */ $tmpfname = $platform->tempnam($gallery->getConfig('data.gallery.tmp'), 'tmp_'); if (!$tmpfname) { GalleryCoreApi::releaseLocks($lockIds); - return array(GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__), - null, null); + return array(GalleryCoreApi::error(ERROR_PLATFORM_FAILURE), null, null); } if (!$platform->copy($path, $tmpfname)) { $platform->unlink($tmpfname); GalleryCoreApi::releaseLocks($lockIds); - return array(GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__), - null, null); + return array(GalleryCoreApi::error(ERROR_PLATFORM_FAILURE), null, null); } if (!$platform->copy($inputFileName, $path)) { $platform->unlink($tmpfname); GalleryCoreApi::releaseLocks($lockIds); - return array(GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__), - null, null); + return array(GalleryCoreApi::error(ERROR_PLATFORM_FAILURE), null, null); } $ret = $item->rescan(); @@ -113,19 +116,19 @@ $platform->copy($tmpfname, $path); $platform->unlink($tmpfname); GalleryCoreApi::releaseLocks($lockIds); - return array($ret->wrap(__FILE__, __LINE__), null, null); + return array($ret, null, null); } $platform->unlink($tmpfname); $ret = GalleryCoreApi::releaseLocks($lockIds); if ($ret) { - return array($ret->wrap(__FILE__, __LINE__), null, null); + return array($ret, null, null); } $ret = GalleryCoreApi::invalidateDerivativeDimensionsBySourceIds( array($item->getId())); if ($ret) { - return array($ret->wrap(__FILE__, __LINE__), null, null); + return array($ret, null, null); } $status[] = $module->translate('Reuploaded file successfully.'); @@ -148,7 +151,7 @@ function loadTemplate(&$template, &$form, $item, $thumbnail) { list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'reupload'); if ($ret) { - return array($ret->wrap(__FILE__, __LINE__), null, null); + return array($ret, null, null); } if ($template->hasVariable('ItemAdmin')) { @@ -178,22 +181,44 @@ 'arg1' => (int)($maxFileSize / (1024)))); } + list ($ret, $hasLinkedEntity) = $this->_hasLinkedEntity($item); + if ($ret) { + return array($ret, null, null); + } + $template->setVariable('ReuploadPhotoOption', array('maxFileSize' => $maxFileSize, - 'uploadsPermitted' => $fileUploadsBool)); - + 'uploadsPermitted' => $fileUploadsBool, + 'hasLinkedEntity' => $hasLinkedEntity)); - return array(null, - 'modules/reupload/templates/ReuploadPhotoOption.tpl', - 'modules_reupload'); + return array(null, 'modules/reupload/templates/ReuploadPhotoOption.tpl', + 'modules_reupload'); } /** * @see ItemEditOption::isAppropriate */ function isAppropriate($item, $thumbnail) { - return array(null, - GalleryUtilities::isA($item, 'GalleryPhotoItem')); + return array(null, GalleryUtilities::isA($item, 'GalleryPhotoItem')); + } + + /** + * Determine if item is part of a linked(replica) set. + * @param GalleryItem $item + * @return array GalleryStatus a status code + * bool true if linked + * @access private + */ + function _hasLinkedEntity($item) { + $hasLink = $item->isLinked(); + if (!$hasLink) { + list ($ret, $linkedIds) = GalleryCoreApi::fetchEntitiesLinkedTo($item->getId()); + if ($ret) { + return array($ret, null); + } + $hasLink = !empty($linkedIds); + } + return array(null, $hasLink); } } ?> --- modules/reupload/templates/ReuploadPhotoOption.tpl 2007-11-20 03:45:20.000000000 +0000 +++ modules/reupload/templates/ReuploadPhotoOption.tpl 2007-10-20 03:50:01.000000000 +0000 @@ -1,5 +1,5 @@ {* - * $Revision: 1.2 $ + * $Revision: 16994 $ * If you want to customize this file, do not edit it directly since future upgrades * may overwrite it. Instead, copy it into a new directory called "local" and edit that * version. Gallery will look for that file first and use it if it exists. @@ -16,6 +16,9 @@ {g->text text="Upload a new revision of this picture instead of the old one."}

+ {if $ReuploadPhotoOption.hasLinkedEntity} + {g->text text="You cannot reupload this item because it shares its data file with other items."} + {else} {if $ReuploadPhotoOption.maxFileSize != 0}

{g->text text="Note: The new file cannot be larger than %s. If you want to upload a larger file you must ask your system administrator to allow larger uploads." @@ -44,4 +47,5 @@ {/if} {/if} + {/if}