Skip to content

Commit

Permalink
Merge pull request #3 from thelia-modules/update
Browse files Browse the repository at this point in the history
Version 1.1
  • Loading branch information
gillesbourgeat committed Oct 9, 2015
2 parents fc8f10e + 860f3cb commit 817869e
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 145 deletions.
Empty file modified AdminIncludes/brand-edit-js.html
100644 → 100755
Empty file.
Empty file modified AdminIncludes/category-edit-js.html
100644 → 100755
Empty file.
Empty file modified AdminIncludes/content-edit-js.html
100644 → 100755
Empty file.
Empty file modified AdminIncludes/folder-edit-js.html
100644 → 100755
Empty file.
Empty file modified AdminIncludes/product-edit-js.html
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 1.1.0

- Fix UI
- Fix I18n
- Add the ability to delete the default url
- Add the ability to reassign the default url
18 changes: 0 additions & 18 deletions Config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,10 @@
<form name="rewriteurl.setdefault.form" class="RewriteUrl\Form\SetDefaultForm"/>
</forms>

<commands>
<!--
<command class="MyModule\Command\MySuperCommand" />
-->
</commands>

<services>
<service id="rewriteurl.action" class="RewriteUrl\EventListeners\RewriteUrlListener">
<tag name="kernel.event_subscriber"/>
</service>
</services>


<!--
<exports>
</exports>
-->

<!--
<imports>
</imports>
-->
</config>
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<descriptive locale="fr_FR">
<title>Gérer la réécriture d'url</title>
</descriptive>
<version>1.0.0</version>
<version>1.1.0</version>
<author>
<name>Vincent Lopes, Gilles Bourgeat</name>
<email>[email protected], [email protected]</email>
Expand Down
8 changes: 0 additions & 8 deletions Config/schema.xml

This file was deleted.

4 changes: 2 additions & 2 deletions Controller/Admin/RewriteUrlAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function deleteAction()
$id_url = $this->getRequest()->request->get('id_url');
$rewritingUrl = RewritingUrlQuery::create()->findOneById($id_url);

