summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers/access.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-09-13 22:23:09 -0700
committerBharat Mediratta <bharat@menalto.com>2010-09-13 22:23:09 -0700
commit1a0d76c43e3545771ae3e1c6ad6ba255beeae32d (patch)
tree497e8d45e86983d3fd4929147f9728aed93b5740 /modules/gallery/helpers/access.php
parent19750cb0d5499920bb7786aa4f890dec84fc5a1f (diff)
When moving a single item, just copy its permissions from its parent
album. This is totally legal since an items permissions must be the same as its parent's, and it's much faster for large installs where a complete recalculation can be very costly. Should fix #1360.
Diffstat (limited to 'modules/gallery/helpers/access.php')
-rw-r--r--modules/gallery/helpers/access.php30
1 files changed, 26 insertions, 4 deletions
diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php
index 86ea9572..52a36298 100644
--- a/modules/gallery/helpers/access.php
+++ b/modules/gallery/helpers/access.php
@@ -263,15 +263,15 @@ class access_Core {
}
/**
- * Recalculate the permissions for a given item and its hierarchy. $item must be an album.
+ * Recalculate the permissions for an album's hierarchy.
*/
- static function recalculate_permissions($item) {
+ static function recalculate_album_permissions($album) {
foreach (self::_get_all_groups() as $group) {
foreach (ORM::factory("permission")->find_all() as $perm) {
if ($perm->name == "view") {
- self::_update_access_view_cache($group, $item);
+ self::_update_access_view_cache($group, $album);
} else {
- self::_update_access_non_view_cache($group, $perm->name, $item);
+ self::_update_access_non_view_cache($group, $perm->name, $album);
}
}
}
@@ -279,6 +279,28 @@ class access_Core {
}
/**
+ * Recalculate the permissions for a single photo.
+ */
+ static function recalculate_photo_permissions($photo) {
+ $parent = $photo->parent();
+ $parent_access_cache = ORM::factory("access_cache")->where("item_id", "=", $parent->id)->find();
+ $photo_access_cache = ORM::factory("access_cache")->where("item_id", "=", $photo->id)->find();
+ foreach (self::_get_all_groups() as $group) {
+ foreach (ORM::factory("permission")->find_all() as $perm) {
+ $field = "{$perm->name}_{$group->id}";
+ if ($perm->name == "view") {
+ $photo->$field = $parent->$field;
+ } else {
+ $photo_access_cache->$field = $parent_access_cache->$field;
+ }
+ }
+ }
+ $photo_access_cache->save();
+ $photo->save();
+ model_cache::clear();
+ }
+
+ /**
* Register a permission so that modules can use it.
*
* @param string $name The internal name for for this permission