[Intermediate] Delete an asset with a link manager


(Chris Horikx) #1

Hi All,


Today I set out to create the functionality to delete an asset with AJAX. I have previously created this functionality with the use of triggers quite a few times, however, the only way to delete a particular asset with a trigger is to utilise the action 'Create link' where you create a link to the trash and select the option 'unlink from all other assets'. If the asset you are deleting has multiple links, then this will delete EVERY link which is not assumed functionality to the average user.



I tried setting up a link manager to delete assets which after a lot of testing I figured out.



On the details screen:


  • don't set a managed asset
    [*]don't set an asset type
    [*]don't select a status
    [*]in the root node area type in the asset id# '1'
    [*]set up a dynamic get var for the managed asset (in this case I will use 'managedAsset')
    [*]set up two different dynamic get vars for the root nodes (in this case I will use 'listingRoot1' and 'listingRoot2')


To move an asset you require the following GET var parameters

[list=1]
[*] http://path/to/linkmanager?managedAsset=||the assetid you wish to move||
[*] &listingRoot1=||the assetid of the managedAsset's parent's parent (so two levels up)||
[*] &listingRoot2=||the assetid of your trash, or safe trash folder||
[*] &selection_flag_page_link_manager_||the assetid of your link manager||_Linked=1
[*] &page_link_manager_||the assetid of your link manager||_Linked[||the assetid of your trash, or safe trash folder||]=1
[/list]

An example URL here might be:
http://path/to/linkmanager?managedAsset=||the?managedAsset=500&[b]listingRoot1[/b]=1&[b]listingRoot2[/b]=600&[b]selection_flag_page_link_manager_700_Linked[/b]=1&[b]page_link_manager_700_Linked[/b][600]=1

The reason why we have 2 listingRoots is because we want to define the areas to manipulate as granularly as possible, I'll get into that later.

Line 5 shows, equivalent in my example immediately above, page_link_manager_700_Linked[600]=1. This particular parameter is tricky. The URL doesn't say 'unlink from here, then link to there' it says 'start from scratch, within my listingRoots, link in these parents'. So we could have multiple parameters like line 5 to link into multiple parents it would look like this:

page_link_manager_700_Linked[600]=1&page_link_manager_700_Linked[1000]=1&page_link_manager_700_Linked[1100]=1&page_link_manager_700_Linked[1200]=1

Then this asset would then be linked into these 4 parent assets.

So... this works, but why the granularity on listingRoots? Why not just define the root always as root asset #1?

[b]BECAUSE[/b], within the listing root, the link manager wipes [b]ALL[/b] of your links except the ones listed in the 'page_link_manager_700_Linked[]' list. If you do not list current links within the listingRoot they will be deleted. However, the links that do not exist within the listingRoots will not be deleted.

For Example in the ASSET TREE:
1
- 2
| - 2.1
| _ 2.2
- 3
| - 3.1
| | - 3.1.1
| - 3.2
| | - 3.1.1
- 4
| - 3.1.1

If you ran the following URL: (cascaded for readability)
http://path/to/linkmanager?managedAsset=||the?
managedAsset=3.1.1&
listingRoot1=3&
listingRoot2=2.1&
selection_flag_page_link_manager_700_Linked=1&
page_link_manager_700_Linked[2.1]=1

It would delete 3.1.1 out of 3.1 AND 3.1.1 out of 3.1.1 out of 3.2, however 3.1.1 inside 4 would remain untouched.

If you ran the following URL: (cascaded for readability)
http://path/to/linkmanager?managedAsset=||the?
managedAsset=3.1.1&
listingRoot1=3&
listingRoot2=2.1&
selection_flag_page_link_manager_700_Linked=1&
page_link_manager_700_Linked[2.1]=1&
page_link_manager_700_Linked[3.2]=1

It would delete 3.1.1 out of 3.1 only.

Only known solution by me:
If you could be bothered, you could perform a AJAX DB Query (using DB Datasource) on top of the AJAX call to the link manager to attain the other links that the managedAsset has, it wouldn't be hard to do but would put more wait on the delete.

[b]Conclusion[/b]:
Although we suffer from the same problems between triggers and a link manager, on a different scale, at least we can narrow down the field of link deletion by using the Link Manager.

Use the link manager, its takes less to set up than the trigger

(Anton Babushkin) #2

We use the link manager to delete assets on our custom front-end with a simple piece of JavaScript to make it asynchronous.


One problem we have is that we have to contact the _nocache/ version of the link manager (since we cache even the back-end) and so it proves to be rather slow.


(Timeverist) #3

How do you do this step:

[quote]


  • in the root node area type in the asset id# '1'
[/quote]

I am unable to 'type' into that area and cant see how I can select 1 with the asset chooser.

(Daniel Nitsche) #4

Only the newer versions of Matrix allow you to type in the Asset ID. Using the asset chooser will have the same affect.


(Chris Horikx) #5

[quote]How do you do this step:






I am unable to 'type' into that area and cant see how I can select 1 with the asset chooser.[/quote]



Though it is hacky, you can do this in 3.16 and below by using the firebug plugin in firefox and manually typing it into the chooser input value.