Giter Site home page Giter Site logo

syliusredirectplugin's Introduction

Sylius Redirect Plugin

Latest Version on Packagist Software License Build Status

Gives you the ability to manage redirects in your Sylius shop.

Installation

Step 1: Download the plugin

Open a command console, enter your project directory and execute the following command to download the latest stable version of this plugin:

$ composer require setono/sylius-redirect-plugin

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the plugin

Then, enable the plugin by adding it to the list of registered plugins/bundles in the config/bundles.php file of your project:

<?php

return [
    // ...
    
    // Add before SyliusGridBundle
    Setono\SyliusRedirectPlugin\SetonoSyliusRedirectPlugin::class => ['all' => true],
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
    
    // ...
];

It is IMPORTANT to add the plugin before the grid bundle else you will get a an exception saying You have requested a non-existent parameter "setono_sylius_redirect.model.redirect.class".

Step 3: Add configuration

# config/routes/setono_sylius_redirect.yaml

setono_sylius_redirect_admin:
    resource: "@SetonoSyliusRedirectPlugin/Resources/config/admin_routing.yaml"
    prefix: /admin
# config/packages/setono_sylius_redirect.yaml
imports:
    # ...
    
    - { resource: "@SetonoSyliusRedirectPlugin/Resources/config/app/config.yaml" }
    
    # ...

Step 4: Update database

Use Doctrine migrations to create a migration file and update the database.

$ bin/console doctrine:migrations:diff
$ bin/console doctrine:migrations:migrate

Step 5: Copy template

You can copy the templates under tests/Application/templates/bundles/SyliusAdminBundle into your own application to enable the possibility to add an automatic redirection when updating product

Step 6: Install assets

$ bin/console assets:install

What it does

This plugin allows you to create new redirects.

Under the new menu entry Redirects unders Configuration, you can manage redirects.

Redirection entry

An entry is composed by:

  • Source url, relative to your website
  • Target URL, can be relative or absolute in case you want to redirect to another website
  • Permanent or Temporary (This impact the HTTP response code of the redirection, 301 or 302)
  • Enabled
  • Redirect only if 404 (to manage potentially dead links)

Security

There is a built-in security when creating/modifying redirection that prevent creating an infinite loop. This work with infinite recursive checking.

A second security is to prevent same source redirection leading to inconstant redirect.

Automatic redirect

There is a built-in feature that allows you to automatically create a redirection when changing a product slug. It also handles the case where it would create an infinite loop and remove the unnecessary redirect.

Example: Having a slug like /products/a, renaming it to /products/b then renaming it to /products/a will result in a redirect from b to a and will automatically delete the one from a to b.

Contributors

syliusredirectplugin's People

Contributors

acornforth avatar dependabot[bot] avatar ianwijma avatar jordidekker avatar loevgaard avatar lruozzi9 avatar mamazu avatar mateuszry avatar pamil avatar reyostallenberg avatar roshyo avatar stefandoorn avatar vvasiloi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

syliusredirectplugin's Issues

Unexpected behaviour when removing 'not accessed'

Given the following setup

  • A redirect is created on day=0
  • The parameter setono_sylius_redirect.remove_after is set to x
  • The redirect is never accessed, i.e. the lastAccessed property is null

It would be expected that when day > x then this redirect is removed. However this is not the case since the service that removes redirects does not include redirects with lastAccessed = null.

To fix this we need to extend TimestampableInterface in RedirectInterface and then add a clause in the service that removes redirects to remove redirects that was never accessed in x days.

Easier configuration of automatic redirects

Right now the automatic redirect feature is maybe too complicated: It involves form extensions and javascript. What if we could just enable it by config like so:

setono_sylius_redirect:
    automatic_redirects:
        - 'sylius.product_translation'
        - 'sylius.taxon_translation'

where sylius.product_translation and sylius.taxon_translation are the resources defined by Sylius.

Of course this would create more redirects than necessary, but if people have implemented the cronjob to remove redirects that aren't accessed, that wouldn't be a problem.

Installation on SF 3.4 / Sylius 1.4 fails

After following the installation instructions, I run into the following error:

"form.type_extension" tagged services must have the extended type configured using the extended_type/extended-type attribute, none was configured for the "setono_sylius_redirect.form.extension.product_translation" service.

I'm assuming for now that it's an incompatibility with Symfony 3.4, but I will do a bit of research also.

Extend README

It would be great to be able to better understand what the plugin exactly does right from the README.

Make it possible to redirects hosts

Right now we are redirects paths basically. Would be nice to be able to redirects hosts also:

i.e. example.com => example.net.

Should be possible to have a checkbox as to whether the redirect should include the path and query string, i.e.

example.com/path?q=val redirects to example.net/path?q=val

Remove the permanent property?

Right now you can create two kinds of redirects: A permanent (301) and a temporary (302). My suggestion is to remove the ability to choose and instead make the 301 redirect the way to go.

I have created tons of redirects in my life during migrations of products etc. I have never in my life created a temporary redirect. Also you would never create a temporary redirect for SEO purposes. That would always be a permanent.

According the this article from Yoast a 302 redirect that is active for too long will be treated as a 301. This has the implication that in theory we should probably have an expiry date when creating a temporary (302) redirect. That will just add to the complexity of this plugin.

Removing the permanent/temporary option would also open up for this issue: #62 which in turn would lower the complexity of the plugin.

Any thoughts / feedback is very welcome.

Possibility to redirect a path without the path being a 404

Say you have a landing page for christmas, /christmas that you want to redirect to the frontpage when christmas is over, but you don't want to delete the page because you can reuse it next year.

