-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update database collection config if auto-detectable
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
namespace Piwik\Updates; | ||
|
||
use Piwik\Common; | ||
use Piwik\Config; | ||
use Piwik\Db; | ||
use Piwik\Updater; | ||
use Piwik\Updates; | ||
|
||
class Updates_5_2_0_b2 extends Updates | ||
{ | ||
public function doUpdate(Updater $updater) | ||
{ | ||
$config = Config::getInstance(); | ||
$dbConfig = $config->database; | ||
|
||
if (!empty($dbConfig['collation'])) { | ||
// config already set, nothing to do | ||
return; | ||
} | ||
|
||
if (!is_writable(Config::getLocalConfigPath())) { | ||
// rely on the system check if config is not writable | ||
return; | ||
} | ||
|
||
try { | ||
$db = Db::get(); | ||
$userTable = Common::prefixTable('user'); | ||
$userTableStatus = $db->fetchRow('SHOW TABLE STATUS WHERE Name = ?', [$userTable]); | ||
$connectionCollation = $db->fetchOne('SELECT @@collation_connection'); | ||
|
||
if ( | ||
empty($userTableStatus['Collation']) | ||
|| empty($connectionCollation) | ||
|| $userTableStatus['Collation'] !== $connectionCollation | ||
) { | ||
// skip config update if user table and connection have different collations | ||
return; | ||
} | ||
|
||
$dbConfig['collation'] = $connectionCollation; | ||
$config->database = $dbConfig; | ||
$config->forceSave(); | ||
} catch (\Exception $e) { | ||
// rely on the system check if detection failed | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters