interchange / interchange6-schema

DBIC schema for Interchange 6
8 stars 7 forks source link

Redirect class proposal #179

Closed hexfusion closed 9 years ago

hexfusion commented 9 years ago

I have a use for a redirect process for Navigation and Product to manage SEO and discontinued products. I propose 2 new classes NavigationRedirect and ProductRedirect. This will allow uri -> $product/$navigation mapping. I think this would be a nice feature and easily managed without much code. I considered jamming this into Navigation but I think that the target of the redirect should be direct relationships to $product and $nav. Open to input on this.

racke commented 9 years ago

I'm using this table in one of my shops. Actually default for status code should be 301.

MariaDB [shop]> describe path_redirect
    -> ;
+-------------+--------------+------+-----+---------+-------+
| Field       | Type         | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| path_source | varchar(255) | NO   | PRI |         |       |
| path_target | varchar(255) | NO   |     |         |       |
| status_code | int(11)      | NO   |     | 0       |       |
| last_used   | int(11)      | NO   |     | 0       |       |
+-------------+--------------+------+-----+---------+-------+
4 rows in set (0.25 sec)
hexfusion commented 9 years ago

I am motivated to make this work if you think this makes sense I will write a few tests.

https://github.com/interchange/interchange6-schema/commit/724064c1a1e1e1f61c86321bfa69da75d160a018

hexfusion commented 9 years ago

possible use case

hook 'before' => sub {
    my $tokens = shift;
    my $redirect;

    # path
    my $path = request->path;
    $path =~ s|^/||;

    # check for redirects
    $redirect = shop_schema->resultset('NavigationRedirect')->find({ uri => $path });
    my $redirect_uri = $redirect->find_related('navigation', { navigation_id => $redirect->navigation_id })->uri if $redirect;
    redirect '/' . $redirect_uri, $redirect->status_code if $redirect_uri;
};
racke commented 9 years ago

Yes this could be a feature of Dancer::Plugin::Interchange6.

hexfusion commented 9 years ago

:+1:

hexfusion commented 9 years ago

@SysPete what do you think of the idea/classes ^^

SysPete commented 9 years ago

I think a single class as per @racke's path_redirect is enough unless @sbatschelet can persuade me otherwise since atm I don't see the advantage of the extra db query plus extra code. Slotted in immediate before https://github.com/interchange/Dancer-Plugin-Interchange6/blob/master/lib/Dancer/Plugin/Interchange6/Routes.pm#L373 this is a simple and useful addition.

SysPete commented 9 years ago

Closed now we have UriRediret class.