@@ -13,65 +13,65 @@ |
||
13 | 13 | |
14 | 14 | class Images extends \Migrations\Parser { |
15 | 15 | |
16 | - public function parse() { |
|
16 | + public function parse() { |
|
17 | 17 | if (is_null($this->data)) { |
18 | - return; |
|
18 | + return; |
|
19 | 19 | } |
20 | 20 | $value = $this->data; |
21 | 21 | if (!is_array($value)) { |
22 | - $value = [$value]; |
|
22 | + $value = [$value]; |
|
23 | 23 | } |
24 | 24 | $ids = []; |
25 | 25 | $dir = pathinfo($this->object->walker->migtarionLog->source, PATHINFO_DIRNAME); |
26 | 26 | $this->model->image_file_id = 0; |
27 | 27 | foreach ($value as $key => $imagePath) { |
28 | - if (!$imagePath || !file_exists($dir . '/' . $imagePath)) { |
|
28 | + if (!$imagePath || !file_exists($dir . '/' . $imagePath)) { |
|
29 | 29 | continue; |
30 | - } |
|
31 | - $notEq = true; |
|
32 | - $md5Cur = md5_file($dir . '/' . $imagePath); |
|
33 | - foreach ($this->model->images as $imageId => $image) { |
|
30 | + } |
|
31 | + $notEq = true; |
|
32 | + $md5Cur = md5_file($dir . '/' . $imagePath); |
|
33 | + foreach ($this->model->images as $imageId => $image) { |
|
34 | 34 | if (!$image->file) { |
35 | - $image->delete(); |
|
36 | - continue; |
|
35 | + $image->delete(); |
|
36 | + continue; |
|
37 | 37 | } |
38 | 38 | $file = $image->file; |
39 | 39 | $md5File = ''; |
40 | 40 | if ($file->md5) { |
41 | - $md5File = $file->md5; |
|
41 | + $md5File = $file->md5; |
|
42 | 42 | } elseif (file_exists($file->getRealPath())) { |
43 | - $md5File = $file->md5 = md5_file($file->getRealPath()); |
|
44 | - $file->save(); |
|
43 | + $md5File = $file->md5 = md5_file($file->getRealPath()); |
|
44 | + $file->save(); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | if ($file && file_exists($file->getRealPath()) && $md5Cur == $md5File) { |
48 | - $notEq = false; |
|
49 | - $ids[] = $imageId; |
|
50 | - break; |
|
48 | + $notEq = false; |
|
49 | + $ids[] = $imageId; |
|
50 | + break; |
|
51 | + } |
|
51 | 52 | } |
52 | - } |
|
53 | - if ($notEq) { |
|
53 | + if ($notEq) { |
|
54 | 54 | $file_id = \App::$primary->files->uploadFromUrl($dir . '/' . $imagePath, ['accept_group' => 'image', 'upload_code' => 'MigrationUpload']); |
55 | 55 | if ($file_id) { |
56 | - $image = new \Ecommerce\Item\Image([ |
|
57 | - 'item_id' => $this->model->pk(), |
|
58 | - 'file_id' => $file_id |
|
59 | - ]); |
|
60 | - $image->save(); |
|
61 | - $ids[] = $image->id; |
|
56 | + $image = new \Ecommerce\Item\Image([ |
|
57 | + 'item_id' => $this->model->pk(), |
|
58 | + 'file_id' => $file_id |
|
59 | + ]); |
|
60 | + $image->save(); |
|
61 | + $ids[] = $image->id; |
|
62 | 62 | } |
63 | - } else { |
|
63 | + } else { |
|
64 | 64 | $image->weight = $key; |
65 | - } |
|
66 | - if ($image && !$this->model->image_file_id) { |
|
65 | + } |
|
66 | + if ($image && !$this->model->image_file_id) { |
|
67 | 67 | $this->model->image_file_id = $image->file_id; |
68 | - } |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | foreach ($this->model->images as $imageId => $image) { |
71 | - if (!in_array($imageId, $ids)) { |
|
71 | + if (!in_array($imageId, $ids)) { |
|
72 | 72 | $image->delete(); |
73 | - } |
|
73 | + } |
|
74 | + } |
|
74 | 75 | } |
75 | - } |
|
76 | 76 | |
77 | 77 | } |