2021-11-11 00:07:46 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2023-01-01 15:36:24 +01:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2021-11-11 00:07:46 +01:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Module\Api\Friendica\Photoalbum;
|
|
|
|
|
2021-11-12 20:03:27 +01:00
|
|
|
use Friendica\DI;
|
2021-11-11 00:07:46 +01:00
|
|
|
use Friendica\Model\Photo;
|
|
|
|
use Friendica\Module\BaseApi;
|
|
|
|
use Friendica\Network\HTTPException\BadRequestException;
|
|
|
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API endpoint: /api/friendica/photoalbum/update
|
|
|
|
*/
|
|
|
|
class Update extends BaseApi
|
|
|
|
{
|
2021-11-30 22:41:10 +01:00
|
|
|
protected function post(array $request = [])
|
2021-11-11 00:07:46 +01:00
|
|
|
{
|
2023-10-11 15:30:42 +02:00
|
|
|
$this->checkAllowedScope(self::SCOPE_WRITE);
|
2021-11-11 00:07:46 +01:00
|
|
|
$uid = self::getCurrentUserID();
|
|
|
|
|
2021-11-28 13:22:27 +01:00
|
|
|
$request = $this->getRequest([
|
2021-11-11 00:07:46 +01:00
|
|
|
'album' => '', // Current album name
|
|
|
|
'album_new' => '', // New album name
|
2021-11-28 00:30:41 +01:00
|
|
|
], $request);
|
2021-11-11 00:07:46 +01:00
|
|
|
|
|
|
|
// we do not allow calls without album string
|
2021-11-12 21:08:36 +01:00
|
|
|
if (empty($request['album'])) {
|
2021-11-11 00:07:46 +01:00
|
|
|
throw new BadRequestException("no albumname specified");
|
|
|
|
}
|
2021-11-12 21:08:36 +01:00
|
|
|
if (empty($request['album_new'])) {
|
2021-11-11 00:07:46 +01:00
|
|
|
throw new BadRequestException("no new albumname specified");
|
|
|
|
}
|
|
|
|
// check if album is existing
|
|
|
|
if (!Photo::exists(['uid' => $uid, 'album' => $request['album']])) {
|
|
|
|
throw new BadRequestException("album not available");
|
|
|
|
}
|
|
|
|
// now let's update all photos to the albumname
|
|
|
|
$result = Photo::update(['album' => $request['album_new']], ['uid' => $uid, 'album' => $request['album']]);
|
|
|
|
|
|
|
|
// return success of updating or error message
|
|
|
|
if ($result) {
|
2022-12-13 19:27:23 +01:00
|
|
|
Photo::clearAlbumCache($uid);
|
2021-11-11 00:07:46 +01:00
|
|
|
$answer = ['result' => 'updated', 'message' => 'album `' . $request['album'] . '` with all containing photos has been renamed to `' . $request['album_new'] . '`.'];
|
2023-09-22 16:14:46 +02:00
|
|
|
$this->response->addFormattedContent('photoalbum_update', ['$result' => $answer], $this->parameters['extension'] ?? null);
|
2021-11-11 00:07:46 +01:00
|
|
|
} else {
|
|
|
|
throw new InternalServerErrorException("unknown error - updating in database failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|