PHRAS-1863 PORT PHRAS-60 Add applicative trash (#2492)

This commit is contained in:
KallooaSan
2018-02-27 20:02:24 +04:00
committed by jygaulier
parent 1ca68fb9a5
commit cb4ef28072
2 changed files with 38 additions and 2 deletions

View File

@@ -189,6 +189,9 @@ class RecordController extends Controller
$deleted = []; $deleted = [];
/** @var \collection[] $trashCollectionsBySbasId */
$trashCollectionsBySbasId = [];
$manager = $this->getEntityManager(); $manager = $this->getEntityManager();
foreach ($records as $record) { foreach ($records as $record) {
try { try {
@@ -205,10 +208,30 @@ class RecordController extends Controller
$manager->remove($attachedStory); $manager->remove($attachedStory);
} }
$sbasId = $record->getDatabox()->get_sbas_id();
if(!array_key_exists($sbasId, $trashCollectionsBySbasId)) {
$trashCollectionsBySbasId[$sbasId] = $record->getDatabox()->getTrashCollection();
}
$deleted[] = $record->getId(); $deleted[] = $record->getId();
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(); $record->delete();
} else {
// move to trash collection
$record->move_to_collection($trashCollectionsBySbasId[$sbasId], $this->getApplicationBox());
// disable permalinks
foreach($record->get_subdefs() as $subdef) {
if( ($pl = $subdef->get_permalink()) ) {
$pl->set_is_activated(false);
}
}
}
} else {
// no trash collection, delete
$record->delete();
}
} catch (\Exception $e) { } catch (\Exception $e) {
} }
} }

View File

@@ -601,6 +601,19 @@ class databox extends base implements ThumbnailedElement
}); });
} }
/**
* @return collection|null
*/
public function getTrashCollection()
{
foreach($this->get_collections() as $collection) {
if($collection->get_name() === '_TRASH_') {
return $collection;
}
}
return null;
}
/** /**
* *
* @param int $record_id * @param int $record_id