Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds update script to remove GeoIP2 plugin from marketplace #12897

Merged
merged 3 commits into from May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions core/Updates/3.5.1-b1.php
@@ -0,0 +1,48 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Updates;

use Piwik\Filesystem;
use Piwik\Notification;
use Piwik\Plugin\Manager;
use Piwik\SettingsServer;
use Piwik\Updater;
use Piwik\Updates as PiwikUpdates;

class Updates_3_5_1_b1 extends PiwikUpdates
{
public function doUpdate(Updater $updater)
{
// try to deactivate and remove the GeoIP2 plugin from marketplace,
// which causes problems with GeoIp2 plugin included in core
// Skip if new file `isoRegionNames.php` is detected within `GeoIP2` directory, as that means filesystem is case
// insensitive and GeoIP2 plugin has been partially overwritten by GeoIp2 plugin
try {
if (is_dir(PIWIK_INCLUDE_PATH . '/plugins/GeoIP2') && !file_exists(PIWIK_INCLUDE_PATH . '/plugins/GeoIP2/data/isoRegionNames.php')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we would need to add a test that makes sure this file exists? Just to be safe... if we otherwise ever remove the file, the plugin will be removed when someone updates from say an older Matomo version to a much newer. Be good to name the test clear to indicate what happens if the file does not exist.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. Will add the test now


// first remove the plugin files, as trying to deactivate would load the plugin files resulting in a fatal error
Filesystem::unlinkRecursive(PIWIK_INCLUDE_PATH . '/plugins/GeoIP2', true);

// if plugin was activated, trigger deactivation to remove the config entry and set a notification
if (Manager::getInstance()->isPluginActivated('GeoIP2')) {
@Manager::getInstance()->deactivatePlugin('GeoIP2');
$notification = new Notification('GeoIP2 plugin from Marketplace has been removed due to compatibility issues. Please check your geolocation settings.');
$notification->context = Notification::CONTEXT_WARNING;
$notification->type = Notification::TYPE_PERSISTENT;
Notification\Manager::notify('GeoIP2_update_warning', $notification);
}

// uninstall the plugin to remove it from config
@Manager::getInstance()->uninstallPlugin('GeoIP2');
}
} catch (\Exception $e) {
}
}
}
2 changes: 1 addition & 1 deletion core/Version.php
Expand Up @@ -20,7 +20,7 @@ final class Version
* The current Matomo version.
* @var string
*/
const VERSION = '3.5.0';
const VERSION = '3.5.1-b1';

public function isStableVersion($version)
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/GeoIp2/tests/Integration/LocationProviderTest.php
Expand Up @@ -11,7 +11,7 @@
use Piwik\Plugins\GeoIp2\LocationProvider\GeoIp2;

/**
* @group GeoIp2x
* @group GeoIp2
*/
class ConvertRegionCodesToIsoTest extends \PHPUnit_Framework_TestCase
{
Expand Down
22 changes: 22 additions & 0 deletions plugins/GeoIp2/tests/Integration/UpdateTest.php
@@ -0,0 +1,22 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\GeoIp2\tests\Integration;

/**
* @group GeoIp2
*/
class UpdateTest extends \PHPUnit_Framework_TestCase
{
public function testEnsureFileForUpdateIsPresent()
{
// In update Updates_3_5_1_b1 the file `plugins/GeoIp2/data/isoRegionNames.php` is used to check file system
// case sensitivity. Therefor we need to ensure this file is present unless the update script isn't changed
$this->assertFileExists(PIWIK_INCLUDE_PATH . '/plugins/GeoIp2/data/isoRegionNames.php');
}
}