@@ -25,11 +25,11 @@ 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 | $file = $image->file; |
35 | 35 | $md5File = ''; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | } |
48 | 48 | } |
49 | 49 | if ($notEq) { |
50 | - $file_id = \App::$primary->files->uploadFromUrl($dir . '/' . $imagePath, ['accept_group' => 'image', 'upload_code' => 'MigrationUpload']); |
|
50 | + $file_id = \App::$primary->files->uploadFromUrl($dir.'/'.$imagePath, ['accept_group' => 'image', 'upload_code' => 'MigrationUpload']); |
|
51 | 51 | $image = new \Ecommerce\Item\Image([ |
52 | 52 | 'item_id' => $this->model->pk(), |
53 | 53 | 'file_id' => $file_id |
@@ -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 | } |
@@ -13,22 +13,22 @@ discard block |
||
13 | 13 | |
14 | 14 | class Image extends \Model { |
15 | 15 | |
16 | - static $objectName = 'Фото товара'; |
|
17 | - static $labels = [ |
|
18 | - 'file_id' => 'Изображение', |
|
19 | - 'item_id' => 'Товар', |
|
20 | - 'name' => 'Название', |
|
21 | - 'description' => 'Описание', |
|
22 | - ]; |
|
23 | - static $cols = [ |
|
24 | - 'file_id' => ['type' => 'image'], |
|
25 | - 'item_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'item'], |
|
26 | - 'name' => ['type' => 'text'], |
|
27 | - 'description' => ['type' => 'html'], |
|
28 | - 'weight' => ['type' => 'number'], |
|
29 | - ]; |
|
16 | + static $objectName = 'Фото товара'; |
|
17 | + static $labels = [ |
|
18 | + 'file_id' => 'Изображение', |
|
19 | + 'item_id' => 'Товар', |
|
20 | + 'name' => 'Название', |
|
21 | + 'description' => 'Описание', |
|
22 | + ]; |
|
23 | + static $cols = [ |
|
24 | + 'file_id' => ['type' => 'image'], |
|
25 | + 'item_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'item'], |
|
26 | + 'name' => ['type' => 'text'], |
|
27 | + 'description' => ['type' => 'html'], |
|
28 | + 'weight' => ['type' => 'number'], |
|
29 | + ]; |
|
30 | 30 | |
31 | - static function relations() { |
|
31 | + static function relations() { |
|
32 | 32 | return [ |
33 | 33 | 'item' => [ |
34 | 34 | 'col' => 'item_id', |
@@ -39,30 +39,30 @@ discard block |
||
39 | 39 | 'model' => 'Files\File' |
40 | 40 | ] |
41 | 41 | ]; |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | - static $dataManagers = [ |
|
45 | - 'manager' => [ |
|
46 | - 'name' => 'Фото товара', |
|
47 | - 'cols' => [ |
|
48 | - 'file_id', 'name' |
|
49 | - ] |
|
50 | - ] |
|
51 | - ]; |
|
52 | - static $forms = [ |
|
53 | - 'manager' => [ |
|
54 | - 'map' => [ |
|
55 | - ['name'], |
|
56 | - ['item_id', 'file_id'], |
|
57 | - ['description'] |
|
58 | - ] |
|
59 | - ] |
|
60 | - ]; |
|
44 | + static $dataManagers = [ |
|
45 | + 'manager' => [ |
|
46 | + 'name' => 'Фото товара', |
|
47 | + 'cols' => [ |
|
48 | + 'file_id', 'name' |
|
49 | + ] |
|
50 | + ] |
|
51 | + ]; |
|
52 | + static $forms = [ |
|
53 | + 'manager' => [ |
|
54 | + 'map' => [ |
|
55 | + ['name'], |
|
56 | + ['item_id', 'file_id'], |
|
57 | + ['description'] |
|
58 | + ] |
|
59 | + ] |
|
60 | + ]; |
|
61 | 61 | |
62 | - function beforeDelete() { |
|
62 | + function beforeDelete() { |
|
63 | 63 | if ($this->file) { |
64 | - $this->file->delete(); |
|
64 | + $this->file->delete(); |
|
65 | + } |
|
65 | 66 | } |
66 | - } |
|
67 | 67 | |
68 | 68 | } |