if ($rewritingUrl) {
if ($rewritingUrl !== null) {
$event = new RewriteUrlEvent($rewritingUrl);
$this->dispatch(RewriteUrlEvents::REWRITEURL_DELETE, $event);
}
Expand Down Expand Up @@ -242,7 +242,7 @@ public function reassignAction()
$isRedirection = RewritingUrlQuery::create()->findByRedirected($rewrite->getId());

//Update urls who redirected to updated URL
if ($isRedirection != null) {
if ($isRedirection !== null) {
/** @var \Thelia\Model\RewritingUrl $redirected */
foreach ($isRedirection as $redirected) {
$redirected->setRedirected($rewrite->getRedirected());
Expand Down
49 changes: 29 additions & 20 deletions EventListeners/RewriteUrlListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,37 @@ public function deleteRewrite(RewriteUrlEvent $event)
{
$rewritingUrl = $event->getRewritingUrl();

try {
if ($rewritingUrl !== null) {

$isRedirection = RewritingUrlQuery::create()->findByRedirected($rewritingUrl->getId());

//Update urls who redirected to deleted URL
if ($isRedirection != null) {
/** @var \Thelia\Model\RewritingUrl $redirected */
foreach ($isRedirection as $redirected) {
$redirected->setRedirected($rewritingUrl->getRedirected());
$newEvent = new RewriteUrlEvent($redirected);
$event->getDispatcher()->dispatch(RewriteUrlEvents::REWRITEURL_UPDATE, $newEvent);
}
}

$rewritingUrl->delete();
$newDefault = null;

// test if default url
if ($event->getRewritingUrl()->getRedirected() === null) {
// add new default url
if (null !== $newDefault = RewritingUrlQuery::create()->findOneByRedirected($rewritingUrl->getId())) {
$event->getDispatcher()->dispatch(
RewriteUrlEvents::REWRITEURL_UPDATE,
new RewriteUrlEvent(
$newDefault->setRedirected(null)
)
);
}
}

} catch (\Exception $e) {
die($e->getMessage());
$isRedirection = RewritingUrlQuery::create()->findByRedirected($rewritingUrl->getId());

//Update urls who redirected to deleted URL
/** @var \Thelia\Model\RewritingUrl $redirected */
foreach ($isRedirection as $redirected) {
$event->getDispatcher()->dispatch(
RewriteUrlEvents::REWRITEURL_UPDATE,
new RewriteUrlEvent(
$redirected->setRedirected(
($newDefault !== null) ? $newDefault->getId() : $rewritingUrl->getRedirected()
)
)
);
}

$rewritingUrl->delete();
}

/**
Expand Down Expand Up @@ -124,7 +134,6 @@ public function setDefaultRewrite(RewriteUrlEvent $event)
*/
public function updateRewrite(RewriteUrlEvent $event)
{
$rewritingUrl = $event->getRewritingUrl();
$rewritingUrl->save();
$event->getRewritingUrl()->save();
}
}
33 changes: 33 additions & 0 deletions I18n/backOffice/default/fr_FR.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

return array(
'Actions' => 'Actions',
'Brand' => 'Marque',
'Category' => 'Catégorie',
'Close' => 'Fermer',
'Default' => 'Url par défaut',
'Default url' => 'Url par défaut',
'Delete Url' => 'Supprimer une Url',
'Delete this redirect' => 'Supprimer cette redirection',
'Do you really want to delete this Url ?' => 'Voulez-vous vraiment supprimer cette Url ?',
'Error this url already exist you can reassign by follow this ' => 'Erreur cette url existe déjà, vous pouvez la réassigner en suivant ce ',
'Folder' => 'Dossier',
'For questions or bug reporting, thank you to use %url.' => 'Pour toutes questions ou déclaration de bug, merci d\'utiliser %url',
'New url' => 'Nouvelle url',
'No redirected url.' => 'Pas de redirection',
'No results found for your search.' => 'Aucun resultat trouvé pour votre recherche.',
'Please wait ...' => 'Veuillez patienter ...',
'Product' => 'Produit',
'Reassign this redirect' => 'Réassigner cette redirection',
'Redirect to default' => 'Rediriger sur l\'url par défaut',
'Redirected' => 'Redirigé vers',
'Search' => 'Rechercher',
'Set this redirect to default' => 'Mettre cette url par défaut',
'Title, Ref ...' => 'Titre, Ref ...',
'Url' => 'Url',
'Url redirected' => 'Url de redirection',
'Validate' => 'Valider',
'View locale' => 'Langue',
'content' => 'Contenu',
'link' => 'lien',
);
23 changes: 0 additions & 23 deletions I18n/en_US.php

This file was deleted.

39 changes: 0 additions & 39 deletions I18n/fr_FR.php

This file was deleted.

4 changes: 1 addition & 3 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Rewrite Url

Authors: Thelia <[email protected]>, Vincent Lopes <[email protected]>, Gilles Bourgeat <[email protected]>

This module manage rewritten urls for products, categories, folders, contents, brands

* Allows you to reassign a url to another (product, category, folder, content, brand)
Expand All @@ -23,7 +21,7 @@ Thelia > 2.0
Add it in your main thelia composer.json file

```
composer require thelia/rewrite-url-module:~1.0
composer require thelia/rewrite-url-module:~1.1
```

## Usage
Expand Down
7 changes: 4 additions & 3 deletions templates/backOffice/default/RewriteUrl/tab-module-js.html
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
"use strict";
(function($, $module){

var i18n = {
Expand Down Expand Up @@ -39,7 +40,7 @@
if (val.length > 3) {
$modalSearchLoader.removeClass('hide');

searchTimer = setTimeout(function(elem) {
searchTimer = setTimeout(function() {
$.ajax({
url: '{url path="/admin/module/rewriteurl/search"}',
data: {
Expand Down Expand Up @@ -79,7 +80,7 @@
}
});

$modalSearch.on('change' ,".js-block-search-result select", function(event){
$modalSearch.on('change' ,".js-block-search-result select", function(){
$modalSearch.find('.js-input-reassign').val($(this).val());
});

Expand All @@ -95,7 +96,7 @@
/************ Action default *************/
/*****************************************/

$module.on('click', '.js-action-add', function(event) {
$module.on('submit', '.js-form-add', function(event){
event.preventDefault();
$module.find('.js-alert-error').addClass('hide');

Expand Down
Loading

0 comments on commit 817869e

Please sign in to comment.