To be tested. A lot less dangerous than the previous one. Prefer not to mess with trigger on the content table
Code:
-- add a image named screensaver% to screensaver when added into screensaver
-- collection
--------------------------------------------
create trigger add_screensaver
-- if an image is added again, the trigger should be an update one
after insert on ShelfContent
for each row
when new.ShelfName = 'screensaver’
and new.ContentID like '%screensaver%'
BEGIN
update content
set DateLastRead = '2032-01-01T12:00:00Z', ReadStatus = '1'
where ContentID = new.ContentID
and ContentType = '6';
END
--------------------------------------------
-- delete the screensaver after remove the file from the collection
--------------------------------------------
create trigger delete_screensaver
after update _IsDeleted
on ShelfContent
for each row
when new._IsDeleted = true
and old._IsDeleted = false
and old.ShelfName = 'screensaver’
and old.ContentID like '%screensaver%'
BEGIN
update content
set DateLastRead = '2015-01-01T12:00:00Z', ReadStatus = ‘2'
where ContentID = old.ContentID
and ContentType = '6';
END
--------------------------------------------
-- adding again
--------------------------------------------
create trigger addagain_screensaver
after update _IsDeleted
on ShelfContent
for each row
when new._IsDeleted = false
and old._IsDeleted = true
and new.ShelfName = 'screensaver’
and new.ContentID like '%screensaver%'
BEGIN
update content
set DateLastRead = '2030-01-01T12:00:00Z', ReadStatus = ‘1'
where ContentID = new.ContentID
and ContentType = '6';
END
-- when removed from a collection, the line stays but _isDeleted is true
-- hence, an update trigger should do the trick for deleting and adding again
If this one works, it should have no impact on the updating process
Another way - without triggering on insert - would be to insert in advance the contentid with a isDisable=false and use only update triggers