-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate NewsCategory to new QueryBuilder
- Loading branch information
Showing
5 changed files
with
149 additions
and
127 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
63 changes: 63 additions & 0 deletions
63
migrations/20180206040040_news_category_status_column_conversion.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,63 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class NewsCategoryStatusColumnConversion extends AbstractMigration | ||
{ | ||
public function up() | ||
{ | ||
$newsCategoryTable = $this->table('news_categories'); | ||
$newsCategoryTable | ||
->addColumn('is_read_only', 'boolean', [ | ||
'after' => 'protected', | ||
'null' => false, | ||
'default' => false, | ||
'comment' => 'When set to true, no new articles should be able to use this category' | ||
]) | ||
->addColumn('is_deleted', 'boolean', [ | ||
'after' => 'is_read_only', | ||
'null' => false, | ||
'default' => false, | ||
'comment' => 'Whether or not the news category has been soft deleted', | ||
]) | ||
->changeColumn('protected', 'boolean', [ | ||
'default' => false, | ||
'null' => false, | ||
'comment' => 'When set to true, prevents the category from being deleted from the UI', | ||
]) | ||
->update() | ||
; | ||
|
||
$this->query("UPDATE news_categories SET is_deleted = 1 WHERE status = 'deleted';"); | ||
|
||
$newsCategoryTable | ||
->removeColumn('status') | ||
->renameColumn('protected', 'is_protected') | ||
->update() | ||
; | ||
} | ||
|
||
public function down() | ||
{ | ||
$newsCategoryTable = $this->table('news_categories'); | ||
$newsCategoryTable | ||
->addColumn('status', 'set', [ | ||
'values' => ['enabled', 'disabled', 'deleted'], | ||
'after' => 'is_deleted', | ||
'null' => false, | ||
'default' => 'enabled', | ||
'comment' => 'The status of the news element', | ||
]) | ||
->renameColumn('is_protected', 'protected') | ||
->update() | ||
; | ||
|
||
$this->query("UPDATE news_categories SET status = 'deleted' WHERE is_deleted = 1;"); | ||
|
||
$newsCategoryTable | ||
->removeColumn('is_deleted') | ||
->removeColumn('is_read_only') | ||
->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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
/** | ||
* Exception thrown when something is attempted to be deleted from the database but permission was denied. | ||
*/ | ||
class DeletionDeniedException extends RuntimeException | ||
{ | ||
|
||
} |
Oops, something went wrong.