Completed
Pull Request — master (#11)
by Gilles
02:15
created

RewriteUrl::update()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 3
eloc 12
nc 2
nop 3
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                                                  */
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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\Map\RewritingUrlTableMap;
17
use Thelia\Model\RewritingUrl;
18
use Thelia\Model\RewritingUrlQuery;
19
use Thelia\Module\BaseModule;
20
21
/**
22
 * Class RewriteUrl
23
 * @package RewriteUrl
24
 * @author Vincent Lopes <[email protected]>
25
 * @author Gilles Bourgeat <[email protected]>
26
 */
27
class RewriteUrl extends BaseModule
28
{
29
    /** @var string  */
30
    const MODULE_DOMAIN = "rewriteurl";
31
32
    /** @var string  */
33
    const MODULE_NAME = "rewriteurl";
34
35
    /**
36
     * @param string $currentVersion
37
     * @param string $newVersion
38
     * @param ConnectionInterface $con
39
     * @throws \Exception
40
     * @throws \Propel\Runtime\Exception\PropelException
41
     * @since 1.2.3
42
     */
43
    public function update($currentVersion, $newVersion, ConnectionInterface $con = null)
44
    {
45
        /*
46
         * Fix for urls that redirect on itself
47
         */
48
        $urls = RewritingUrlQuery::create()
49
            ->where(RewritingUrlTableMap::ID . " = " . RewritingUrlTableMap::REDIRECTED)
50
            ->find();
51
52
        /** @var RewritingUrl $url */
53
        foreach ($urls as $url) {
54
            $parent = RewritingUrlQuery::create()
55
                ->filterByView($url->getView())
56
                ->filterByViewId($url->getViewId())
57
                ->filterByViewLocale($url->getViewLocale())
58
                ->filterByRedirected(null)
59
                ->findOne();
60
61
            $url->setRedirected(($parent === null) ? null : $parent->getId())->save();
62
        }
63
    }
64
}
65