-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
188 additions
and
28 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace ether\seo\migrations; | ||
|
||
use Craft; | ||
use craft\db\Migration; | ||
use ether\seo\records\RedirectRecord; | ||
|
||
/** | ||
* m200518_110721_add_order_to_redirects migration. | ||
*/ | ||
class m200518_110721_add_order_to_redirects extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->addColumn( | ||
RedirectRecord::$tableName, | ||
'order', | ||
$this->integer()->null() | ||
); | ||
|
||
$rows = RedirectRecord::find()->select(['id', 'siteId'])->all(); | ||
$siteCounts = []; | ||
|
||
foreach ($rows as $row) | ||
{ | ||
if (!array_key_exists($row->siteId, $siteCounts)) | ||
$siteCounts[$row->siteId] = 0; | ||
|
||
$record = RedirectRecord::findOne(['id' => $row->id]); | ||
$record->order = $siteCounts[$row->siteId]; | ||
$record->save(false); | ||
|
||
$siteCounts[$row->siteId]++; | ||
} | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown() | ||
{ | ||
$this->dropColumn( | ||
RedirectRecord::$tableName, | ||
'order' | ||
); | ||
} | ||
} |
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.