private function save($data)
 {
     if (!$this->id) {
         $this->log('album_create', 1);
         $this->id = $this->album_model->add($data);
     } else {
         $album = $this->album_model->getById($this->id);
         if (!$album) {
             throw new Exception("Album doesn't exist");
         }
         if ($album['parent_id']) {
             $parent = $this->album_model->getById($album['parent_id']);
             if ($parent && $parent['status'] <= 0) {
                 $data['status'] = 0;
             }
         }
         $name = $album['name'];
         if (empty($data['name'])) {
             $data['name'] = $name;
         }
         if ($album['type'] != photosAlbumModel::TYPE_DYNAMIC && isset($data['conditions'])) {
             unset($data['conditions']);
         }
         if ($data['status'] <= 0) {
             if (isset($data['url']) && !$data['url']) {
                 unset($data['url']);
             }
         } else {
             if (!isset($data['url']) || !strlen($data['url'])) {
                 $data['url'] = photosPhoto::suggestUrl($data['name']);
             }
         }
         $this->album_model->update($this->id, $data);
         $album_params = new photosAlbumParamsModel();
         $album_params->set($this->id, $data['params']);
     }
     $album_rights_model = new photosAlbumRightsModel();
     if ($data['status'] <= 0 && $data['group_ids']) {
         $album_rights_model->setRights($this->id, $data['group_ids']);
     } else {
         $album_rights_model->setRights($this->id, 0);
     }
 }
 public function execute()
 {
     $id = $this->get('id', true);
     $album_model = new photosAlbumModel();
     $album = $album_model->getById($id);
     if ($album) {
         $album_rights_model = new photosAlbumRightsModel();
         if (!$album_rights_model->checkRights($id, true)) {
             throw new waAPIException('access_denied', 403);
         }
         $data = waRequest::post();
         if (isset($data['parent_id']) && $album['parent_id'] != $data['parent_id']) {
             if (!$album_model->getById($data['parent_id'])) {
                 throw new waAPIException('invalid_param', 'Parent album not found', 404);
             }
             if (!$album_model->move($id, null, $data['parent_id'])) {
                 throw new waAPIException('server_error', 500);
             }
         }
         if (isset($data['type'])) {
             unset($data['type']);
         }
         if ($album_model->update($id, $data)) {
             // correct rights
             $album = $album_model->getById($id);
             $group_ids = array(0);
             if ($data['status'] == -1) {
                 $group_ids = array(-wa()->getUser()->getId());
             }
             $album_rights_model = new photosAlbumRightsModel();
             $album_rights_model->setRights($id, $group_ids);
             $method = new photosAlbumGetInfoMethod();
             $this->response = $method->getResponse(true);
         } else {
             throw new waAPIException('server_error', 500);
         }
     } else {
         throw new waAPIException('invalid_param', 'Album not found', 404);
     }
 }