Completed
Push — master ( 8f4bc9...726447 )
by Matthieu
12:25 queued 06:28
created

Controller::isAllowedToTroubleshootAsSuperUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 4
Ratio 40 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
dl 4
loc 10
ccs 0
cts 7
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
eloc 7
nc 2
nop 0
1
<?php
2
/**
3
 * Piwik - free/libre analytics platform
4
 *
5
 * @link http://piwik.org
6
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7
 *
8
 */
9
namespace Piwik\Plugins\CorePluginsAdmin;
10
11
use Exception;
12
use Piwik\API\Request;
13
use Piwik\Common;
14
use Piwik\Config;
15
use Piwik\Container\StaticContainer;
16
use Piwik\Exception\MissingFilePermissionException;
17
use Piwik\Filechecks;
18
use Piwik\Filesystem;
19
use Piwik\Nonce;
20
use Piwik\Notification;
21
use Piwik\Piwik;
22
use Piwik\Plugin;
23
use Piwik\Plugins\Marketplace\Marketplace;
24
use Piwik\Plugins\Marketplace\Controller as MarketplaceController;
25
use Piwik\Plugins\Marketplace\Plugins;
26
use Piwik\SettingsPiwik;
27
use Piwik\Translation\Translator;
28
use Piwik\Url;
29
use Piwik\Version;
30
use Piwik\View;
31
32
class Controller extends Plugin\ControllerAdmin
33
{
34
    const ACTIVATE_NONCE = 'CorePluginsAdmin.activatePlugin';
35
    const DEACTIVATE_NONCE = 'CorePluginsAdmin.deactivatePlugin';
36
    const UNINSTALL_NONCE = 'CorePluginsAdmin.uninstallPlugin';
37
38
    /**
39
     * @var Translator
40
     */
41
    private $translator;
42
43
    /**
44
     * @var Plugin\SettingsProvider
45
     */
46
    private $settingsProvider;
47
48
    /**
49
     * @var PluginInstaller
50
     */
51
    private $pluginInstaller;
52
    /**
53
     * @var Plugin\Manager
54
     */
55
    private $pluginManager;
56
57
    /**
58
     * @var Plugins
59
     */
60
    private $marketplacePlugins;
61
62
    /**
63
     * Controller constructor.
64
     * @param Translator $translator
65
     * @param Plugin\SettingsProvider $settingsProvider
66
     * @param PluginInstaller $pluginInstaller
67
     * @param Plugins $marketplacePlugins
68
     */
69
    public function __construct(Translator $translator, Plugin\SettingsProvider $settingsProvider, PluginInstaller $pluginInstaller, $marketplacePlugins = null)
70
    {
71
        $this->translator = $translator;
72
        $this->settingsProvider = $settingsProvider;
73
        $this->pluginInstaller = $pluginInstaller;
74
        $this->pluginManager = Plugin\Manager::getInstance();
75
76
        if (!empty($marketplacePlugins)) {
77
            $this->marketplacePlugins = $marketplacePlugins;
78
        } elseif (Marketplace::isMarketplaceEnabled()) {
79
            // we load it manually as marketplace might not be loaded
80
            $this->marketplacePlugins = StaticContainer::get('Piwik\Plugins\Marketplace\Plugins');
81
        }
82
83
        parent::__construct();
84
    }
85
86
    public function uploadPlugin()
87
    {
88
        static::dieIfPluginsAdminIsDisabled();
0 ignored issues
show
Bug introduced by
Since dieIfPluginsAdminIsDisabled() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of dieIfPluginsAdminIsDisabled() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
89
        Piwik::checkUserHasSuperUserAccess();
90
91
        $nonce = Common::getRequestVar('nonce', null, 'string');
92
93
        if (!Nonce::verifyNonce(MarketplaceController::INSTALL_NONCE, $nonce)) {
94
            throw new \Exception($this->translator->translate('General_ExceptionNonceMismatch'));
95
        }
96
97
        Nonce::discardNonce(MarketplaceController::INSTALL_NONCE);
98
99
        if (empty($_FILES['pluginZip'])) {
100
            throw new \Exception('You did not specify a ZIP file.');
101
        }
102
103
        if (!empty($_FILES['pluginZip']['error'])) {
104
            throw new \Exception('Something went wrong during the plugin file upload. Please try again.');
105
        }
106
107
        $file = $_FILES['pluginZip']['tmp_name'];
108
        if (!file_exists($file)) {
109
            throw new \Exception('Something went wrong during the plugin file upload. Please try again.');
110
        }
111
112
        $view = $this->configureView('@CorePluginsAdmin/uploadPlugin');
113
114
        $pluginMetadata = $this->pluginInstaller->installOrUpdatePluginFromFile($file);
115
116
        $view->nonce = Nonce::getNonce(static::ACTIVATE_NONCE);
0 ignored issues
show
Documentation introduced by
The property nonce does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
117
        $view->plugin = array(
0 ignored issues
show
Documentation introduced by
The property plugin does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
118
            'name'        => $pluginMetadata->name,
119
            'version'     => $pluginMetadata->version,
120
            'isTheme'     => !empty($pluginMetadata->theme),
121
            'isActivated' => $this->pluginManager->isPluginActivated($pluginMetadata->name)
122
        );
123
124
        return $view->render();
125
    }
126
127
    /**
128
     * @deprecated
129
     */
130
    public function browsePlugins()
131
    {
132
        $this->redirectToIndex('Marketplace', 'overview');
133
    }
134
135
    /**
136
     * @deprecated
137
     */
138
    public function browseThemes()
139
    {
140
        $this->redirectToIndex('Marketplace', 'overview', null, null, null, array('show' => 'themes'));
141
    }
142
143
    private function dieIfPluginsAdminIsDisabled()
144
    {
145
        if (!CorePluginsAdmin::isPluginsAdminEnabled()) {
146
            throw new \Exception('Enabling, disabling and uninstalling plugins has been disabled by Piwik admins.
147
            Please contact your Piwik admins with your request so they can assist you.');
148
        }
149
    }
150
151
    private function createPluginsOrThemesView($template, $themesOnly)
152
    {
153
        Piwik::checkUserHasSuperUserAccess();
154
155
        $view = $this->configureView('@CorePluginsAdmin/' . $template);
156
157
        $view->updateNonce = Nonce::getNonce(MarketplaceController::UPDATE_NONCE);
0 ignored issues
show
Documentation introduced by
The property updateNonce does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
158
        $view->activateNonce = Nonce::getNonce(static::ACTIVATE_NONCE);
0 ignored issues
show
Documentation introduced by
The property activateNonce does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
159
        $view->uninstallNonce = Nonce::getNonce(static::UNINSTALL_NONCE);
0 ignored issues
show
Documentation introduced by
The property uninstallNonce does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
160
        $view->deactivateNonce = Nonce::getNonce(static::DEACTIVATE_NONCE);
0 ignored issues
show
Documentation introduced by
The property deactivateNonce does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
161
        $view->pluginsInfo = $this->getPluginsInfo($themesOnly);
0 ignored issues
show
Documentation introduced by
The property pluginsInfo does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
162
163
        $users = Request::processRequest('UsersManager.getUsers');
164
        $view->otherUsersCount = count($users) - 1;
0 ignored issues
show
Documentation introduced by
The property otherUsersCount does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
165
        $view->themeEnabled = $this->pluginManager->getThemeEnabled()->getPluginName();
0 ignored issues
show
Documentation introduced by
The property themeEnabled does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
166
167
        $view->pluginNamesHavingSettings = array_keys($this->settingsProvider->getAllSystemSettings());
0 ignored issues
show
Documentation introduced by
The property pluginNamesHavingSettings does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
168
        $view->isMarketplaceEnabled = Marketplace::isMarketplaceEnabled();
0 ignored issues
show
Documentation introduced by
The property isMarketplaceEnabled does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
169
        $view->isPluginsAdminEnabled = CorePluginsAdmin::isPluginsAdminEnabled();
0 ignored issues
show
Documentation introduced by
The property isPluginsAdminEnabled does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
170
171
        $view->pluginsHavingUpdate    = array();
0 ignored issues
show
Documentation introduced by
The property pluginsHavingUpdate does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
172
        $view->marketplacePluginNames = array();
0 ignored issues
show
Documentation introduced by
The property marketplacePluginNames does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
173
174
        if (Marketplace::isMarketplaceEnabled() && $this->marketplacePlugins) {
175
            try {
176
                $view->marketplacePluginNames = $this->marketplacePlugins->getAvailablePluginNames($themesOnly);
0 ignored issues
show
Documentation introduced by
The property marketplacePluginNames does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
177
                $view->pluginsHavingUpdate    = $this->marketplacePlugins->getPluginsHavingUpdate();
0 ignored issues
show
Documentation introduced by
The property pluginsHavingUpdate does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
178
            } catch(Exception $e) {
179
                // curl exec connection error (ie. server not connected to internet)
180
            }
181
        }
182
183
        return $view;
184
    }
185
186
    public function plugins()
187
    {
188
        $view = $this->createPluginsOrThemesView('plugins', $themesOnly = false);
189
        return $view->render();
190
    }
191
192
    public function themes()
193
    {
194
        $view = $this->createPluginsOrThemesView('themes', $themesOnly = true);
195
        return $view->render();
196
    }
197
198 View Code Duplication
    protected function configureView($template)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
199
    {
200
        Piwik::checkUserIsNotAnonymous();
201
202
        $view = new View($template);
203
        $this->setBasicVariablesView($view);
204
205
        // If user can manage plugins+themes, display a warning if config not writable
206
        if (CorePluginsAdmin::isPluginsAdminEnabled()) {
207
            $this->displayWarningIfConfigFileNotWritable();
208
        }
209
210
        $view->errorMessage = '';
0 ignored issues
show
Documentation introduced by
The property errorMessage does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
211
212
        return $view;
213
    }
214
215
    protected function getPluginsInfo($themesOnly = false)
216
    {
217
        $plugins = $this->pluginManager->loadAllPluginsAndGetTheirInfo();
218
219
        foreach ($plugins as $pluginName => &$plugin) {
220
221
            $plugin['isCorePlugin'] = $this->pluginManager->isPluginBundledWithCore($pluginName);
222
223
            if (!empty($plugin['info']['description'])) {
224
                $plugin['info']['description'] = $this->translator->translate($plugin['info']['description']);
225
            }
226
227
            if (!isset($plugin['info'])) {
228
229
                $suffix = $this->translator->translate('CorePluginsAdmin_PluginNotWorkingAlternative');
230
                // If the plugin has been renamed, we do not show message to ask user to update plugin
231
                list($pluginNameRenamed, $methodName) = Request::getRenamedModuleAndAction($pluginName, 'index');
0 ignored issues
show
Unused Code introduced by
The assignment to $methodName is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
232
                if ($pluginName != $pluginNameRenamed) {
233
                    $suffix = "You may uninstall the plugin or manually delete the files in piwik/plugins/$pluginName/";
234
                }
235
236
                $description = '<strong>'
237
                    . $this->translator->translate('CorePluginsAdmin_PluginNotCompatibleWith', array($pluginName, self::getPiwikVersion()))
238
                    . '</strong><br/>'
239
                    . $suffix;
240
                $plugin['info'] = array(
241
                    'description' => $description,
242
                    'version'     => $this->translator->translate('General_Unknown'),
243
                    'theme'       => false,
244
                );
245
            }
246
        }
247
248
        $pluginsFiltered = $this->keepPluginsOrThemes($themesOnly, $plugins);
249
        return $pluginsFiltered;
250
    }
251
252
    protected function keepPluginsOrThemes($themesOnly, $plugins)
253
    {
254
        $pluginsFiltered = array();
255
        foreach ($plugins as $name => $thisPlugin) {
256
257
            $isTheme = false;
258
            if (!empty($thisPlugin['info']['theme'])) {
259
                $isTheme = (bool)$thisPlugin['info']['theme'];
260
            }
261
            if (($themesOnly && $isTheme)
262
                || (!$themesOnly && !$isTheme)
263
            ) {
264
                $pluginsFiltered[$name] = $thisPlugin;
265
            }
266
        }
267
        return $pluginsFiltered;
268
    }
269
270
    public function safemode($lastError = array())
271
    {
272
        ob_clean();
273
        
274
        $this->tryToRepairPiwik();
275
276
        if (empty($lastError)) {
277
            $lastError = array(
278
                'message' => Common::getRequestVar('error_message', null, 'string'),
279
                'file'    => Common::getRequestVar('error_file', null, 'string'),
280
                'line'    => Common::getRequestVar('error_line', null, 'integer')
281
            );
282
        }
283
284
        $outputFormat = Common::getRequestVar('format', 'html', 'string');
285
        $outputFormat = strtolower($outputFormat);
286
287
        if (!empty($outputFormat) && 'html' !== $outputFormat) {
288
289
            $errorMessage = $lastError['message'];
290
291
            if (Piwik::isUserIsAnonymous()) {
292
                $errorMessage = 'A fatal error occurred.';
293
            }
294
295
            $response = new \Piwik\API\ResponseBuilder($outputFormat);
296
            $message  = $response->getResponseException(new Exception($errorMessage));
297
298
            return $message;
299
        }
300
301
        if (Common::isPhpCliMode()) {
302
            throw new Exception("Error: " . var_export($lastError, true));
303
        }
304
        $view = new View('@CorePluginsAdmin/safemode');
305
        $view->lastError   = $lastError;
0 ignored issues
show
Documentation introduced by
The property lastError does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
306
        $view->isAllowedToTroubleshootAsSuperUser = $this->isAllowedToTroubleshootAsSuperUser();
0 ignored issues
show
Documentation introduced by
The property isAllowedToTroubleshootAsSuperUser does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
307
        $view->isSuperUser = Piwik::hasUserSuperUserAccess();
0 ignored issues
show
Documentation introduced by
The property isSuperUser does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
308
        $view->isAnonymousUser = Piwik::isUserIsAnonymous();
0 ignored issues
show
Documentation introduced by
The property isAnonymousUser does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
309
        $view->plugins         = $this->pluginManager->loadAllPluginsAndGetTheirInfo();
0 ignored issues
show
Documentation introduced by
The property plugins does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
310
        $view->deactivateNonce = Nonce::getNonce(static::DEACTIVATE_NONCE);
0 ignored issues
show
Documentation introduced by
The property deactivateNonce does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
311
        $view->deactivateIAmSuperUserSalt = Common::getRequestVar('i_am_super_user', '', 'string');
0 ignored issues
show
Documentation introduced by
The property deactivateIAmSuperUserSalt does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
312
        $view->uninstallNonce  = Nonce::getNonce(static::UNINSTALL_NONCE);
0 ignored issues
show
Documentation introduced by
The property uninstallNonce does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
313
        $view->emailSuperUser  = implode(',', Piwik::getAllSuperUserAccessEmailAddresses());
0 ignored issues
show
Documentation introduced by
The property emailSuperUser does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
314
        $view->piwikVersion    = Version::VERSION;
0 ignored issues
show
Documentation introduced by
The property piwikVersion does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
315
        $view->showVersion     = !Common::getRequestVar('tests_hide_piwik_version', 0);
0 ignored issues
show
Documentation introduced by
The property showVersion does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
316
        $view->pluginCausesIssue = '';
0 ignored issues
show
Documentation introduced by
The property pluginCausesIssue does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
317
318
        // When the CSS merger in StylesheetUIAssetMerger throws an exception, safe mode is displayed.
319
        // This flag prevents an infinite loop where safemode would try to re-generate the cache buster which requires CSS merger..
320
        $view->disableCacheBuster();
321
322
        if (!empty($lastError['file'])) {
323
            preg_match('/piwik\/plugins\/(.*)\//', $lastError['file'], $matches);
324
325
            if (!empty($matches[1])) {
326
                $view->pluginCausesIssue = $matches[1];
0 ignored issues
show
Documentation introduced by
The property pluginCausesIssue does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
327
            }
328
        }
329
330
        return $view->render();
331
    }
332
333
    public function activate($redirectAfter = true)
334
    {
335
        $pluginName = $this->initPluginModification(static::ACTIVATE_NONCE);
336
        $this->dieIfPluginsAdminIsDisabled();
337
338
        $this->pluginManager->activatePlugin($pluginName);
339
340
        if ($redirectAfter) {
341
            $message = $this->translator->translate('CorePluginsAdmin_SuccessfullyActicated', array($pluginName));
342
            
343
            if ($this->settingsProvider->getSystemSettings($pluginName)) {
344
                $target   = sprintf('<a href="index.php%s#%s">',
345
                    Url::getCurrentQueryStringWithParametersModified(array('module' => 'CoreAdminHome', 'action' => 'generalSettings')),
346
                    $pluginName);
347
                $message .= ' ' . $this->translator->translate('CorePluginsAdmin_ChangeSettingsPossible', array($target, '</a>'));
348
            }
349
350
            $notification = new Notification($message);
351
            $notification->raw     = true;
352
            $notification->title   = $this->translator->translate('General_WellDone');
353
            $notification->context = Notification::CONTEXT_SUCCESS;
354
            Notification\Manager::notify('CorePluginsAdmin_PluginActivated', $notification);
355
356
            $redirectTo = Common::getRequestVar('redirectTo', '', 'string');
357
            if (!empty($redirectTo) && $redirectTo === 'marketplace') {
358
                $this->redirectToIndex('Marketplace', 'overview');
359
            } elseif (!empty($redirectTo) && $redirectTo === 'referrer') {
360
                $this->redirectAfterModification($redirectAfter);
361
            } else {
362
                $plugin = $this->pluginManager->loadPlugin($pluginName);
363
364
                $actionToRedirect = 'plugins';
365
                if ($plugin->isTheme()) {
366
                    $actionToRedirect = 'themes';
367
                }
368
369
                $this->redirectToIndex('CorePluginsAdmin', $actionToRedirect);
370
            }
371
372
        }
373
    }
374
375
    public function deactivate($redirectAfter = true)
376
    {
377
        if($this->isAllowedToTroubleshootAsSuperUser()) {
378
            Piwik::doAsSuperUser(function() use ($redirectAfter) {
379
                $this->doDeactivatePlugin($redirectAfter);
380
            });
381
        } else {
382
            $this->doDeactivatePlugin($redirectAfter);
383
        }
384
    }
385
386
    public function uninstall($redirectAfter = true)
387
    {
388
        $pluginName = $this->initPluginModification(static::UNINSTALL_NONCE);
389
        $this->dieIfPluginsAdminIsDisabled();
390
391
        $uninstalled = $this->pluginManager->uninstallPlugin($pluginName);
392
393
        if (!$uninstalled) {
394
            $path = Filesystem::getPathToPiwikRoot() . '/plugins/' . $pluginName . '/';
395
            $messagePermissions = Filechecks::getErrorMessageMissingPermissions($path);
396
397
            $messageIntro = $this->translator->translate("Warning: \"%s\" could not be uninstalled. Piwik did not have enough permission to delete the files in $path. ",
398
                $pluginName);
399
            $exitMessage  = $messageIntro . "<br/><br/>" . $messagePermissions;
400
            $exitMessage .= "<br> Or manually delete this directory (using FTP or SSH access)";
401
402
            $ex = new MissingFilePermissionException($exitMessage);
403
            $ex->setIsHtmlMessage();
404
405
            throw $ex;
406
        }
407
408
        $this->redirectAfterModification($redirectAfter);
409
    }
410
411
    public function showLicense()
412
    {
413
        $pluginName = Common::getRequestVar('pluginName', null, 'string');
414
415
        $metadata = new Plugin\MetadataLoader($pluginName);
416
        $license_file = $metadata->getPathToLicenseFile();
417
418
        $license = 'No license file found for this plugin.';
419
        if(!empty($license_file)) {
420
            $license = file_get_contents($license_file);
421
            $license = nl2br($license);
422
        }
423
424
        $view = $this->configureView('@CorePluginsAdmin/license');
425
        $view->pluginName = $pluginName;
0 ignored issues
show
Documentation introduced by
The property pluginName does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
426
        $view->license = $license;
0 ignored issues
show
Documentation introduced by
The property license does not exist on object<Piwik\View>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
427
        return $view->render();
428
    }
429
430 View Code Duplication
    protected function initPluginModification($nonceName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
431
    {
432
        Piwik::checkUserHasSuperUserAccess();
433
434
        $nonce = Common::getRequestVar('nonce', null, 'string');
435
436
        if (!Nonce::verifyNonce($nonceName, $nonce)) {
437
            throw new \Exception($this->translator->translate('General_ExceptionNonceMismatch'));
438
        }
439
440
        Nonce::discardNonce($nonceName);
441
442
        $pluginName = Common::getRequestVar('pluginName', null, 'string');
443
444
        if (!$this->pluginManager->isValidPluginName($pluginName)) {
445
            throw new Exception('Invalid plugin name');
446
        }
447
448
        return $pluginName;
449
    }
450
451
    protected function redirectAfterModification($redirectAfter)
452
    {
453
        if ($redirectAfter) {
454
            Url::redirectToReferrer();
455
        }
456
    }
457
458
    private function tryToRepairPiwik()
459
    {
460
        // in case any opcaches etc were not cleared after an update for instance. Might prevent from getting the
461
        // error again
462
        try {
463
            Filesystem::deleteAllCacheOnUpdate();
464
        } catch (Exception $e) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
465
    }
466
467
    /**
468
     * Let Super User troubleshoot in safe mode, even when Login is broken, with this special trick
469
     *
470
     * @return bool
471
     * @throws Exception
472
     */
473
    protected function isAllowedToTroubleshootAsSuperUser()
474
    {
475
        $isAllowedToTroubleshootAsSuperUser = false;
476
        $salt = SettingsPiwik::getSalt();
477 View Code Duplication
        if (!empty($salt)) {
478
            $saltFromRequest = Common::getRequestVar('i_am_super_user', '', 'string');
479
            $isAllowedToTroubleshootAsSuperUser = ($salt == $saltFromRequest);
480
        }
481
        return $isAllowedToTroubleshootAsSuperUser;
482
    }
483
484
    /**
485
     * @param $redirectAfter
486
     * @throws Exception
487
     */
488
    protected function doDeactivatePlugin($redirectAfter)
489
    {
490
        $pluginName = $this->initPluginModification(static::DEACTIVATE_NONCE);
491
        $this->dieIfPluginsAdminIsDisabled();
492
493
        $this->pluginManager->deactivatePlugin($pluginName);
494
        $this->redirectAfterModification($redirectAfter);
495
    }
496
497
}
498