1
|
|
|
<?php |
2
|
|
|
/*************************************************************************************/ |
3
|
|
|
/* This file is part of the RewriteUrl module for Thelia. */ |
4
|
|
|
/* */ |
5
|
|
|
/* Copyright (c) OpenStudio */ |
6
|
|
|
/* email : [email protected] */ |
7
|
|
|
/* web : http://www.thelia.net */ |
8
|
|
|
/* */ |
9
|
|
|
/* For the full copyright and license information, please view the LICENSE.txt */ |
10
|
|
|
/* file that was distributed with this source code. */ |
11
|
|
|
/*************************************************************************************/ |
12
|
|
|
|
13
|
|
|
namespace RewriteUrl; |
14
|
|
|
|
15
|
|
|
use Propel\Runtime\Connection\ConnectionInterface; |
16
|
|
|
use Thelia\Model\ConfigQuery; |
17
|
|
|
use Thelia\Model\Map\RewritingUrlTableMap; |
18
|
|
|
use Thelia\Model\RewritingUrl; |
19
|
|
|
use Thelia\Model\RewritingUrlQuery; |
20
|
|
|
use Thelia\Module\BaseModule; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class RewriteUrl |
24
|
|
|
* @package RewriteUrl |
25
|
|
|
* @author Vincent Lopes <[email protected]> |
26
|
|
|
* @author Gilles Bourgeat <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class RewriteUrl extends BaseModule |
29
|
|
|
{ |
30
|
|
|
/** @var string */ |
31
|
|
|
const MODULE_DOMAIN = "rewriteurl"; |
32
|
|
|
|
33
|
|
|
/** @var string */ |
34
|
|
|
const MODULE_NAME = "rewriteurl"; |
35
|
|
|
|
36
|
|
|
/** @static null|array */ |
37
|
|
|
static protected $unknownSources; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $currentVersion |
41
|
|
|
* @param string $newVersion |
42
|
|
|
* @param ConnectionInterface $con |
43
|
|
|
* @throws \Exception |
44
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
45
|
|
|
* @since 1.2.3 |
46
|
|
|
*/ |
47
|
|
|
public function update($currentVersion, $newVersion, ConnectionInterface $con = null) |
48
|
|
|
{ |
49
|
|
|
/* |
50
|
|
|
* Fix for urls that redirect on itself |
51
|
|
|
*/ |
52
|
|
|
$urls = RewritingUrlQuery::create() |
53
|
|
|
->where(RewritingUrlTableMap::ID . " = " . RewritingUrlTableMap::REDIRECTED) |
54
|
|
|
->find(); |
55
|
|
|
|
56
|
|
|
/** @var RewritingUrl $url */ |
57
|
|
|
foreach ($urls as $url) { |
58
|
|
|
$parent = RewritingUrlQuery::create() |
59
|
|
|
->filterByView($url->getView()) |
60
|
|
|
->filterByViewId($url->getViewId()) |
61
|
|
|
->filterByViewLocale($url->getViewLocale()) |
62
|
|
|
->filterByRedirected(null) |
63
|
|
|
->findOne(); |
64
|
|
|
|
65
|
|
|
$url->setRedirected(($parent === null) ? null : $parent->getId())->save(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array|null |
71
|
|
|
*/ |
72
|
|
|
public static function getUnknownSources() |
73
|
|
|
{ |
74
|
|
|
if (static::$unknownSources === null) { |
75
|
|
|
static::$unknownSources = []; |
76
|
|
|
if (null !== $config = ConfigQuery::read('obsolete_rewriten_url_view', null)) { |
77
|
|
|
static::$unknownSources[] = $config; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
return static::$unknownSources; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|