mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
ENHANCEMENT: warning when deleting a page with documents that exist only on this page. Also, when actually deleting the page, delete the associated documents that only exist on that page
This commit is contained in:
parent
e30a34eedb
commit
9e9cc995b3
@ -54,4 +54,15 @@ class DMSSiteTreeExtension extends DataExtension {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onBeforeDelete() {
|
||||||
|
$dmsDocuments = $this->owner->Documents();
|
||||||
|
foreach($dmsDocuments as $document) {
|
||||||
|
//if the document is only associated with one page, i.e. only associated with this page
|
||||||
|
if ($document->Pages()->Count() <= 1) {
|
||||||
|
//delete the document before deleting this page
|
||||||
|
$document->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -32,6 +32,48 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.cms-content-actions.south .ss-ui-action-destructive').entwine({
|
||||||
|
confirmBeforeDelete: function() {
|
||||||
|
var deleteButtons = $('button.dms-delete[data-pages-count=1]');
|
||||||
|
|
||||||
|
//we have page with DMSDocuments on it, and we have documents that only exist on this page
|
||||||
|
if (deleteButtons.length > 0) {
|
||||||
|
var message = "Are you sure you want to delete this page? Deleting this page will delete "+deleteButtons.length;
|
||||||
|
if (deleteButtons.length == 1) {
|
||||||
|
message += " document that is associated only with this page. This document is:\n\n";
|
||||||
|
} else {
|
||||||
|
message += " documents that are associated only with this page. These documents are:\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//create a list of documents and their IDs
|
||||||
|
deleteButtons.each(function(){
|
||||||
|
var tr = $(this).closest('tr');
|
||||||
|
message += tr.find('.col-ID').text() +' - '+ tr.find('.col-Title').text() +"\n";
|
||||||
|
});
|
||||||
|
|
||||||
|
if(!confirm(message)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#Form_EditForm_action_deletefromlive').entwine({
|
||||||
|
onclick: function(e) {
|
||||||
|
if (this.confirmBeforeDelete()) this._super(e);
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#Form_EditForm_action_delete').entwine({
|
||||||
|
onclick: function(e) {
|
||||||
|
if (this.confirmBeforeDelete()) this._super(e);
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}(jQuery));
|
}(jQuery));
|
||||||
|
@ -72,4 +72,26 @@ class DMSDocumentTest extends SapphireTest {
|
|||||||
$documentsArray = $documents->toArray();
|
$documentsArray = $documents->toArray();
|
||||||
$this->assertNotContains($doc, $documentsArray, "Document no longer associated with page");
|
$this->assertNotContains($doc, $documentsArray, "Document no longer associated with page");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testDeletingPageWithAssociatedDocuments() {
|
||||||
|
$s1 = $this->objFromFixture('SiteTree','s1');
|
||||||
|
$s2 = $this->objFromFixture('SiteTree','s2');
|
||||||
|
|
||||||
|
$doc = new DMSDocument();
|
||||||
|
$doc->Filename = "delete test file";
|
||||||
|
$doc->Folder = "0";
|
||||||
|
$doc->write();
|
||||||
|
|
||||||
|
$doc->addPage($s1);
|
||||||
|
$doc->addPage($s2);
|
||||||
|
|
||||||
|
$s1->delete();
|
||||||
|
|
||||||
|
$documents = DataObject::get("DMSDocument","Filename = 'delete test file'");
|
||||||
|
$this->assertEquals($documents->Count(),'1',"Deleting one of the associated page doesn't affect the single document we created");
|
||||||
|
|
||||||
|
$s2->delete();
|
||||||
|
$documents = DataObject::get("DMSDocument","Filename = 'delete test file'");
|
||||||
|
$this->assertEquals($documents->Count(),'0',"However, deleting the last page that a document is associated with causes that document to be deleted as well");
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user