|
2 | 2 |
|
3 | 3 | namespace nullthoughts\LaravelDataSync; |
4 | 4 |
|
| 5 | +use Illuminate\Support\Collection; |
| 6 | +use Illuminate\Support\Facades\File; |
5 | 7 | use Illuminate\Support\Facades\Storage; |
| 8 | +use Illuminate\Support\Str; |
6 | 9 | use nullthoughts\LaravelDataSync\Exceptions\ErrorUpdatingModelException; |
7 | 10 | use nullthoughts\LaravelDataSync\Exceptions\FileDirectoryNotFoundException; |
8 | 11 | use nullthoughts\LaravelDataSync\Exceptions\NoCriteriaException; |
9 | 12 | use nullthoughts\LaravelDataSync\Exceptions\NoRecordsInvalidJSONException; |
10 | | -use Illuminate\Support\Collection; |
11 | | -use Illuminate\Support\Facades\File; |
12 | | -use Illuminate\Support\Str; |
13 | 13 | use stdClass; |
14 | 14 |
|
15 | 15 | class Updater |
@@ -116,7 +116,7 @@ protected function getDirectory($path) |
116 | 116 | { |
117 | 117 | $directory = $path ?? config('data-sync.path', base_path('sync')); |
118 | 118 |
|
119 | | - if (!file_exists($directory) && !$this->remote) { |
| 119 | + if ($this->directoryMissingLocally($directory) || $this->directoryMissingRemotely($directory)) { |
120 | 120 | throw new FileDirectoryNotFoundException(); |
121 | 121 | } |
122 | 122 |
|
@@ -309,4 +309,24 @@ protected function resolveObjects(Collection $record) |
309 | 309 | return [$key => $value]; |
310 | 310 | })->toArray(); |
311 | 311 | } |
| 312 | + |
| 313 | + /** |
| 314 | + * @param \Illuminate\Config\Repository $directory |
| 315 | + * |
| 316 | + * @return bool |
| 317 | + */ |
| 318 | + protected function directoryMissingLocally($directory) |
| 319 | + { |
| 320 | + return !$this->remote && !file_exists($directory); |
| 321 | + } |
| 322 | + |
| 323 | + /** |
| 324 | + * @param \Illuminate\Config\Repository $directory |
| 325 | + * |
| 326 | + * @return bool |
| 327 | + */ |
| 328 | + protected function directoryMissingRemotely($directory) |
| 329 | + { |
| 330 | + return $this->remote && !Storage::disk($this->disk)->exists($directory); |
| 331 | + } |
312 | 332 | } |
0 commit comments