PHRAS-2769 delete record

This commit is contained in:
aynsix
2019-11-04 17:19:18 +04:00
parent 2163f0452d
commit 378f67c203
3 changed files with 16 additions and 4 deletions

View File

@@ -14,6 +14,8 @@ use Alchemy\Phrasea\Application\Helper\EntityManagerAware;
use Alchemy\Phrasea\Application\Helper\SearchEngineAware;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Controller\RecordsRequest;
use Alchemy\Phrasea\Core\Event\Record\DeleteEvent;
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
use Alchemy\Phrasea\Core\Event\RecordEdit;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Model\Entities\BasketElement;
@@ -234,7 +236,7 @@ class RecordController extends Controller
if($trashCollectionsBySbasId[$sbasId] !== null) {
if($record->getCollection()->get_coll_id() == $trashCollectionsBySbasId[$sbasId]->get_coll_id()) {
// record is already in trash so delete it
$record->delete();
$this->getEventDispatcher()->dispatch(RecordEvents::DELETE, new DeleteEvent($record));
} else {
// move to trash collection
$record->move_to_collection($trashCollectionsBySbasId[$sbasId], $this->getApplicationBox());
@@ -247,7 +249,7 @@ class RecordController extends Controller
}
} else {
// no trash collection, delete
$record->delete();
$this->getEventDispatcher()->dispatch(RecordEvents::DELETE, new DeleteEvent($record));
}
} catch (\Exception $e) {
}

View File

@@ -13,8 +13,10 @@ namespace Alchemy\Phrasea\Core\Event\Record;
final class RecordEvents
{
const CREATED = 'record.created';
const DELETED = 'record.deleted';
const CREATED = 'record.created';
const DELETED = 'record.deleted';
const DELETE = 'record.delete';
// Change
const COLLECTION_CHANGED = 'record.collection_changed';
const METADATA_CHANGED = 'record.metadata_changed';

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Core\Event\Subscriber;
use Alchemy\Phrasea\Core\Event\Record\CollectionChangedEvent;
use Alchemy\Phrasea\Core\Event\Record\DeleteEvent;
use Alchemy\Phrasea\Core\Event\Record\RecordEvent;
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionCreateEvent;
@@ -32,6 +33,7 @@ class RecordEditSubscriber implements EventSubscriberInterface
RecordEvents::ROTATE => 'onRecordChange',
RecordEvents::COLLECTION_CHANGED => 'onCollectionChanged',
RecordEvents::SUBDEFINITION_CREATE => 'onSubdefinitionCreate',
RecordEvents::DELETE => 'onDelete',
);
}
@@ -57,6 +59,12 @@ class RecordEditSubscriber implements EventSubscriberInterface
$recordAdapter->rebuild_subdefs();
}
public function onDelete(DeleteEvent $event)
{
$recordAdapter = $this->convertToRecordAdapter($event->getRecord());
$recordAdapter->delete();
}
public function onEdit(RecordEdit $event)
{
static $into = false;