@@ -13,66 +13,66 @@ |
||
| 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 | - var_dump($image,$this->model->images); |
|
| 36 | - $image->delete(); |
|
| 37 | - continue; |
|
| 35 | + var_dump($image,$this->model->images); |
|
| 36 | + $image->delete(); |
|
| 37 | + continue; |
|
| 38 | 38 | } |
| 39 | 39 | $file = $image->file; |
| 40 | 40 | $md5File = ''; |
| 41 | 41 | if ($file->md5) { |
| 42 | - $md5File = $file->md5; |
|
| 42 | + $md5File = $file->md5; |
|
| 43 | 43 | } elseif (file_exists($file->getRealPath())) { |
| 44 | - $md5File = $file->md5 = md5_file($file->getRealPath()); |
|
| 45 | - $file->save(); |
|
| 44 | + $md5File = $file->md5 = md5_file($file->getRealPath()); |
|
| 45 | + $file->save(); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | if ($file && file_exists($file->getRealPath()) && $md5Cur == $md5File) { |
| 49 | - $notEq = false; |
|
| 50 | - $ids[] = $imageId; |
|
| 51 | - break; |
|
| 49 | + $notEq = false; |
|
| 50 | + $ids[] = $imageId; |
|
| 51 | + break; |
|
| 52 | + } |
|
| 52 | 53 | } |
| 53 | - } |
|
| 54 | - if ($notEq) { |
|
| 54 | + if ($notEq) { |
|
| 55 | 55 | $file_id = \App::$primary->files->uploadFromUrl($dir . '/' . $imagePath, ['accept_group' => 'image', 'upload_code' => 'MigrationUpload']); |
| 56 | 56 | if ($file_id) { |
| 57 | - $image = new \Ecommerce\Item\Image([ |
|
| 58 | - 'item_id' => $this->model->pk(), |
|
| 59 | - 'file_id' => $file_id |
|
| 60 | - ]); |
|
| 61 | - $image->save(); |
|
| 62 | - $ids[] = $image->id; |
|
| 57 | + $image = new \Ecommerce\Item\Image([ |
|
| 58 | + 'item_id' => $this->model->pk(), |
|
| 59 | + 'file_id' => $file_id |
|
| 60 | + ]); |
|
| 61 | + $image->save(); |
|
| 62 | + $ids[] = $image->id; |
|
| 63 | 63 | } |
| 64 | - } else { |
|
| 64 | + } else { |
|
| 65 | 65 | $image->weight = $key; |
| 66 | - } |
|
| 67 | - if ($image && !$this->model->image_file_id) { |
|
| 66 | + } |
|
| 67 | + if ($image && !$this->model->image_file_id) { |
|
| 68 | 68 | $this->model->image_file_id = $image->file_id; |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | } |
| 71 | 71 | foreach ($this->model->images as $imageId => $image) { |
| 72 | - if (!in_array($imageId, $ids)) { |
|
| 72 | + if (!in_array($imageId, $ids)) { |
|
| 73 | 73 | $image->delete(); |
| 74 | - } |
|
| 74 | + } |
|
| 75 | + } |
|
| 75 | 76 | } |
| 76 | - } |
|
| 77 | 77 | |
| 78 | 78 | } |
@@ -25,14 +25,14 @@ discard block |
||
| 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 | 30 | } |
| 31 | 31 | $notEq = true; |
| 32 | - $md5Cur = md5_file($dir . '/' . $imagePath); |
|
| 32 | + $md5Cur = md5_file($dir.'/'.$imagePath); |
|
| 33 | 33 | foreach ($this->model->images as $imageId => $image) { |
| 34 | 34 | if (!$image->file) { |
| 35 | - var_dump($image,$this->model->images); |
|
| 35 | + var_dump($image, $this->model->images); |
|
| 36 | 36 | $image->delete(); |
| 37 | 37 | continue; |
| 38 | 38 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | if ($notEq) { |
| 55 | - $file_id = \App::$primary->files->uploadFromUrl($dir . '/' . $imagePath, ['accept_group' => 'image', 'upload_code' => 'MigrationUpload']); |
|
| 55 | + $file_id = \App::$primary->files->uploadFromUrl($dir.'/'.$imagePath, ['accept_group' => 'image', 'upload_code' => 'MigrationUpload']); |
|
| 56 | 56 | if ($file_id) { |
| 57 | 57 | $image = new \Ecommerce\Item\Image([ |
| 58 | 58 | 'item_id' => $this->model->pk(), |