diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2020-11-27 21:42:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-27 21:42:52 +0300 |
commit | 8ba7a162846d0cfab5638d3459c9f3938b8e7856 (patch) | |
tree | 061232b62a211d948c92cb510d7a01a6e47463cc /core | |
parent | b66217b6a4555f198aaf8cdb4ddaec45f48d42b9 (diff) |
Improve token auth migration (#16822)
Diffstat (limited to 'core')
-rw-r--r-- | core/Updater/Migration/Custom.php | 44 | ||||
-rw-r--r-- | core/Updates/4.0.0-b1.php | 38 |
2 files changed, 51 insertions, 31 deletions
diff --git a/core/Updater/Migration/Custom.php b/core/Updater/Migration/Custom.php new file mode 100644 index 0000000000..c69dca9fd6 --- /dev/null +++ b/core/Updater/Migration/Custom.php @@ -0,0 +1,44 @@ +<?php +/** + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +namespace Piwik\Updater\Migration; + +use Piwik\Config; +use Piwik\Container\StaticContainer; +use Piwik\Updater\Migration; + +/** + * Create a custom migration that can execute any callback. + * + * @api + */ +class Custom extends Migration +{ + private $callback; + private $toString; + + public function __construct($callback, $toString) + { + $this->callback = $callback; + $this->toString = $toString; + } + + public function exec() + { + call_user_func($this->callback); + } + + public function __toString() + { + return $this->toString; + } + + public function shouldIgnoreError($exception) + { + return false; + } +} diff --git a/core/Updates/4.0.0-b1.php b/core/Updates/4.0.0-b1.php index 780c2d034d..18531968b2 100644 --- a/core/Updates/4.0.0-b1.php +++ b/core/Updates/4.0.0-b1.php @@ -10,10 +10,11 @@ namespace Piwik\Updates; use Piwik\DataAccess\TableMetadata; -use Piwik\Date; +use Piwik\Updater\Migration\Custom as CustomMigration; use Piwik\Db; use Piwik\DbHelper; use Piwik\Plugin\Manager; +use Piwik\Plugins\CoreAdminHome\Commands\MigrateTokenAuths; use Piwik\Plugins\CoreHome\Columns\Profilable; use Piwik\Plugins\CoreHome\Columns\VisitorSecondsSinceFirst; use Piwik\Plugins\CoreHome\Columns\VisitorSecondsSinceOrder; @@ -57,36 +58,12 @@ class Updates_4_0_0_b1 extends PiwikUpdates $migrations = []; - /** APP SPECIFIC TOKEN START */ - $migrations[] = $this->migration->db->createTable('user_token_auth', array( - 'idusertokenauth' => 'BIGINT UNSIGNED NOT NULL AUTO_INCREMENT', - 'login' => 'VARCHAR(100) NOT NULL', - 'description' => 'VARCHAR('.Model::MAX_LENGTH_TOKEN_DESCRIPTION.') NOT NULL', - 'password' => 'VARCHAR(191) NOT NULL', - 'system_token' => 'TINYINT(1) NOT NULL DEFAULT 0', - 'hash_algo' => 'VARCHAR(30) NOT NULL', - 'last_used' => 'DATETIME NULL', - 'date_created' => ' DATETIME NOT NULL', - 'date_expired' => ' DATETIME NULL', - ), 'idusertokenauth'); - $migrations[] = $this->migration->db->addUniqueKey('user_token_auth', 'password', 'uniq_password'); - - $migrations[] = $this->migration->db->dropIndex('user', 'uniq_keytoken'); - - $userModel = new Model(); - foreach ($userModel->getUsers(array()) as $user) { - if (!empty($user['token_auth'])) { - $migrations[] = $this->migration->db->insert('user_token_auth', array( - 'login' => $user['login'], - 'description' => 'Created by Matomo 4 migration', - 'password' => $userModel->hashTokenAuth($user['token_auth']), - 'date_created' => Date::now()->getDatetime(), - 'hash_algo' => 'sha512' - )); - } - } + $domain = Config::getLocalConfigPath() === Config::getDefaultLocalConfigPath() ? '' : Config::getHostname(); + $domainArg = !empty($domain) ? "--matomo-domain=". escapeshellarg($domain) . " " : ''; + $toString = sprintf('./console %score:matomo4-migrate-token-auths', $domainArg); + $custom = new CustomMigration(array(MigrateTokenAuths::class, 'migrate'), $toString); - /** APP SPECIFIC TOKEN END */ + $migrations[] = $custom; // invalidations table $migrations[] = $this->migration->db->createTable('archive_invalidations', [ @@ -105,7 +82,6 @@ class Updates_4_0_0_b1 extends PiwikUpdates $migrations[] = $this->migration->db->addIndex('archive_invalidations', ['idsite', 'date1', 'period'], 'index_idsite_dates_period_name'); $migrations[] = $this->migration->db->dropColumn('user', 'alias'); - $migrations[] = $this->migration->db->dropColumn('user', 'token_auth'); // prevent possible duplicates when shorting session id $migrations[] = $this->migration->db->sql('DELETE FROM `' . Common::prefixTable('session') . '` WHERE length(id) > 190'); |