Skip to content

Laravel/fix sync file uuids #129

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2f5999d
Update dependency mockery/mockery to v1.5.0
renovate-bot Jan 24, 2022
c96ea95
Update typescript-eslint monorepo to v5.10.1
renovate-bot Jan 24, 2022
afdbe08
Fix ascending and descending being flipped in tables.
jameswilddev Jan 26, 2022
edee96c
It is now possible to horizontally align input components.
jameswilddev Jan 26, 2022
a7f9e5a
Fix not being able to clear searches.
jameswilddev Jan 26, 2022
513f76e
Merge pull request #116 from jameswilddev/renovate/typescript-eslint-…
jameswilddev Jan 26, 2022
a321ae0
Merge pull request #111 from jameswilddev/renovate/mockery-mockery-1.x
jameswilddev Jan 26, 2022
561c06f
Allow alignment of table columns.
jameswilddev Jan 26, 2022
cc6faa4
Merge branch 'master' of https://github.com/jameswilddev/react-native…
jameswilddev Jan 26, 2022
85fbedf
Float inputs can now have a fixed number of decimal places.
jameswilddev Jan 26, 2022
4f7c770
Update dependency metro-react-native-babel-preset to v0.67.0
renovate-bot Jan 26, 2022
a35c11a
Update dependency vimeo/psalm to v4.19.0
renovate-bot Jan 28, 2022
02a7bb2
Add a row press callback to tables.
jameswilddev Jan 28, 2022
d92378e
Merge pull request #117 from jameswilddev/renovate/metro-react-native…
jameswilddev Jan 28, 2022
2d72d7e
Merge pull request #118 from jameswilddev/renovate/vimeo-psalm-4.x
jameswilddev Jan 28, 2022
b231a2e
Merge branch 'master' of https://github.com/jameswilddev/react-native…
jameswilddev Jan 28, 2022
0ef9f1a
Add "setParameters" to stack routes.
jameswilddev Mar 17, 2022
51da450
Updated to use uuid instead of name for media uuids:
SteJaySulli Mar 18, 2022
9a0ae5e
Added font weight to buttons
SteJaySulli Mar 18, 2022
c150255
Merge branch 'master' into laravel/fix-sync-file-uuids
SteJaySulli Mar 18, 2022
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
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
{
"name": "jameswilddev",
"email": "jameswilddev@outlook.com"
},
{
"name": "Stephen J Sullivan",
"email": "stephen@sulli.work"
}
],
"require": {
Expand All @@ -25,7 +29,7 @@
},
"require-dev": {
"phpunit/phpunit": "9.5.13",
"vimeo/psalm": "4.18.1",
"mockery/mockery": "1.4.4"
"vimeo/psalm": "4.19.0",
"mockery/mockery": "1.5.0"
}
}
52 changes: 26 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 42 additions & 7 deletions laravel/src/SyncApiCollectionMediaCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,36 @@ class SyncApiCollectionMediaCollection implements SyncApiCollectionMediaCollecti

private int $syncCapabilities;

private function getMediaUuidField(): string
{
if (config('react-native-sync')) {
if (config('react-native-sync.uuid-fields')) {
if (config('react-native-sync.uuid-fields.media')) {
return config('react-native-sync.uuid-fields.media');
}
if (config('react-native-sync.uuid-fields.default')) {
return config('react-native-sync.uuid-fields.default');
}
}
}
return "uuid";
}

private function getModelUuidField(string $modelName): string
{
if (config('react-native-sync')) {
if (config('react-native-sync.uuid-fields')) {
if (config('react-native-sync.uuid-fields.models.' . $modelName)) {
return config('react-native-sync.uuid-fields.models.' . $modelName);
}
if (config('react-native-sync.uuid-fields.default')) {
return config('react-native-sync.uuid-fields.default');
}
}
}
return "uuid";
}

public function __construct(
SyncApiCollection $syncApiCollection,
string $name,
Expand Down Expand Up @@ -107,20 +137,25 @@ function (string $modelUuid, string $mediaUuid) {
$model = $this
->syncApiCollection
->modelClass::$scopeName()
->where('uuid', $modelUuid)
->where($this->getModelUuidField($this->syncApiCollection->modelClass), $modelUuid)
->first();

if ($model) {
$media = $model
->getMedia($this->name)
->where('name', $mediaUuid)
->where($this->getMediaUuidField(), $mediaUuid)
->first();

if ($media === null) {
// TODO why isn't this propagating
throw new ModelNotFoundException();
} else {
return redirect()->to($media->getTemporaryUrl(now()->addHour()));
if (config("filesystems.disks.{$media->disk}.driver" == "s3")) {
return redirect()->to($media->getTemporaryUrl(now()->addHour()));
} else {

return redirect()->to($media->getFullUrl());
}
}
} else {
throw new ModelNotFoundException();
Expand All @@ -138,13 +173,13 @@ function (string $modelUuid, string $mediaUuid) {
$model = $this
->syncApiCollection
->modelClass::$scopeName()
->where('uuid', $modelUuid)
->where($this->getModelUuidField($this->syncApiCollection->modelClass), $modelUuid)
->first();

if ($model) {
$media = $model
->getMedia($this->name)
->where('name', $mediaUuid)
->where($this->getMediaUuidField(), $mediaUuid)
->first();

if ($media === null) {
Expand Down Expand Up @@ -172,13 +207,13 @@ function (string $modelUuid, string $mediaUuid) {
$model = $this
->syncApiCollection
->modelClass::$scopeName()
->where('uuid', $modelUuid)
->where($this->getModelUuidField($this->syncApiCollection->modelClass), $modelUuid)
->first();

if ($model) {
$media = $model
->getMedia($this->name)
->where('name', $mediaUuid)
->where($this->getMediaUuidField(), $mediaUuid)
->first();

if ($media !== null) {
Expand Down
Loading