protected function createPhoto($photo_id) { $cache_key = 'PinholePhoto.' . $photo_id; $photo = $this->app->getCacheValue($cache_key, 'photos'); if ($photo !== false) { $this->photo = $photo; $this->photo->setDatabase($this->app->db); } if ($this->photo === null) { $photo_class = SwatDBClassMap::get('PinholePhoto'); $this->photo = new $photo_class(); $this->photo->setDatabase($this->app->db); $this->photo->load($photo_id); $this->app->addCacheValue($this->photo, $cache_key, 'photos'); } if ($this->photo !== null && $this->photo->id !== null) { // ensure we are loading a photo in the current site instance $current_instance_id = $this->app->getInstanceId(); if ($current_instance_id === null) { $photo_instance_id = $this->photo->image_set->instance; } else { $photo_instance_id = $this->photo->image_set->instance->id; } if ($photo_instance_id != $current_instance_id) { throw new SiteNotFoundException(sprintf('Photo does not belong to the current instance: %s.', $this->app->getInstance()->shortname)); } elseif ($this->photo->status != PinholePhoto::STATUS_PUBLISHED) { throw new SiteNotFoundException('Photo is not published yet.'); } } else { // photo was not found throw new SiteNotFoundException(sprintf('No photo with the id %d exists.', $photo_id)); } }
protected function initPhoto() { $class_name = SwatDBClassMap::get('PinholePhoto'); $this->photo = new $class_name(); $this->photo->setDatabase($this->app->db); if ($this->id === null) { throw new AdminNoAccessException(Pinhole::_('A Photo id is required.')); } else { $instance_id = $this->app->getInstanceId(); if (!$this->photo->load($this->id)) { throw new AdminNotFoundException(sprintf(Pinhole::_('Photo with id “%s” not found.'), $this->id)); } elseif ($this->photo->image_set->instance !== null && $this->photo->image_set->instance->id != $instance_id) { throw new AdminNotFoundException(sprintf(Pinhole::_('Photo with id “%s” loaded ' . 'in the wrong instance.'), $this->id)); } } }