In the current implementation this isn't possible, but if the listener looked in the redirection table on every request this would be possible.

However, this comes with a speed cost. If the redirection table has thousands or even millions of rows and you had to lookup the path on every request it would slow down the request. Could this problem be fixed with some kind of cache?

Incompatibility with Sylius 1.9

Plugin version : v2.1.1
Sylius version : 1.9

With the recent Sylius 1.9 update, the plugin is not compatible anymore and won't work
You systematically get this error :

Argument 1 passed to Setono\SyliusRedirectPlugin\EventListener\NotFoundSubscriber::__construct() must be an instance of Doctrine\Common\Persistence\ObjectManager, instance of EntityManager_9a5be93 given, called in /Users/user/PhpstormProjects/sylius/var/cache/dev/ContainerXhzYauW/getSetonoSyliusRedirect_EventListener_NotFoundService.php on line 11

[to fix] issue with in internal path

Hello,

I noticed I have lot of queries since I installed the plugin whereas I was thinknig it should be only check one time the url to redirect.

image

The issue comes internal paths, at first, I added a condition on : RedirectionPathResolver with someting like

if(false === strpos($source, '/_fragment/')){
//do the stuff
}

but there is lot of sources with this issue ('wishlist' (wishlist bundle) , 'block' / 'section' / 'page' (CMS bundle).

What is the best way to catch the good one to redirect (at home it should be "/") and not all the internal path render wiht controllers?

The best way should be to detect the good request but when I compare the Symfony\Component\HttpFoundation\Request, there is no way to know the good one.

Maybe add a paramter to excludes somes routes?

'Last redirect' functionality is a mess

Instead of having a hierarchy of redirects it would be much better to have functionality that updated the redirect hierarchy when adding a new redirect so that all redirects always pointed to the last destination and not any intermediary destination

Custom http codes

I was wondering if there is interest in allowing custom response codes other then 301 & 302. For example 307 (Temporary Redirect)?

app_dev.php gets prepended

On redirect generation (when changing product slug) the app_dev.php file is prepended when on Symfony 3.4 and developing locally. The controller subscriber doesn't strip this off, so a redirect is never found in the end.

Improve indexes?

Currently we have next indexes:

        <indexes>
            <index columns="last_accessed"/>
            <index columns="enabled"/>
            <index columns="only_404"/>
        </indexes>

How about adding next ones?

        <indexes>
            ...
            <index name="removeNotAccessed_idx" columns="last_accessed,created_at"/>
            <index name="findOneEnabledBySource_idx" columns="source,enabled"/>
            <index name="findOne404EnabledBySource_idx" columns="source,enabled,only404"/>
        </indexes>

(adding another one index that include channels seems impossible for me as we have many-to-many)

Bulk delete redirects

If a filter is made (#22) it would make sense to have bulk delete also so that when you have applied a filter, you can delete all redirects matching this filter

Requirement to install thecodingmachine/safe?

Hi,
Using an install of Sylius 1.7.3, creating a redirect and then accessing it causes a 500 error:

"Attempted to load class "DateTime" from namespace "Safe". Did you forget a "use" statement...

in
vendor/setono/sylius-redirect-plugin/src/Model/Redirect.php, line 108

It seems the thecodingmachine/safe should be required in the composer.json but isn't. Is it assumed it's installed elsewhere?

[ENHANCEMENT] Allow importing batch redirect plan

Basically, when someone wants to work on products URI to optimize SEO for example, they create a CSV or similar file and want to import it.
We should provide such a functionality, and obviously, check the file integrity (infinite loop/duplicate)

A small question though:

  • Would it be linked to SyliusImportExportPlugin ?
  • Or should such a functionality remains fully under this plugin ?

Doesn't Work on PostGres

I assume this issue will also affect other database back-end that have a native boolean type.

the issue is in the queries in the repository, doing a comparison of a boolean filed type against an integer literal only works in mysql, and works because internally doctrine stores boolean values as tinyint in mysql. for databases with a native boolean type, this needs to be a boolean comparison.

Happy to submit a PR for review, but i will not be able to test my changes on a mysql backend.

Only allow redirects with shop security regex

To circumvent situations where the end user would make a redirect on urls starting with /admin or /api we should only allow redirects that matches the sylius.security.shop_regex parameter

Why do we need a redirect path?

Right now it's possible to have a redirection path like A => B => C => D. Why is that?

Given this redirection path, if I add a new redirect that redirects D => E, then it would make more sense to update the redirects, such that:

  • A => E
  • B => E
  • C => E
  • D => E

This way we know that when we have a redirect it always contains it's final destination in the destination field.

UPDATED
Comment from @Roshyo: This would only be correct if all the redirects are permanent redirects.

Admin checkbox toggle broken

I have recently configured the plugin and I have this problem with the checkbox toggles into admin.
All admin checkbox toggles are affected and everything works fine if I remove the plugin.

setono_sylius_redirect_plugin_toggle_issue

Plugin versions: v2.1.1, v2.1.0, v2.0.0

Other plugins used from Setono:

name: setono/sylius-analytics-plugin
version: v1.1.2

name: setono/sylius-facebook-tracking-plugin
version: v1.0.0-beta.3

name: setono/sylius-tag-bag-plugin
version: v1.0.0,

name: setono/sylius-terms-plugin
version: v1.0.6

name: setono/tag-bag-bundle
version: v1.3.1

2.2 - keep_query_string migration

Hi,

From version 2.2.0 the column keep_query_string is added to the database. The plugin doesn't provide a migration for that, though. It would be great to have migration support available, so it automatically updates like Sylius itself does.

Thanks!

Sorry - no time to PR it myself at the moment, so filing it here as a suggestion.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.