From c40104149948afbd2379ab9b1201a7332b18213b Mon Sep 17 00:00:00 2001 From: nagatomi Date: Thu, 21 Nov 2024 19:36:54 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=81=AEobject=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Import.php | 28 ++++- src/Models/Entry.php | 44 ++++++-- src/POST/GoogleTranslate/CreateEntry.php | 134 ++++++++++++++++------- 3 files changed, 155 insertions(+), 51 deletions(-) diff --git a/src/Import.php b/src/Import.php index 19c90c7c..2efe50fd 100644 --- a/src/Import.php +++ b/src/Import.php @@ -98,7 +98,8 @@ protected function buildEntry(&$model, $entry) foreach ($entry->units as $new) { $clid = $new->clid; foreach ($model->units as $i => $current) { - if ($current['clid'] === $clid) { + var_dump($current->getId(), $clid); + if (is_array($current) && $current['clid'] === $clid) { $type = detectUnitTypeSpecifier($new->type); switch ($type) { case 'text': @@ -119,11 +120,36 @@ protected function buildEntry(&$model, $entry) $current['id'] = uniqueString(); $model->units[$i] = $current; break; + } elseif (is_object($current) && $current->getId() === $clid) { + var_dump($new->text); + $type = detectUnitTypeSpecifier($new->type); + switch ($type) { + case 'text': + $current->setField1($new->text); + break; + case 'table': + $current->setTable($new->table); + break; + case 'media': + case 'image': + $current->setCaption($new->caption); + $current->setAlt($new->alt); + break; + case 'file': + $current->setCaption($new->caption); + break; + } + $newId = $current->generateNewIdTrait(); + $current->setId($newId); + $model->units[$i] = $current; + break; } } } } + // var_dump($model); + // field if (property_exists($entry, 'fields') && is_array($entry->fields)) { foreach ($entry->fields as $field) { diff --git a/src/Models/Entry.php b/src/Models/Entry.php index 47ae99df..833ecfd9 100644 --- a/src/Models/Entry.php +++ b/src/Models/Entry.php @@ -3,11 +3,12 @@ namespace Acms\Plugins\GoogleTranslate\Models; use Acms\Plugins\GoogleTranslate\Contracts\Model; +use Acms\Services\Facades\Application; use DB; use SQL; use Field; use Common; -use Entry as EntryHelper; +use Acms\Services\Entry\Helper as EntryHelper; class Entry extends Model { @@ -132,14 +133,32 @@ public function load($item) $key = preg_replace('/entry_/', '', $key); $this->{$key} = $value; } + $this->fields = loadEntryField($this->id); - $this->units = loadColumn($this->id); - foreach ($this->units as & $unit) { - $type = detectUnitTypeSpecifier($unit['type']); - if ($type === 'custom') { - $unit['field'] = acmsUnserialize($unit['field']); + + // ablogcms v3.1.23 からリファクタリングによりメソッドがなくなっている問題の解決 + if (method_exists(EntryHelper::class, 'saveColumn')) { + $this->units = loadColumn($this->id); + foreach ($this->units as & $unit) { + $type = detectUnitTypeSpecifier($unit['type']); + if ($type === 'custom') { + $unit['field'] = acmsUnserialize($unit['field']); + } + $unit['id'] = uniqueString(); + } + } else { + /** @var \Acms\Services\Unit\Repository $unitService */ + $unitService = Application::make('unit-repository'); + $this->units = $unitService->loadUnits($this->id); + + foreach ($this->units as & $unit) { + $type = detectUnitTypeSpecifier($unit->getType()); + if ($type === 'custom') { + $unit->setField6(acmsUnserialize($unit->getField6())); + } + $newId = $unit->generateNewIdTrait(); + $unit->setId($newId); } - $unit['id'] = uniqueString(); } } @@ -168,7 +187,16 @@ public function save() $DB->query($SQL->get(dsn()), 'exec'); } - EntryHelper::saveColumn($this->units, $this->id, $this->blog_id); + // ablogcms v3.1.23 からリファクタリングによりメソッドがなくなっている問題の解決 + if (method_exists(EntryHelper::class, 'saveColumn')) { + $entryHelper = new EntryHelper(); + $entryHelper->saveColumn($this->units, $this->id, $this->blog_id); + } else { + $unitRepository = Application::make('unit-repository'); + assert($unitRepository instanceof \Acms\Services\Unit\Repository); + $unitRepository->saveUnits($this->units, $this->id, $this->blog_id); + } + Common::saveField('eid', $this->id, $this->fields); Common::saveFulltext('eid', $this->id, Common::loadEntryFulltext($this->id)); } diff --git a/src/POST/GoogleTranslate/CreateEntry.php b/src/POST/GoogleTranslate/CreateEntry.php index 79fa7022..b4199c31 100644 --- a/src/POST/GoogleTranslate/CreateEntry.php +++ b/src/POST/GoogleTranslate/CreateEntry.php @@ -109,27 +109,52 @@ protected function googleTranslate($targetBid, $newEid) protected function addToTranslationUnits($units, $googleTranslate) { foreach ($units as $i => $unit) { - $type = detectUnitTypeSpecifier($unit['type']); - switch ($type) { - case 'text': - $tagType = $this->getTextUnitFormat($unit['tag']); - if ($tagType === 'html') { - $googleTranslate->addHtml('unit_text_' . $i, $this->newLineEscape($unit['text'])); - } elseif ($tagType === 'text') { - $googleTranslate->addText('unit_text_' . $i, $unit['text']); - } - break; - case 'table': - $googleTranslate->addHtml('unit_table_' . $i, $unit['table']); - break; - case 'media': - case 'image': - $googleTranslate->addText('unit_caption_' . $i, $unit['caption']); - $googleTranslate->addText('unit_alt_' . $i, $unit['alt']); - break; - case 'file': - $googleTranslate->addText('unit_caption_' . $i, $unit['caption']); - break; + if (is_array($unit)) { + $type = detectUnitTypeSpecifier($unit['type']); + switch ($type) { + case 'text': + $tagType = $this->getTextUnitFormat($unit['tag']); + if ($tagType === 'html') { + $googleTranslate->addHtml('unit_text_' . $i, $this->newLineEscape($unit['text'])); + } elseif ($tagType === 'text') { + $googleTranslate->addText('unit_text_' . $i, $unit['text']); + } + break; + case 'table': + $googleTranslate->addHtml('unit_table_' . $i, $unit['table']); + break; + case 'media': + case 'image': + $googleTranslate->addText('unit_caption_' . $i, $unit['caption']); + $googleTranslate->addText('unit_alt_' . $i, $unit['alt']); + break; + case 'file': + $googleTranslate->addText('unit_caption_' . $i, $unit['caption']); + break; + } + } elseif (is_object($unit)) { + $type = detectUnitTypeSpecifier($unit->getType()); + switch ($type) { + case 'text': + $tagType = $this->getTextUnitFormat($unit->getTag()); + if ($tagType === 'html') { + $googleTranslate->addHtml('unit_text_' . $i, $this->newLineEscape($unit->getText())); + } elseif ($tagType === 'text') { + $googleTranslate->addText('unit_text_' . $i, $unit->getText()); + } + break; + case 'table': + $googleTranslate->addHtml('unit_table_' . $i, $unit->getTable()); + break; + case 'media': + case 'image': + $googleTranslate->addText('unit_caption_' . $i, $unit->getCaption()); + $googleTranslate->addText('unit_alt_' . $i, $unit->getAlt()); + break; + case 'file': + $googleTranslate->addText('unit_caption_' . $i, $unit->getCaption()); + break; + } } } } @@ -141,27 +166,52 @@ protected function addToTranslationUnits($units, $googleTranslate) protected function getTranslationUnits(&$units, $googleTranslate) { foreach ($units as $i => & $unit) { - $type = detectUnitTypeSpecifier($unit['type']); - switch ($type) { - case 'text': - $tagType = $this->getTextUnitFormat($unit['tag']); - if ($tagType === 'html') { - $unit['text'] = $this->newLineUnEscape($googleTranslate->getHtml('unit_text_' . $i)); - } elseif ($tagType === 'text') { - $unit['text'] = $googleTranslate->getText('unit_text_' . $i); - } - break; - case 'table': - $unit['table'] = $googleTranslate->getHtml('unit_table_' . $i); - break; - case 'media': - case 'image': - $unit['caption'] = $googleTranslate->getText('unit_caption_' . $i); - $unit['alt'] = $googleTranslate->getText('unit_alt_' . $i); - break; - case 'file': - $unit['caption'] = $googleTranslate->getText('unit_caption_' . $i); - break; + if(is_array($unit)) { + $type = detectUnitTypeSpecifier($unit['type']); + switch ($type) { + case 'text': + $tagType = $this->getTextUnitFormat($unit['tag']); + if ($tagType === 'html') { + $unit['text'] = $this->newLineUnEscape($googleTranslate->getHtml('unit_text_' . $i)); + } elseif ($tagType === 'text') { + $unit['text'] = $googleTranslate->getText('unit_text_' . $i); + } + break; + case 'table': + $unit['table'] = $googleTranslate->getHtml('unit_table_' . $i); + break; + case 'media': + case 'image': + $unit['caption'] = $googleTranslate->getText('unit_caption_' . $i); + $unit['alt'] = $googleTranslate->getText('unit_alt_' . $i); + break; + case 'file': + $unit['caption'] = $googleTranslate->getText('unit_caption_' . $i); + break; + } + } elseif (is_object($unit)) { + $type = detectUnitTypeSpecifier($unit->getType()); + switch ($type) { + case 'text': + $tagType = $this->getTextUnitFormat($unit->getTag()); + if ($tagType === 'html') { + $unit->setText($this->newLineUnEscape($googleTranslate->getHtml('unit_text_' . $i))); + } elseif ($tagType === 'text') { + $unit->setText($googleTranslate->getText('unit_text_' . $i)); + } + break; + case 'table': + $unit->setTable($googleTranslate->getHtml('unit_table_' . $i)); + break; + case 'media': + case 'image': + $unit->setCaption($googleTranslate->getText('unit_caption_' . $i)); + $unit->setAlt($googleTranslate->getText('unit_alt_' . $i)); + break; + case 'file': + $unit->setCaption($googleTranslate->getText('unit_caption_' . $i)); + break; + } } } } From e2206f17db6d383db52fd6e6fe17aeb1730af43b Mon Sep 17 00:00:00 2001 From: atsu666 Date: Thu, 21 Nov 2024 20:16:28 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=89=E6=99=82=E3=81=AB=E3=83=A6=E3=83=8B?= =?UTF-8?q?=E3=83=83=E3=83=88ID=E3=82=92=E6=96=B0=E8=A6=8FID=E3=81=AB?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=81=97=E3=81=A6=E3=81=84=E3=81=9F=E5=95=8F?= =?UTF-8?q?=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Models/Entry.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Models/Entry.php b/src/Models/Entry.php index 833ecfd9..a325664c 100644 --- a/src/Models/Entry.php +++ b/src/Models/Entry.php @@ -156,8 +156,7 @@ public function load($item) if ($type === 'custom') { $unit->setField6(acmsUnserialize($unit->getField6())); } - $newId = $unit->generateNewIdTrait(); - $unit->setId($newId); + $unit->setTempId(uniqueString()); } } } From 5a02f48c2408689b6ea9331a1439a059997c89dd Mon Sep 17 00:00:00 2001 From: nagatomi Date: Thu, 21 Nov 2024 20:37:58 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=82=AA=E3=83=96=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88=E3=81=AE?= =?UTF-8?q?image=E3=81=A8table=E3=81=A8=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=81=A8=E6=9C=AC=E6=96=87=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Import.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Import.php b/src/Import.php index 2efe50fd..6cffa252 100644 --- a/src/Import.php +++ b/src/Import.php @@ -98,7 +98,6 @@ protected function buildEntry(&$model, $entry) foreach ($entry->units as $new) { $clid = $new->clid; foreach ($model->units as $i => $current) { - var_dump($current->getId(), $clid); if (is_array($current) && $current['clid'] === $clid) { $type = detectUnitTypeSpecifier($new->type); switch ($type) { @@ -121,22 +120,21 @@ protected function buildEntry(&$model, $entry) $model->units[$i] = $current; break; } elseif (is_object($current) && $current->getId() === $clid) { - var_dump($new->text); $type = detectUnitTypeSpecifier($new->type); switch ($type) { case 'text': $current->setField1($new->text); break; case 'table': - $current->setTable($new->table); + $current->setField1($new->table); break; case 'media': case 'image': - $current->setCaption($new->caption); - $current->setAlt($new->alt); + $current->setField1($new->caption); + $current->setField4($new->alt); break; case 'file': - $current->setCaption($new->caption); + $current->setField1($new->caption); break; } $newId = $current->generateNewIdTrait(); @@ -148,8 +146,6 @@ protected function buildEntry(&$model, $entry) } } - // var_dump($model); - // field if (property_exists($entry, 'fields') && is_array($entry->fields)) { foreach ($entry->fields as $field) { From d089b388af7987536378e15e344b90cdf9a6744e Mon Sep 17 00:00:00 2001 From: nagatomi Date: Thu, 21 Nov 2024 20:40:57 +0900 Subject: [PATCH 4/5] =?UTF-8?q?Lint=E3=82=A8=E3=83=A9=E3=83=BC=E8=A7=A3?= =?UTF-8?q?=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/POST/GoogleTranslate/CreateEntry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/POST/GoogleTranslate/CreateEntry.php b/src/POST/GoogleTranslate/CreateEntry.php index b4199c31..69a24475 100644 --- a/src/POST/GoogleTranslate/CreateEntry.php +++ b/src/POST/GoogleTranslate/CreateEntry.php @@ -166,7 +166,7 @@ protected function addToTranslationUnits($units, $googleTranslate) protected function getTranslationUnits(&$units, $googleTranslate) { foreach ($units as $i => & $unit) { - if(is_array($unit)) { + if (is_array($unit)) { $type = detectUnitTypeSpecifier($unit['type']); switch ($type) { case 'text': From b1f7ca24a03f8f06a1eed12eb646b831e74bb288 Mon Sep 17 00:00:00 2001 From: nagatomi Date: Tue, 26 Nov 2024 18:28:10 +0900 Subject: [PATCH 5/5] =?UTF-8?q?media=E3=81=8C=E7=BF=BB=E8=A8=B3=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=81=A8=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E3=81=AA=E3=81=84=E3=82=AA=E3=83=96=E3=82=B8=E3=82=A7?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Engine.php | 4 +-- src/Import.php | 6 ++-- src/POST/GoogleTranslate/CreateEntry.php | 46 ------------------------ 3 files changed, 6 insertions(+), 50 deletions(-) diff --git a/src/Engine.php b/src/Engine.php index 1700ed9d..253a7735 100644 --- a/src/Engine.php +++ b/src/Engine.php @@ -144,7 +144,7 @@ public function buildEntryData($entry, $targetField, $detail = true) ]; if ($detail) { $item['fields'] = $this->buildFieldData($eid, $targetField); - $item['units'] = $this->buildUnitDate($eid); + $item['units'] = $this->buildUnitData($eid); } return $item; } @@ -347,7 +347,7 @@ protected function buildFieldData($eid, $targetField) * @param int $eid * @return array */ - protected function buildUnitDate($eid) + protected function buildUnitData($eid) { $item = []; $units = loadColumn($eid); diff --git a/src/Import.php b/src/Import.php index 6cffa252..524a72e5 100644 --- a/src/Import.php +++ b/src/Import.php @@ -129,6 +129,9 @@ protected function buildEntry(&$model, $entry) $current->setField1($new->table); break; case 'media': + $current->setField2($new->caption); + $current->setField3($new->alt); + break; case 'image': $current->setField1($new->caption); $current->setField4($new->alt); @@ -137,8 +140,7 @@ protected function buildEntry(&$model, $entry) $current->setField1($new->caption); break; } - $newId = $current->generateNewIdTrait(); - $current->setId($newId); + $current->setTempId(uniqueString()); $model->units[$i] = $current; break; } diff --git a/src/POST/GoogleTranslate/CreateEntry.php b/src/POST/GoogleTranslate/CreateEntry.php index 69a24475..9f9eb53b 100644 --- a/src/POST/GoogleTranslate/CreateEntry.php +++ b/src/POST/GoogleTranslate/CreateEntry.php @@ -132,29 +132,6 @@ protected function addToTranslationUnits($units, $googleTranslate) $googleTranslate->addText('unit_caption_' . $i, $unit['caption']); break; } - } elseif (is_object($unit)) { - $type = detectUnitTypeSpecifier($unit->getType()); - switch ($type) { - case 'text': - $tagType = $this->getTextUnitFormat($unit->getTag()); - if ($tagType === 'html') { - $googleTranslate->addHtml('unit_text_' . $i, $this->newLineEscape($unit->getText())); - } elseif ($tagType === 'text') { - $googleTranslate->addText('unit_text_' . $i, $unit->getText()); - } - break; - case 'table': - $googleTranslate->addHtml('unit_table_' . $i, $unit->getTable()); - break; - case 'media': - case 'image': - $googleTranslate->addText('unit_caption_' . $i, $unit->getCaption()); - $googleTranslate->addText('unit_alt_' . $i, $unit->getAlt()); - break; - case 'file': - $googleTranslate->addText('unit_caption_' . $i, $unit->getCaption()); - break; - } } } } @@ -189,29 +166,6 @@ protected function getTranslationUnits(&$units, $googleTranslate) $unit['caption'] = $googleTranslate->getText('unit_caption_' . $i); break; } - } elseif (is_object($unit)) { - $type = detectUnitTypeSpecifier($unit->getType()); - switch ($type) { - case 'text': - $tagType = $this->getTextUnitFormat($unit->getTag()); - if ($tagType === 'html') { - $unit->setText($this->newLineUnEscape($googleTranslate->getHtml('unit_text_' . $i))); - } elseif ($tagType === 'text') { - $unit->setText($googleTranslate->getText('unit_text_' . $i)); - } - break; - case 'table': - $unit->setTable($googleTranslate->getHtml('unit_table_' . $i)); - break; - case 'media': - case 'image': - $unit->setCaption($googleTranslate->getText('unit_caption_' . $i)); - $unit->setAlt($googleTranslate->getText('unit_alt_' . $i)); - break; - case 'file': - $unit->setCaption($googleTranslate->getText('unit_caption_' . $i)); - break; - } } } }