PHRAS-3604 remove deleted record from a publication

This commit is contained in:
aynsix
2021-12-08 15:51:49 +03:00
parent 43132f453c
commit bc17030f9d
4 changed files with 165 additions and 94 deletions

View File

@@ -230,21 +230,4 @@ class FeedItem
{ {
return new \record_adapter($app, $this->getSbasId(), $this->getRecordId(), $this->getOrd()); 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;
}
}
} }

View File

@@ -0,0 +1,81 @@
<?php
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Repositories\FeedItemRepository;
use Alchemy\Phrasea\Model\Entities\FeedItem;
class patch_415PHRAS3604 implements patchInterface
{
/** @var string */
private $release = '4.1.5';
/** @var array */
private $concern = [base::APPLICATION_BOX];
/**
* @inheritDoc
*/
public function get_release()
{
return $this->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();
}
}

View File

@@ -32,6 +32,7 @@ use Alchemy\Phrasea\Media\TechnicalData;
use Alchemy\Phrasea\Media\TechnicalDataSet; use Alchemy\Phrasea\Media\TechnicalDataSet;
use Alchemy\Phrasea\Metadata\Tag\TfBasename; use Alchemy\Phrasea\Metadata\Tag\TfBasename;
use Alchemy\Phrasea\Metadata\Tag\TfFilename; use Alchemy\Phrasea\Metadata\Tag\TfFilename;
use Alchemy\Phrasea\Model\Repositories\FeedItemRepository;
use Alchemy\Phrasea\Model\Entities\OrderElement; use Alchemy\Phrasea\Model\Entities\OrderElement;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\RecordInterface; use Alchemy\Phrasea\Model\RecordInterface;
@@ -2146,6 +2147,14 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
$this->app['orm.em']->remove($basket_element); $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['orm.em']->flush();
$this->app['filesystem']->remove($ftodel); $this->app['filesystem']->remove($ftodel);

View File

@@ -1,87 +1,85 @@
{% import 'common/thumbnail.html.twig' as thumbnail %} {% import 'common/thumbnail.html.twig' as thumbnail %}
{% if item.isRecordExist(app) %}
{% set record = item.record(app) %} {% set record = item.record(app) %}
<div style="width:{{ images_size+30 }}px;" <div style="width:{{ images_size+30 }}px;"
sbas="{{ record.databoxId }}" sbas="{{ record.databoxId }}"
id="{{'PUBLI_' ~ entry.id ~ '_' ~ record.id }}" id="{{'PUBLI_' ~ entry.id ~ '_' ~ record.id }}"
class="IMGT diapo type-{{ record.type }} open-preview-action" class="IMGT diapo type-{{ record.type }} open-preview-action"
data-kind="FEED" data-kind="FEED"
data-position="{{ record.getNumber }}" data-position="{{ record.getNumber }}"
data-id="{{ entry.id }}" data-id="{{ entry.id }}"
> >
<div style="padding: 4px;"> <div style="padding: 4px;">
<div style="height:40px; position: relative; z-index: 95;margin-bottom:0;border-bottom:none;"> <div style="height:40px; position: relative; z-index: 95;margin-bottom:0;border-bottom:none;">
<div class="title" style="max-height:100%" title="{{ record.get_title }}"> <div class="title" style="max-height:100%" title="{{ record.get_title }}">
{{ record.get_title }} {{ record.get_title }}
</div>
<div class="status">
{% for flag in record_flags(record) %}
<img src="{{ flag.path }}" title="{{ attribute(flag.labels, app.locale) }}" />
{% endfor %}
</div>
</div> </div>
<div class="status">
{% set rollover_gif = record.get_rollover_thumbnail %} {% for flag in record_flags(record) %}
<img src="{{ flag.path }}" title="{{ attribute(flag.labels, app.locale) }}" />
{% if rollover_thumbnail == 'caption' %} {% endfor %}
{% 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 %}
<div class="thumb captionTips " tooltipsrc="{{ tooltipsrc }}"
style="height:{{ images_size }}px; z-index:90;">
<div class="doc_infos">
<span class="duration">
{{ record.get_formated_duration }}
</span>
{% if doctype_display %}
{{ record_doctype_icon(record) }}
{% endif %}
</div>
<div class="{% if rollover_gif %}rollovable{% 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 %}
</div>
</div>
<div style="height: 25px; position:relative; text-align:left;">
<table class="bottom" style="width:100%; table-layout:fixed;">
<tr>
<td style="text-align:left;text-overflow:ellipsis;overflow:hidden;">
{{ record.get_collection_logo(app)|raw }}
</td>
{% 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 %}
<td style='text-align:right;width:{{ l_width }}px;' valign='bottom'>
{% if record.has_preview and has_access_subdef(record, 'preview') %}
<div tooltipsrc="{{ path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}"
class="previewTips"></div>
{% endif %}
{% if rollover_thumbnail == 'preview' %}
<div tooltipsrc="{{ path('prod_tooltip_caption', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId, 'context' : 'answer', 'number' : record.getNumber }) }}"
class="captionRolloverTips"></div>
{% endif %}
{% if technical_display == '1' %}
<img class="infoTips"
tooltipsrc="{{ path('prod_tooltip_technical_data', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}"
src="/assets/common/images/icons/info.gif"/>
{% endif %}
</td>
</tr>
</table>
</div> </div>
</div> </div>
{% 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 %}
<div class="thumb captionTips " tooltipsrc="{{ tooltipsrc }}"
style="height:{{ images_size }}px; z-index:90;">
<div class="doc_infos">
<span class="duration">
{{ record.get_formated_duration }}
</span>
{% if doctype_display %}
{{ record_doctype_icon(record) }}
{% endif %}
</div>
<div class="{% if rollover_gif %}rollovable{% 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 %}
</div>
</div>
<div style="height: 25px; position:relative; text-align:left;">
<table class="bottom" style="width:100%; table-layout:fixed;">
<tr>
<td style="text-align:left;text-overflow:ellipsis;overflow:hidden;">
{{ record.get_collection_logo(app)|raw }}
</td>
{% 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 %}
<td style='text-align:right;width:{{ l_width }}px;' valign='bottom'>
{% if record.has_preview and has_access_subdef(record, 'preview') %}
<div tooltipsrc="{{ path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}"
class="previewTips"></div>
{% endif %}
{% if rollover_thumbnail == 'preview' %}
<div tooltipsrc="{{ path('prod_tooltip_caption', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId, 'context' : 'answer', 'number' : record.getNumber }) }}"
class="captionRolloverTips"></div>
{% endif %}
{% if technical_display == '1' %}
<img class="infoTips"
tooltipsrc="{{ path('prod_tooltip_technical_data', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}"
src="/assets/common/images/icons/info.gif"/>
{% endif %}
</td>
</tr>
</table>
</div>
</div>
</div> </div>
{% endif %}