0byt3m1n1
Path:
/
data
/
applications
/
aps
/
gallery
/
2.2-08
/
htdocs
/
modules
/
panorama
/
classes
/
[
Home
]
File: PanoramaUpgradeHelper.class
<?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2007 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ /** * A helper class for the upgrading Panorama module. * @package Panorama * @subpackage Classes * @author Alan Harder <alan.harder@sun.com> * @version $Revision: 15513 $ * @static */ class PanoramaUpgradeHelper { /** * Switch back from using PanoramaPhotoItem and PanoramaDerivativeImage to * the base classes, now that we're using renderers. This can get deleted * after GalleryCoreApi moves to 8.x because we're doing the same thing in * the core module. * * NOTE: If you change this code, you should update the matching block * in modules/core/CoreModuleExtras.inc * * @return object GalleryStatus a status code */ function revertEntities() { global $gallery; $query = ' SELECT [GalleryEntity::id], [GalleryEntity::entityType] FROM [GalleryEntity] WHERE [GalleryEntity::entityType] IN (\'PanoramaPhotoItem\', \'PanoramaDerivativeImage\') '; list ($ret, $searchResults) = $gallery->search($query, array()); if ($ret) { return $ret; } if (!$searchResults->resultCount()) { return null; } $photos = array(); $derivatives = array(); while ($result = $searchResults->nextResult()) { $gallery->guaranteeTimeLimit(30); if ($result[1] == 'PanoramaPhotoItem') { $photos[] = $result[0]; } else { $derivatives[] = $result[0]; } } $storage =& $gallery->getStorage(); /* Switch PanoramaPhotoItems back to GalleryPhotoItems */ while ($photos) { $ids = array_splice($photos, 0, 500); $markers = GalleryUtilities::makeMarkers($ids); $query = "UPDATE [GalleryItem] SET [::renderer] = 'PanoramaRenderer' " . "WHERE [GalleryItem::id] IN ($markers)"; $ret = $storage->execute($query, $ids); if ($ret) { return $ret; } $query = "UPDATE [GalleryEntity] SET [::entityType] = 'GalleryPhotoItem' " . "WHERE [GalleryEntity::id] IN ($markers)"; $ret = $storage->execute($query, $ids); if ($ret) { return $ret; } } /* Switch PanoramaDerivativeImage back to GalleryDerivativeImage */ while ($derivatives) { $ids = array_splice($derivatives, 0, 500); $markers = GalleryUtilities::makeMarkers($ids); $query = "UPDATE [GalleryEntity] SET [::entityType] = 'GalleryDerivativeImage' " . "WHERE [GalleryEntity::id] IN ($markers)"; $ret = $storage->execute($query, $ids); if ($ret) { return $ret; } } /* * Flush the entity cache because we've changed types * Swallow any errors here; they're going to be recoverable. * @todo Refactor this together with the code from the upgrader */ $cacheBaseDir = $gallery->getConfig('data.gallery.cache'); $platform =& $gallery->getPlatform(); @$platform->recursiveRmDir("$cacheBaseDir/entity"); return null; } } ?>