Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split previous joind.in URL into joind.in username and separate URL (#…
…1174) Remove double-declaration Replace duplicate tests with joind.in URL tests
- Loading branch information
1 parent
0e54c18
commit e104a12
Showing
13 changed files
with
366 additions
and
107 deletions.
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
73 changes: 73 additions & 0 deletions
73
migrations/20181002234013_create_user_joind_in_username_column.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,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2013-2018 OpenCFP | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/opencfp/opencfp | ||
*/ | ||
use Cartalyst\Sentinel\Users\EloquentUser; | ||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CreateUserJoindInUsernameColumn extends AbstractMigration | ||
{ | ||
/** @var Capsule $capsule */ | ||
public $capsule; | ||
|
||
public function bootEloquent(): void | ||
{ | ||
$adapter = $this->getAdapter()->getAdapter(); | ||
$options = $adapter->getOptions(); | ||
$this->capsule = new Capsule(); | ||
$this->capsule->addConnection([ | ||
'driver' => 'mysql', | ||
'database' => $options['name'], | ||
]); | ||
$this->capsule->getConnection()->setPdo($adapter->getConnection()); | ||
$this->capsule->bootEloquent(); | ||
$this->capsule->setAsGlobal(); | ||
} | ||
|
||
public function up(): void | ||
{ | ||
// Create joindin_username | ||
$this->table('users') | ||
->addColumn('joindin_username', 'string', ['null' => true]) | ||
->update(); | ||
|
||
// Go through each record in user, strip out (https://joind.in/user/) and copy to joindin_username | ||
$joindInRegex = '/^https:\/\/joind\.in\/user\/(.{1,100})$/'; | ||
|
||
$users = EloquentUser::all(); | ||
|
||
foreach ($users as $user) { | ||
if (\preg_match($joindInRegex, $user->url, $matches) === 1) { | ||
$user->joindin_username = $matches[1]; | ||
$user->url = null; | ||
$user->save(); | ||
} | ||
} | ||
} | ||
|
||
public function down(): void | ||
{ | ||
// Go through each record in user, update `url` to move the joindin_username to there | ||
$users = EloquentUser::all(); | ||
|
||
foreach ($users as $user) { | ||
$user->url = $user->joindin_username | ||
? 'https://joind.in/user/' . $user->joindin_username | ||
: null; | ||
$user->joindin_username = null; | ||
$user->save(); | ||
} | ||
// Drop the joindin_username column | ||
$this->table('users') | ||
->removeColumn('joindin_username') | ||
->update(); | ||
} | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.