Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify photoId to photoID and albumId to albumID when found #2017

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions app/Factories/AlbumFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AlbumFactory
* Returns an existing instance of an album with the given ID or fails
* with an exception.
*
* @param string $albumId the ID of the requested album
* @param string $albumID the ID of the requested album
* @param bool $withRelations indicates if the relations of an
* album (i.e. photos and sub-albums,
* if applicable) shall be loaded, too.
Expand All @@ -53,21 +53,21 @@ class AlbumFactory
* @throws InvalidSmartIdException should not be thrown; otherwise this
* indicates an internal bug
*/
public function findAbstractAlbumOrFail(string $albumId, bool $withRelations = true): AbstractAlbum
public function findAbstractAlbumOrFail(string $albumID, bool $withRelations = true): AbstractAlbum
{
$smartAlbumType = SmartAlbumType::tryFrom($albumId);
$smartAlbumType = SmartAlbumType::tryFrom($albumID);
if ($smartAlbumType !== null) {
return $this->createSmartAlbum($smartAlbumType, $withRelations);
}

return $this->findBaseAlbumOrFail($albumId, $withRelations);
return $this->findBaseAlbumOrFail($albumID, $withRelations);
}

/**
* Returns an existing model instance of an album with the given ID or
* fails with an exception.
*
* @param string $albumId the ID of the requested album
* @param string $albumID the ID of the requested album
* @param bool $withRelations indicates if the relations of an
* album (i.e. photos and sub-albums,
* if applicable) shall be loaded, too.
Expand All @@ -78,7 +78,7 @@ public function findAbstractAlbumOrFail(string $albumId, bool $withRelations = t
*
* @noinspection PhpIncompatibleReturnTypeInspection
*/
public function findBaseAlbumOrFail(string $albumId, bool $withRelations = true): BaseAlbum
public function findBaseAlbumOrFail(string $albumID, bool $withRelations = true): BaseAlbum
{
$albumQuery = Album::query();
$tagAlbumQuery = TagAlbum::query();
Expand All @@ -91,12 +91,12 @@ public function findBaseAlbumOrFail(string $albumId, bool $withRelations = true)
try {
// PHPStan does not understand that `findOrFail` returns `BaseAlbum`, but assumes that it returns `Model`
// @phpstan-ignore-next-line
return $albumQuery->findOrFail($albumId);
return $albumQuery->findOrFail($albumID);
} catch (ModelNotFoundException) {
try {
return $tagAlbumQuery->findOrFail($albumId);
return $tagAlbumQuery->findOrFail($albumID);
} catch (ModelNotFoundException) {
throw (new ModelNotFoundException())->setModel(BaseAlbumImpl::class, [$albumId]);
throw (new ModelNotFoundException())->setModel(BaseAlbumImpl::class, [$albumID]);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Administration/SharingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public function setByAlbum(SetSharesByAlbumRequest $request): void
* Apply the modification.
*
* @param array<int,int> $userIds
* @param array<int,string> $albumIds
* @param array<int,string> $albumIDs
*
* @return void
*/
private function updateLinks(array $userIds, array $albumIds): void
private function updateLinks(array $userIds, array $albumIDs): void
{
/** @var Collection<User> $users */
$users = User::query()
Expand All @@ -90,7 +90,7 @@ private function updateLinks(array $userIds, array $albumIds): void
/** @var User $user */
foreach ($users as $user) {
$user->shared()->syncWithPivotValues(
$albumIds,
$albumIDs,
[
APC::IS_LINK_REQUIRED => false, // In sharing no required link is needed
APC::GRANTS_DOWNLOAD => Configs::getValueAsBool('grants_download'),
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Resources/SearchResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
*/
public function toArray($request)
{
$albumIds = $this->albums->reduce(fn (string $carry, Album $item) => $carry . $item->id, '');
$albumIDs = $this->albums->reduce(fn (string $carry, Album $item) => $carry . $item->id, '');
$tagAlbumsIds = $this->tag_albums->reduce(fn (string $carry, TagAlbum $item) => $carry . $item->id, '');
$photosIds = $this->photos->reduce(fn (string $carry, Photo $item) => $carry . $item->id, '');
// The checksum is used by the web front-end as an efficient way to
Expand All @@ -43,7 +43,7 @@ public function toArray($request)
// next character of a search term although the search result might
// stay the same, the GUI would flicker.
// The checksum is just over the id, we do not need a full conversion of the data.
$checksum = md5($albumIds . $tagAlbumsIds . $photosIds);
$checksum = md5($albumIDs . $tagAlbumsIds . $photosIds);

return [
'albums' => AlbumResource::collection($this->albums)->toArray($request),
Expand Down
12 changes: 6 additions & 6 deletions app/Jobs/ProcessImageJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ProcessImageJob implements ShouldQueue

public string $filePath;
public string $originalBaseName;
public ?string $albumId;
public ?string $albumID;
public int $userId;
public ?int $fileLastModifiedTime;

Expand All @@ -45,20 +45,20 @@ class ProcessImageJob implements ShouldQueue
*/
public function __construct(
ProcessableJobFile $file,
string|AbstractAlbum|null $albumId,
string|AbstractAlbum|null $albumID,
?int $fileLastModifiedTime,
) {
$this->filePath = $file->getPath();
$this->originalBaseName = $file->getOriginalBasename();
$this->albumId = is_string($albumId) ? $albumId : $albumId?->id;
$this->albumID = is_string($albumID) ? $albumID : $albumID?->id;
$this->userId = Auth::user()->id;
$this->fileLastModifiedTime = $fileLastModifiedTime;

// Set up our new history record.
$this->history = new JobHistory();
$this->history->owner_id = $this->userId;
$this->history->job = Str::limit('Process Image: ' . $this->originalBaseName, 200);
$this->history->parent_id = $this->albumId;
$this->history->parent_id = $this->albumID;
$this->history->status = JobStatus::READY;

$this->history->save();
Expand All @@ -82,8 +82,8 @@ public function handle(AlbumFactory $albumFactory): Photo
);

$album = null;
if ($this->albumId !== null) {
$album = $albumFactory->findAbstractAlbumOrFail($this->albumId);
if ($this->albumID !== null) {
$album = $albumFactory->findAbstractAlbumOrFail($this->albumID);
}

$photo = $create->add($copiedFile, $album, $this->fileLastModifiedTime);
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/Base/BaseSharingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@ protected function generateExpectedSmartAlbumJson(
];
}

protected function ensurePhotosWereTakenOnThisDay(string ...$photoIds): void
protected function ensurePhotosWereTakenOnThisDay(string ...$photoIDs): void
{
DB::table('photos')
->whereIn('id', $photoIds)
->whereIn('id', $photoIDs)
->update(['taken_at' => (Carbon::today())->subYear()->format('Y-m-d H:i:s.u')]);
}

protected function ensurePhotosWereNotTakenOnThisDay(string ...$photoIds): void
protected function ensurePhotosWereNotTakenOnThisDay(string ...$photoIDs): void
{
DB::table('photos')
->whereIn('id', $photoIds)
->whereIn('id', $photoIDs)
->update(['taken_at' => (Carbon::today())->subMonth()->format('Y-m-d H:i:s.u')]);
}
}
40 changes: 20 additions & 20 deletions tests/Feature/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public function tearDown(): void

public function testSearchPhotoByTitle(): void
{
$photoId1 = $this->photos_tests->upload(
$photoID1 = $this->photos_tests->upload(
AbstractTestCase::createUploadedFile(TestConstants::SAMPLE_FILE_NIGHT_IMAGE)
)->offsetGet('id');
$photoId2 = $this->photos_tests->upload(
$photoID2 = $this->photos_tests->upload(
AbstractTestCase::createUploadedFile(TestConstants::SAMPLE_FILE_MONGOLIA_IMAGE)
)->offsetGet('id');
$this->photos_tests->set_title($photoId1, 'photo search');
$this->photos_tests->set_title($photoId2, 'do not find me');
$this->photos_tests->set_title($photoID1, 'photo search');
$this->photos_tests->set_title($photoID2, 'do not find me');

$response = $this->runSearch('search');

Expand All @@ -68,7 +68,7 @@ public function testSearchPhotoByTitle(): void
'album_id' => null,
'aperture' => 'f/2.8',
'focal' => '16 mm',
'id' => $photoId1,
'id' => $photoID1,
'iso' => '1250',
'lens' => 'EF16-35mm f/2.8L USM',
'make' => 'Canon',
Expand Down Expand Up @@ -100,22 +100,22 @@ public function testSearchPhotoByTitle(): void
]);

$response->assertJsonMissing([
'id' => $photoId2,
'id' => $photoID2,
]);
}

public function testSearchPhotoByTag(): void
{
$photoId1 = $this->photos_tests->upload(
$photoID1 = $this->photos_tests->upload(
AbstractTestCase::createUploadedFile(TestConstants::SAMPLE_FILE_NIGHT_IMAGE)
)->offsetGet('id');
$photoId2 = $this->photos_tests->upload(
$photoID2 = $this->photos_tests->upload(
AbstractTestCase::createUploadedFile(TestConstants::SAMPLE_FILE_MONGOLIA_IMAGE)
)->offsetGet('id');
$this->photos_tests->set_title($photoId1, 'photo search');
$this->photos_tests->set_title($photoId2, 'do not find me');
$this->photos_tests->set_tag([$photoId1], ['search tag']);
$this->photos_tests->set_tag([$photoId2], ['other tag']);
$this->photos_tests->set_title($photoID1, 'photo search');
$this->photos_tests->set_title($photoID2, 'do not find me');
$this->photos_tests->set_tag([$photoID1], ['search tag']);
$this->photos_tests->set_tag([$photoID2], ['other tag']);

$response = $this->runSearch('search');

Expand All @@ -125,7 +125,7 @@ public function testSearchPhotoByTag(): void
'album_id' => null,
'aperture' => 'f/2.8',
'focal' => '16 mm',
'id' => $photoId1,
'id' => $photoID1,
'iso' => '1250',
'lens' => 'EF16-35mm f/2.8L USM',
'make' => 'Canon',
Expand Down Expand Up @@ -161,22 +161,22 @@ public function testSearchPhotoByTag(): void
]);

$response->assertJsonMissing([
'id' => $photoId2,
'id' => $photoID2,
]);
}

public function testSearchAlbumByTitle(): void
{
/** @var string $albumId1 */
$albumId1 = $this->albums_tests->add(null, 'search')->offsetGet('id');
/** @var string $albumId2 */
$albumId2 = $this->albums_tests->add(null, 'other')->offsetGet('id');
/** @var string $albumID1 */
$albumID1 = $this->albums_tests->add(null, 'search')->offsetGet('id');
/** @var string $albumID2 */
$albumID2 = $this->albums_tests->add(null, 'other')->offsetGet('id');

$response = $this->runSearch('search');

$response->assertJson([
'albums' => [[
'id' => $albumId1,
'id' => $albumID1,
'title' => 'search',
]],
]);
Expand All @@ -186,7 +186,7 @@ public function testSearchAlbumByTitle(): void
]);

$response->assertJsonMissing([
'id' => $albumId2,
'id' => $albumID2,
]);
}

Expand Down