From bc17030f9d7c52f3fd2adacbff1cad9ebd777117 Mon Sep 17 00:00:00 2001 From: aynsix Date: Wed, 8 Dec 2021 15:51:49 +0300 Subject: [PATCH] PHRAS-3604 remove deleted record from a publication --- .../Phrasea/Model/Entities/FeedItem.php | 17 -- lib/classes/patch/415PHRAS3604.php | 81 ++++++++++ lib/classes/record/adapter.php | 9 ++ templates/web/prod/results/item.html.twig | 152 +++++++++--------- 4 files changed, 165 insertions(+), 94 deletions(-) create mode 100644 lib/classes/patch/415PHRAS3604.php diff --git a/lib/Alchemy/Phrasea/Model/Entities/FeedItem.php b/lib/Alchemy/Phrasea/Model/Entities/FeedItem.php index 16f0e24208..054622a7c4 100644 --- a/lib/Alchemy/Phrasea/Model/Entities/FeedItem.php +++ b/lib/Alchemy/Phrasea/Model/Entities/FeedItem.php @@ -230,21 +230,4 @@ class FeedItem { return new \record_adapter($app, $this->getSbasId(), $this->getRecordId(), $this->getOrd()); } - - /** - * @param Application $app - * @return bool - */ - public function isRecordExist(Application $app) - { - try { - return (new \record_adapter($app, $this->getSbasId(), $this->getRecordId(), $this->getOrd())) != null ? true : false ; - } catch (\Exception $e) { - // remove feeditem from the feed entry if record don't exist - $app['orm.em']->remove($this); - $app['orm.em']->flush(); - - return false; - } - } } diff --git a/lib/classes/patch/415PHRAS3604.php b/lib/classes/patch/415PHRAS3604.php new file mode 100644 index 0000000000..54a97b3139 --- /dev/null +++ b/lib/classes/patch/415PHRAS3604.php @@ -0,0 +1,81 @@ +release; + } + + /** + * @inheritDoc + */ + public function concern() + { + return $this->concern; + } + + /** + * @inheritDoc + */ + public function require_all_upgrades() + { + return false; + } + + /** + * @inheritDoc + */ + public function getDoctrineMigrations() + { + return []; + } + + /** + * @inheritDoc + */ + public function apply(base $base, Application $app) + { + if ($base->get_base_type() === base::DATA_BOX) { + $this->patch_databox($base, $app); + } + elseif ($base->get_base_type() === base::APPLICATION_BOX) { + $this->patch_appbox($base, $app); + } + + return true; + } + + private function patch_databox(base $databox, Application $app) + { + } + + private function patch_appbox(base $databox, Application $app) + { + /** @var FeedItemRepository $feedItemRepository */ + $feedItemRepository = $app['repo.feed-items']; + + /** @var FeedItem $feedItem */ + foreach ($feedItemRepository->findAll() as $feedItem) { + // if the record is not found, delete the feedItem + if ($app->findDataboxById($feedItem->getSbasId())->getRecordRepository()->find($feedItem->getRecordId()) == null) { + $app['orm.em']->remove($feedItem); + } + } + + $app['orm.em']->flush(); + } +} diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 8c94ea83ef..9dab828c1e 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -32,6 +32,7 @@ use Alchemy\Phrasea\Media\TechnicalData; use Alchemy\Phrasea\Media\TechnicalDataSet; use Alchemy\Phrasea\Metadata\Tag\TfBasename; use Alchemy\Phrasea\Metadata\Tag\TfFilename; +use Alchemy\Phrasea\Model\Repositories\FeedItemRepository; use Alchemy\Phrasea\Model\Entities\OrderElement; use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\RecordInterface; @@ -2146,6 +2147,14 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $this->app['orm.em']->remove($basket_element); } + /** @var FeedItemRepository $feedItemRepository */ + $feedItemRepository = $this->app['repo.feed-items']; + + // remove the record from publications + foreach($feedItemRepository->findBy(['recordId' => $this->getRecordId()]) as $feedItem) { + $this->app['orm.em']->remove($feedItem); + } + $this->app['orm.em']->flush(); $this->app['filesystem']->remove($ftodel); diff --git a/templates/web/prod/results/item.html.twig b/templates/web/prod/results/item.html.twig index 0b04a340bc..81430b347d 100644 --- a/templates/web/prod/results/item.html.twig +++ b/templates/web/prod/results/item.html.twig @@ -1,87 +1,85 @@ {% import 'common/thumbnail.html.twig' as thumbnail %} -{% if item.isRecordExist(app) %} - {% set record = item.record(app) %} +{% set record = item.record(app) %} -
-
-
- {{ record.get_title }} -
-
- {% for flag in record_flags(record) %} - - {% endfor %} -
+
+
+ {{ record.get_title }}
- - {% set rollover_gif = record.get_rollover_thumbnail %} - - {% if rollover_thumbnail == 'caption' %} - {% set tooltipsrc = path('prod_tooltip_caption', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId, 'context' : 'publi' }) %} - {% elseif rollover_thumbnail == 'preview' %} - {% set tooltipsrc = path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) %} - {% endif %} - -
-
- - {{ record.get_formated_duration }} - - {% if doctype_display %} - {{ record_doctype_icon(record) }} - {% endif %} -
-
- {% set extraclass = rollover_gif ? 'rollover-gif-out' : '' %} - {{ thumbnail.format(record.get_thumbnail(), images_size, images_size, extraclass, true, false) }} - {% if rollover_gif %} - {{ thumbnail.format(rollover_gif, images_size, images_size, 'rollover-gif-hover hide', true, false) }} - {% endif %} -
-
- -
- - - - {% set l_width = 30 %} - {% if rollover_thumbnail == 'preview' %} - {% set l_width = l_width + 50 %} - {% endif %} - {% if technical_display == '1' %} - {% set l_width = l_width + 50 %} - {% endif %} - - -
- {{ record.get_collection_logo(app)|raw }} - - {% if record.has_preview and has_access_subdef(record, 'preview') %} -
- {% endif %} - {% if rollover_thumbnail == 'preview' %} -
- {% endif %} - {% if technical_display == '1' %} - - {% endif %} -
+
+ {% for flag in record_flags(record) %} + + {% endfor %}
+ + {% set rollover_gif = record.get_rollover_thumbnail %} + + {% if rollover_thumbnail == 'caption' %} + {% set tooltipsrc = path('prod_tooltip_caption', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId, 'context' : 'publi' }) %} + {% elseif rollover_thumbnail == 'preview' %} + {% set tooltipsrc = path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) %} + {% endif %} + +
+
+ + {{ record.get_formated_duration }} + + {% if doctype_display %} + {{ record_doctype_icon(record) }} + {% endif %} +
+
+ {% set extraclass = rollover_gif ? 'rollover-gif-out' : '' %} + {{ thumbnail.format(record.get_thumbnail(), images_size, images_size, extraclass, true, false) }} + {% if rollover_gif %} + {{ thumbnail.format(rollover_gif, images_size, images_size, 'rollover-gif-hover hide', true, false) }} + {% endif %} +
+
+ +
+ + + + {% set l_width = 30 %} + {% if rollover_thumbnail == 'preview' %} + {% set l_width = l_width + 50 %} + {% endif %} + {% if technical_display == '1' %} + {% set l_width = l_width + 50 %} + {% endif %} + + +
+ {{ record.get_collection_logo(app)|raw }} + + {% if record.has_preview and has_access_subdef(record, 'preview') %} +
+ {% endif %} + {% if rollover_thumbnail == 'preview' %} +
+ {% endif %} + {% if technical_display == '1' %} + + {% endif %} +
+
+
-{% endif %}