-
-
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.
- Update News model to use new `is_deleted` and `is_draft` columns with the respective database migration - Update News controller to use new query builder - Change News editor to only allow drafts for items that have not been published yet
- Loading branch information
Showing
7 changed files
with
225 additions
and
90 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
67 changes: 67 additions & 0 deletions
67
migrations/20180202213952_news_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,67 @@ | ||
<?php | ||
|
||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class NewsStatusColumnConversion extends AbstractMigration | ||
{ | ||
public function up() | ||
{ | ||
$newsTable = $this->table('news'); | ||
$newsTable | ||
->addColumn('is_draft', 'boolean', [ | ||
'after' => 'editor', | ||
'null' => false, | ||
'default' => false, | ||
'comment' => 'Whether or not the news article is a draft', | ||
]) | ||
->addColumn('is_deleted', 'boolean', [ | ||
'after' => 'is_draft', | ||
'null' => false, | ||
'default' => false, | ||
'comment' => 'Whether or not the news article has been soft deleted', | ||
]) | ||
->update() | ||
; | ||
|
||
$this->query("UPDATE news SET is_draft = 1 WHERE status = 'revision' OR status ='draft';"); | ||
$this->query("UPDATE news SET is_deleted = 1 WHERE status = 'deleted' OR status = 'disabled';"); | ||
|
||
$newsTable | ||
->removeColumn('parent_id') | ||
->removeColumn('status') | ||
->update() | ||
; | ||
} | ||
|
||
public function down() | ||
{ | ||
$newsTable = $this->table('news'); | ||
$newsTable | ||
->addColumn('parent_id', 'integer', [ | ||
'after' => 'id', | ||
'null' => true, | ||
'default' => null, | ||
'length' => 11, | ||
'comment' => 'The ID of the original news post. If this column is set, then it is a revision', | ||
]) | ||
->addColumn('status', 'set', [ | ||
'values' => ['published', 'revision', 'draft', 'disabled', 'deleted'], | ||
'after' => 'editor', | ||
'null' => false, | ||
'default' => 'published', | ||
'comment' => 'The status of the news element', | ||
]) | ||
->update() | ||
; | ||
|
||
$this->query("UPDATE news SET status = 'draft' WHERE is_draft = 1;"); | ||
$this->query("UPDATE news SET status = 'deleted' WHERE is_deleted = 1;"); | ||
|
||
$newsTable | ||
->removeColumn('is_draft') | ||
->removeColumn('is_deleted') | ||
->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
Oops, something went wrong.