Jump to content

Restoring PageTable page after trashing


alexcapes
 Share

Recommended Posts

Hi,

I've noticed when I trash pages from a PageTable field, then restore them, they are restored to their original location, however the connection is broken with the PageTable field.

Is this expected behaviour? Is there a way for it to maintain this relationship? Otherwise restoring it doesn't actually restore it to it's previous state.

Note that in this case the parent pages for the PageTable field is not set as the direct parent.

 

 

 

  • Like 1
Link to comment
Share on other sites

not really a solution, but i use the limit page table module to prevent users from trashing items in page tables, and use the extra actions (hide, unpub); so basically the users can't trash pagetable pages – if they don't want those pages anymore then they can unpub;

Link to comment
Share on other sites

9 hours ago, alexcapes said:

Is this expected behaviour? Is there a way for it to maintain this relationship? Otherwise restoring it doesn't actually restore it to it's previous state.

It would be nice if restoring a page could simultaneously restore relationships for that page, but I'd say the current behaviour is not unexpected. The same limitation would apply if the page had been selected in a Page Reference field (which is PageTable field is like an extended version of).

If you check the names of pages in the Trash you can see how the location and sort position of the original page is stored:

2017-06-08_094236.png.4919b0a0b275399288a3fc0817070549.png

I guess it's just not practical to keep all the relationship information that applied to a page in this kind of format.

Link to comment
Share on other sites

On 2017-6-7 at 10:45 PM, Robin S said:

It would be nice if restoring a page could simultaneously restore relationships for that page, but I'd say the current behaviour is not unexpected. The same limitation would apply if the page had been selected in a Page Reference field (which is PageTable field is like an extended version of).

If you check the names of pages in the Trash you can see how the location and sort position of the original page is stored:

2017-06-08_094236.png.4919b0a0b275399288a3fc0817070549.png

I guess it's just not practical to keep all the relationship information that applied to a page in this kind of format.

I wonder how difficult it would be to store the relationship info somewhere else and then add the page back to the PageTable if restored? Do you think it's doable with a simple module?

Link to comment
Share on other sites

13 hours ago, alexcapes said:

Do you think it's doable with a simple module?

It would be possible to get the relationship at the time a page is trashed - for instance, with a PageTable field you could hook InputfieldPageTable::processInput() and get the pages about to be trashed. As for simple it depends on what you're comfortable with. To store the information in a self-contained way your module would need to create and use its own database table. There are existing modules you could look at as an example of how to do this, e.g. Template Access by Parents

  • Like 1
Link to comment
Share on other sites

On 2017-6-13 at 1:08 AM, Robin S said:

It would be possible to get the relationship at the time a page is trashed - for instance, with a PageTable field you could hook InputfieldPageTable::processInput() and get the pages about to be trashed. As for simple it depends on what you're comfortable with. To store the information in a self-contained way your module would need to create and use its own database table. There are existing modules you could look at as an example of how to do this, e.g. Template Access by Parents

Thanks @Robin S I'll have a play around and see if I can get something working.

Link to comment
Share on other sites

@alexcapes, are you looking for a solution that would allow non-superusers to restore accidentally trashed PageTable pages? Or is it just an occasional mistake that a superuser needs to fix on request? If it's just the latter you could restore the pages from the trash and use Version Control or Changelog to put the PageTable field back how it was before the deletion.

  • Like 1
Link to comment
Share on other sites

40 minutes ago, Robin S said:

@alexcapes, are you looking for a solution that would allow non-superusers to restore accidentally trashed PageTable pages? Or is it just an occasional mistake that a superuser needs to fix on request? If it's just the latter you could restore the pages from the trash and use Version Control or Changelog to put the PageTable field back how it was before the deletion.

This would be for super-users only as last resort to fix mistakes.

I think using 'Version Control' may be a workable solution although it does feel a little like using a sledgehammer to crack a nut - I don't really need/want version control and it might add too much complication for the client - and I only need this 'restore' option on one single pagetable field.

Just to note I don't think changelog offers any way to 'restore' the a previous state of a field. 

*Update*
Version Control can be switched on for specific fields only so I think this is going to be a workable solution for me. Thanks @Robin S

*Update #2*
Looks like Version Control is not compatible with PageTable fields.

 

 

Link to comment
Share on other sites

2 hours ago, alexcapes said:

Just to note I don't think changelog offers any way to 'restore' the a previous state of a field.

For either Version Control or Changelog my thinking was that you would use these just as a way of tracing which pages were deleted from which PageTable fields. You would restore the pages to the PageTable field using the API. The issue with restoring directly from Version Control is that other changes may have been made after the deletion and you wouldn't want to lose those.

But I had a better idea anyway which is just to log any deletions from your PageTable field. Here's an example for a single field but you could extend this by foreaching any fields on the current page of type InputfieldPageTable.

$pages->addHookAfter('saveReady', function(HookEvent $event) {
    $page = $event->arguments(0);
    if(!$page->my_pagetable) return;
    $old_value = $this->pages->getById($page->id, array(
        'getFromCache' => false,
        'getOne' => true,
    ))->my_pagetable;
    $trashed = $old_value->removeItems($page->my_pagetable);
    if(count($trashed)) {
        $trashed_ids = $trashed->implode(', ', 'id');
        $this->log->save('trashed-pt-pages', "Container page: $page->id | Field: my_pagetable | Trashed: $trashed_ids");
    }
});

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...