Skip to content

Commit

Permalink
try to fix oneclickupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
diosmosis committed Mar 31, 2020
1 parent 4ed6ad4 commit 246de42
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
12 changes: 12 additions & 0 deletions plugins/CoreUpdater/Controller.php
Expand Up @@ -12,6 +12,7 @@
use Piwik\AssetManager;
use Piwik\Common;
use Piwik\Config;
use Piwik\DataTable\Renderer\Json;
use Piwik\DbHelper;
use Piwik\Filechecks;
use Piwik\FileIntegrity;
Expand Down Expand Up @@ -172,6 +173,17 @@ public function oneClickUpdate()
return $view->render();
}

public function oneClickUpdatePartTwo()
{
Piwik::checkUserHasSuperUserAccess();

Json::sendHeaderJSON();

$messages = $this->updater->oneClickUpdatePartTwo();

echo json_encode($messages);
}

public function oneClickResults()
{
Filesystem::deleteAllCacheOnUpdate();
Expand Down
50 changes: 39 additions & 11 deletions plugins/CoreUpdater/Updater.php
Expand Up @@ -23,6 +23,7 @@
use Piwik\SettingsServer;
use Piwik\Translation\Translator;
use Piwik\Unzip;
use Piwik\Url;
use Piwik\Version;

class Updater
Expand Down Expand Up @@ -138,9 +139,45 @@ public function updatePiwik($https = true)
throw new UpdaterException($e, $messages);
}

$partTwoUrl = Url::getCurrentUrlWithoutQueryString() . Url::getCurrentQueryStringWithParametersModified([
'action' => 'oneClickUpdatePartTwo',
]);

$response = Http::sendHttpRequest($partTwoUrl, 300);
$response = @json_decode($response, $assoc = true);

$messages = array_merge($messages, $response);

try {
$disabledPluginNames = $this->disableIncompatiblePlugins($newVersion);
if (!empty($disabledPluginNames)) {
$messages[] = $this->translator->translate('CoreUpdater_DisablingIncompatiblePlugins', implode(', ', $disabledPluginNames));
}
} catch (Exception $e) {
throw new UpdaterException($e, $messages);
}

return $messages;
}

public function oneClickUpdatePartTwo()
{
$messages = [];

if (Marketplace::isMarketplaceEnabled() && !empty($marketplaceClient)) {
$newVersion = Version::VERSION;

// we also need to make sure to create a new instance here as otherwise we would change the "global"
// environment, but we only want to change piwik version temporarily for this task here
$environment = StaticContainer::getContainer()->make('Piwik\Plugins\Marketplace\Environment');
$environment->setPiwikVersion($newVersion);
/** @var \Piwik\Plugins\Marketplace\Api\Client $marketplaceClient */
$marketplaceClient = StaticContainer::getContainer()->make('Piwik\Plugins\Marketplace\Api\Client', array(
'environment' => $environment
));

try {

if (Marketplace::isMarketplaceEnabled()) {
$messages[] = $this->translator->translate('CoreUpdater_CheckingForPluginUpdates');
$pluginManager = PluginManager::getInstance();
$pluginManager->loadAllPluginsAndGetTheirInfo();
Expand All @@ -152,7 +189,7 @@ public function updatePiwik($https = true)
foreach ($pluginsWithUpdate as $pluginWithUpdate) {
$pluginName = $pluginWithUpdate['name'];
$messages[] = $this->translator->translate('CoreUpdater_UpdatingPluginXToVersionY',
array($pluginName, $pluginWithUpdate['version']));
array($pluginName, $pluginWithUpdate['version']));
$pluginInstaller = new PluginInstaller($marketplaceClient);
$pluginInstaller->installOrUpdatePluginFromMarketplace($pluginName);
}
Expand All @@ -163,15 +200,6 @@ public function updatePiwik($https = true)
throw new UpdaterException($e, $messages);
}

try {
$disabledPluginNames = $this->disableIncompatiblePlugins($newVersion);
if (!empty($disabledPluginNames)) {
$messages[] = $this->translator->translate('CoreUpdater_DisablingIncompatiblePlugins', implode(', ', $disabledPluginNames));
}
} catch (Exception $e) {
throw new UpdaterException($e, $messages);
}

return $messages;
}

Expand Down
5 changes: 5 additions & 0 deletions plugins/UserCountry/VisitorGeolocator.php
Expand Up @@ -305,6 +305,11 @@ private function getDefaultProvider()
public static function getDefaultLocationCache()
{
if (self::$defaultLocationCache === null) {
if (!class_exists(Transient::class)) {
$ex = new \Exception();
print $ex->getTraceAsString()."\n";
exit;
}
self::$defaultLocationCache = new Transient();
}
return self::$defaultLocationCache;
Expand Down
1 change: 1 addition & 0 deletions tests/PHPUnit/Fixtures/LatestStableInstall.php
Expand Up @@ -140,6 +140,7 @@ private function cloneMatomoPackageRepo()
{
$pathToMatomoPackage = PIWIK_INCLUDE_PATH . '/../matomo-package';
if (file_exists($pathToMatomoPackage)) {
return;
Filesystem::unlinkRecursive($pathToMatomoPackage, true);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/UI/specs/OneClickUpdate_spec.js
Expand Up @@ -52,7 +52,7 @@ describe("OneClickUpdate", function () {
it('should update successfully and show the finished update screen', async function () {
await page.click('#updateUsingHttp');
await page.waitForNetworkIdle();
await page.waitFor('.content');
await page.waitFor('.content', { timeout: 120000 });
expect(await page.screenshot({ fullPage: true })).to.matchImage('update_success');
});

Expand Down

0 comments on commit 246de42

Please sign in to comment.