Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/View.php7
-rw-r--r--core/View/OneClickDone.php90
-rw-r--r--plugins/CoreUpdater/Controller.php53
-rw-r--r--plugins/CoreUpdater/templates/update_one_click_results.tpl (renamed from plugins/CoreUpdater/templates/update_one_click_done.tpl)0
4 files changed, 130 insertions, 20 deletions
diff --git a/core/View.php b/core/View.php
index b6f700184f..f48ad2058d 100644
--- a/core/View.php
+++ b/core/View.php
@@ -30,6 +30,8 @@ class Piwik_View implements Piwik_View_Interface
const MOBILE = 1;
const CLI = 2;
+ const COREUPDATER_ONE_CLICK_DONE = 'update_one_click_done';
+
private $template = '';
private $smarty = false;
private $variables = array();
@@ -262,6 +264,11 @@ class Piwik_View implements Piwik_View_Interface
*/
static public function factory( $templateName = null, $viewType = null)
{
+ if ($templateName == self::COREUPDATER_ONE_CLICK_DONE)
+ {
+ return new Piwik_View_OneClickDone(Piwik::getCurrentUserTokenAuth());
+ }
+
Piwik_PostEvent('View.getViewType', $viewType);
// get caller
diff --git a/core/View/OneClickDone.php b/core/View/OneClickDone.php
new file mode 100644
index 0000000000..7e69c882d3
--- /dev/null
+++ b/core/View/OneClickDone.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ * @version $Id$
+ *
+ * @category Piwik
+ * @package Piwik
+ */
+
+/**
+ * Post-update view
+ *
+ * During a Piwik software update, there will be instances of old classes
+ * loaded in memory. This is problematic as we will start to instantiate
+ * new classes which may not be backward compatible. This class provides
+ * a clean bridge/transition by forcing a new request.
+ *
+ * This class needs to be self-contained, with no external dependencies.
+ *
+ * @package Piwik
+ */
+class Piwik_View_OneClickDone
+{
+ /**
+ * @var string
+ */
+ private $tokenAuth;
+
+ /**
+ * @var string
+ */
+ public $coreError;
+
+ /**
+ * @var array
+ */
+ public $feedbackMessages;
+
+ public function __construct($tokenAuth)
+ {
+ $this->tokenAuth = $tokenAuth;
+ }
+
+ /**
+ * Outputs the data.
+ *
+ * @return string html
+ */
+ public function render()
+ {
+ // set response headers
+ @header('Content-Type: text/html; charset=UTF-8');
+ @header('Pragma: ');
+ @header('Expires: ');
+ @header('Cache-Control: must-revalidate');
+ @header('X-Frame-Options: deny');
+
+ $error = htmlspecialchars($this->coreError, ENT_QUOTES, 'UTF-8');
+ $messages = htmlspecialchars(serialize($this->feedbackMessages), ENT_QUOTES, 'UTF-8');
+ $tokenAuth = $this->tokenAuth;
+
+ // use a heredoc instead of an external file
+ echo <<<END_OF_TEMPLATE
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <meta charset="utf-8" />
+ <title></title>
+ </head>
+ <body>
+ <form name="myform" method="post" action="?module=CoreUpdater&amp;action=oneClickResults">
+ <input type="hidden" name="token_auth" value="$tokenAuth" />
+ <input type="hidden" name="error" value="$error" />
+ <input type="hidden" name="messages" value="$messages" />
+ </form>
+ <script type="text/javascript">
+ document.myform.submit();
+ </script>
+ <noscript>
+ <button type="submit" value="Continue" />
+ </noscript>
+ </body>
+</html>
+END_OF_TEMPLATE;
+ }
+}
diff --git a/plugins/CoreUpdater/Controller.php b/plugins/CoreUpdater/Controller.php
index 4042bdee31..355173e5c0 100644
--- a/plugins/CoreUpdater/Controller.php
+++ b/plugins/CoreUpdater/Controller.php
@@ -1,7 +1,7 @@
<?php
/**
* Piwik - Open source web analytics
- *
+ *
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
* @version $Id$
@@ -28,7 +28,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
{
Piwik::checkUserIsSuperUser();
$newVersion = $this->checkNewVersionIsAvailableOrDie();
-
+
$view = Piwik_View::factory('update_new_version_available');
$view->piwik_version = Piwik_Version::VERSION;
$view->piwik_new_version = $newVersion;
@@ -54,7 +54,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
array('oneClick_Copy', Piwik_Translate('CoreUpdater_InstallingTheLatestVersion')),
array('oneClick_Finished', Piwik_Translate('CoreUpdater_PiwikUpdatedSuccessfully')),
);
-
+
$errorMessage = false;
$messages = array();
foreach($steps as $step) {
@@ -68,13 +68,26 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
break;
}
}
-
+
+ // this is a magic template to trigger the Piwik_View_Update
$view = Piwik_View::factory('update_one_click_done');
$view->coreError = $errorMessage;
$view->feedbackMessages = $messages;
echo $view->render();
}
+ public function oneClickResults()
+ {
+ $this->checkTokenInUrl();
+ Piwik_API_Request::reloadAuthUsingTokenAuth($_POST);
+ Piwik::checkUserIsSuperUser();
+
+ $view = Piwik_View::factory('update_one_click_results');
+ $view->coreError = Piwik_Common::getRequestVar('error', '', 'string', $_POST);
+ $view->feedbackMessages = safe_unserialize(Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('messages', '', 'string', $_POST)));
+ echo $view->render();
+ }
+
private function checkNewVersionIsAvailableOrDie()
{
$newVersion = Piwik_UpdateCheck::isNewestVersionAvailable();
@@ -84,7 +97,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
}
return $newVersion;
}
-
+
private function oneClick_Download()
{
$this->pathPiwikZip = PIWIK_USER_PATH . self::PATH_TO_EXTRACT_LATEST_VERSION . 'latest.zip';
@@ -94,7 +107,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
$url = Piwik_Config::getInstance()->General['latest_version_url'] . '?cb=' . $this->newVersion;
$fetched = Piwik_Http::fetchRemoteFile($url, $this->pathPiwikZip);
}
-
+
private function oneClick_Unpack()
{
$pathExtracted = PIWIK_USER_PATH . self::PATH_TO_EXTRACT_LATEST_VERSION;
@@ -110,25 +123,25 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
if ( 0 == ($archive_files = $archive->extract($pathExtracted) ) )
{
throw new Exception(Piwik_TranslateException('CoreUpdater_ExceptionArchiveIncompatible', $archive->errorInfo()));
- }
-
+ }
+
if ( 0 == count($archive_files) )
{
throw new Exception(Piwik_TranslateException('CoreUpdater_ExceptionArchiveEmpty'));
}
unlink($this->pathPiwikZip);
}
-
+
private function oneClick_Verify()
{
- $someExpectedFiles = array(
+ $someExpectedFiles = array(
'/config/global.ini.php',
'/index.php',
'/core/Piwik.php',
'/piwik.php',
'/plugins/API/API.php'
);
- foreach($someExpectedFiles as $file)
+ foreach($someExpectedFiles as $file)
{
if(!is_file($this->pathRootExtractedPiwik . $file))
{
@@ -136,14 +149,14 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
}
}
}
-
+
private function oneClick_CreateConfigFileBackup()
{
$configFileBefore = PIWIK_USER_PATH . '/config/global.ini.php';
$configFileAfter = PIWIK_USER_PATH . self::CONFIG_FILE_BACKUP;
Piwik::copy($configFileBefore, $configFileAfter);
}
-
+
private function oneClick_Copy()
{
/*
@@ -201,7 +214,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
apc_clear_cache(); // clear the system (aka 'opcode') cache
}
}
-
+
private function oneClick_Finished()
{
}
@@ -219,14 +232,14 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
protected function runUpdaterAndExit()
{
$updater = new Piwik_Updater();
- $componentsWithUpdateFile = Piwik_CoreUpdater::getComponentUpdates($updater);
+ $componentsWithUpdateFile = Piwik_CoreUpdater::getComponentUpdates($updater);
if(empty($componentsWithUpdateFile))
{
Piwik::redirectToModule('CoreHome');
}
-
+
Piwik::setMaxExecutionTime(0);
-
+
$sqlQueries = $updater->getSqlQueriesToExecute();
if(Piwik_Common::isPhpCliMode())
{
@@ -287,7 +300,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
} catch( Exception $e) {
$currentVersion = '<= 0.2.9';
}
-
+
foreach($componentsWithUpdateFile as $name => $filenames)
{
if($name == 'core')
@@ -318,7 +331,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
$view->errorMessages = $this->errorMessages;
$view->current_piwik_version = $currentVersion;
$view->pluginNamesToUpdate = $pluginNamesToUpdate;
- $view->coreToUpdate = $coreToUpdate;
+ $view->coreToUpdate = $coreToUpdate;
}
private function doExecuteUpdates($view, $updater, $componentsWithUpdateFile)
@@ -345,7 +358,7 @@ class Piwik_CoreUpdater_Controller extends Piwik_Controller
$this->warningMessages = array_merge($this->warningMessages, $updater->update($name));
} catch (Piwik_Updater_UpdateErrorException $e) {
$this->errorMessages[] = $e->getMessage();
- if($name == 'core')
+ if($name == 'core')
{
$this->coreError = true;
break;
diff --git a/plugins/CoreUpdater/templates/update_one_click_done.tpl b/plugins/CoreUpdater/templates/update_one_click_results.tpl
index 50bd0e4160..50bd0e4160 100644
--- a/plugins/CoreUpdater/templates/update_one_click_done.tpl
+++ b/plugins/CoreUpdater/templates/update_one_click_results.tpl