Skip to content
Extraits de code Groupes Projets
Valider 6f6a2a9b rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

When Piwik DB needs to be upgraded, the API should return a valid response

parent 0841a4c8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -10,6 +10,7 @@ namespace Piwik\Plugins\CoreUpdater; ...@@ -10,6 +10,7 @@ namespace Piwik\Plugins\CoreUpdater;
use Exception; use Exception;
use Piwik\Access; use Piwik\Access;
use Piwik\API\ResponseBuilder;
use Piwik\Common; use Piwik\Common;
use Piwik\Filesystem; use Piwik\Filesystem;
use Piwik\FrontController; use Piwik\FrontController;
...@@ -73,6 +74,15 @@ class CoreUpdater extends \Piwik\Plugin ...@@ -73,6 +74,15 @@ class CoreUpdater extends \Piwik\Plugin
if (FrontController::shouldRethrowException()) { if (FrontController::shouldRethrowException()) {
throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" . throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" .
"--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n"); "--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n");
} elseif ($module === 'API') {
$outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $_GET + $_POST));
$response = new ResponseBuilder($outputFormat);
$e = new Exception('Database Upgrade Required. Your Piwik database is out-of-date, and must be upgraded before you can continue.');
echo $response->getResponseException($e);
Common::sendResponseCode(503);
exit;
} else { } else {
Piwik::redirectToModule('CoreUpdater'); Piwik::redirectToModule('CoreUpdater');
} }
......
...@@ -17,6 +17,18 @@ describe("CoreUpdaterDb", function () { ...@@ -17,6 +17,18 @@ describe("CoreUpdaterDb", function () {
testEnvironment.save(); testEnvironment.save();
}); });
function apiUpgradeTest(format) {
it("should start the updater when an old version of Piwik is detected in the DB", function (done) {
expect.file('CoreUpdater.API.ErrorMessage' + format + '.txt').to.be.pageContents(function (page) {
page.load('');
page.downloadUrl('?module=API&method=API.getPiwikVersion&format=' + format);
}, done);
});
}
var formats = ['CSV', 'TSV', 'XML', 'JSON', 'PHP'];
formats.forEach(apiUpgradeTest);
it("should start the updater when an old version of Piwik is detected in the DB", function (done) { it("should start the updater when an old version of Piwik is detected in the DB", function (done) {
expect.screenshot("main").to.be.capture(function (page) { expect.screenshot("main").to.be.capture(function (page) {
page.load(""); page.load("");
......
...@@ -114,6 +114,10 @@ PageRenderer.prototype.downloadLink = function (selector, waitTime) { ...@@ -114,6 +114,10 @@ PageRenderer.prototype.downloadLink = function (selector, waitTime) {
this.queuedEvents.push([this._downloadLink, waitTime, selector]); this.queuedEvents.push([this._downloadLink, waitTime, selector]);
}; };
PageRenderer.prototype.downloadUrl = function (url, waitTime) {
this.queuedEvents.push([this._downloadUrl, waitTime, url]);
};
PageRenderer.prototype.dragDrop = function (startSelector, endSelector, waitTime) { PageRenderer.prototype.dragDrop = function (startSelector, endSelector, waitTime) {
this.mousedown(startSelector, waitTime); this.mousedown(startSelector, waitTime);
this.mouseMove(endSelector, waitTime); this.mouseMove(endSelector, waitTime);
...@@ -220,16 +224,23 @@ PageRenderer.prototype._evaluate = function (impl, callback) { ...@@ -220,16 +224,23 @@ PageRenderer.prototype._evaluate = function (impl, callback) {
}; };
PageRenderer.prototype._downloadLink = function (str, callback) { PageRenderer.prototype._downloadLink = function (str, callback) {
var response = this.webpage.evaluate(function (selector) { var url = this.webpage.evaluate(function (selector) {
var $ = window.jQuery, return $(selector).attr('href');
url = $(selector).attr('href'); }, str);
this._downloadUrl(url, callback);
};
PageRenderer.prototype._downloadUrl = function (url, callback) {
var response = this.webpage.evaluate(function (url) {
var $ = window.jQuery;
return $.ajax({ return $.ajax({
type: "GET", type: "GET",
url: url, url: url,
async: false async: false
}).responseText; }).responseText;
}, str); }, url);
this.downloadedContents = response; this.downloadedContents = response;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter