forked from YesWiki/yeswiki-extension-login-sso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(migration): use new migration system introduced in 4.5
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
migrations/20240801105857_LoginssoAddSsoFieldToUserTable.php
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,25 @@ | ||
<?php | ||
|
||
use YesWiki\Core\YesWikiMigration; | ||
|
||
class LoginssoAddSsoFieldToUserTable extends YesWikiMigration | ||
{ | ||
public function run() | ||
{ | ||
$tableName = $this->dbService->prefixTable('users'); | ||
|
||
$columExist = $this->dbService->count(sprintf("SHOW COLUMNS FROM %s LIKE 'loginsso_id'", $tableName)) > 0; | ||
if (!$columExist) { | ||
$this->dbService->query(sprintf('ALTER TABLE %s ADD COLUMN loginsso_id VARCHAR(255) DEFAULT NULL', $tableName)); | ||
$this->dbService->query(sprintf('CREATE UNIQUE INDEX idx_loginsso_id ON %s(loginsso_id);', $tableName)); | ||
|
||
// Retro compatibility from previous versions | ||
$this->dbService->query(sprintf('UPDATE %s SET loginsso_id=email', $tableName)); | ||
} | ||
|
||
return $this->wiki->render('@loginsso/handlers/update/add_column.html.twig', [ | ||
'tableName' => $tableName, | ||
'columnExist' => $columExist, | ||
]); | ||
} | ||
} |