API renaming SiteTree->OwnerID column because it conflicts with the blog module

This commit is contained in:
Julian Seidenberg 2013-03-18 15:20:51 +13:00
parent 26ba97a567
commit 72c3faca96
8 changed files with 39 additions and 14 deletions

View File

@ -21,3 +21,8 @@ new to have the DailyTask cron job set up. See ScheduledTask.php
## Usage ## Usage
When you open a page in the CMS, there will now be a Review tab. When you open a page in the CMS, there will now be a Review tab.
## Migration
When migrating from an older version of this module to the current version,
you might need to run: /dev/tasks/ContentReviewOwnerMigrationTask

View File

@ -15,10 +15,10 @@ class ContentReviewEmails extends DailyTask {
Subsite::$disable_subsite_filter = true; Subsite::$disable_subsite_filter = true;
} }
$pages = DataObject::get('Page', "\"SiteTree\".\"NextReviewDate\" = '".(class_exists('SS_Datetime') ? SS_Datetime::now()->URLDate() : SSDatetime::now()->URLDate())."' AND \"SiteTree\".\"OwnerID\" != 0"); $pages = DataObject::get('Page', "\"SiteTree\".\"NextReviewDate\" = '".(class_exists('SS_Datetime') ? SS_Datetime::now()->URLDate() : SSDatetime::now()->URLDate())."' AND \"SiteTree\".\"ContentReviewOwnerID\" != 0");
if ($pages && $pages->Count()) { if ($pages && $pages->Count()) {
foreach($pages as $page) { foreach($pages as $page) {
$owner = $page->Owner(); $owner = $page->ContentReviewOwner();
if ($owner) { if ($owner) {
$sender = Security::findAnAdministrator(); $sender = Security::findAnAdministrator();
$recipient = $owner; $recipient = $owner;

View File

@ -0,0 +1,20 @@
<?php
/**
* Task which migrates the ContentReview Module's SiteTree->OwnerID column to a new column name
*/
class ContentReviewOwnerMigrationTask extends BuildTask {
public function run($request) {
$results = DB::query('SHOW columns from "SiteTree" WHERE "field" = \'OwnerID\'');
if ($results->numRecords() == 0) {
echo "<h1>No need to run task. SiteTree->OwnerID doesn't exist</h1>";
} else {
DB::query('UPDATE "SiteTree" SET "ContentReviewOwnerID" = "OwnerID"');
DB::query('UPDATE "SiteTree_Live" SET "ContentReviewOwnerID" = "OwnerID"');
DB::query('UPDATE "SiteTree_versions" SET "ContentReviewOwnerID" = "OwnerID"');
DB::query('ALTER TABLE "SiteTree" DROP COLUMN "OwnerID"');
DB::query('ALTER TABLE "SiteTree_Live" DROP COLUMN "OwnerID"');
DB::query('ALTER TABLE "SiteTree_versions" DROP COLUMN "OwnerID"');
echo "<h1>Migrated 3 tables. Dropped obsolete OwnerID column</h1>";
}
}
}

View File

@ -40,7 +40,7 @@ class PagesDueForReviewReport extends SS_Report {
$map = $map + array('' => 'Any', '-1' => '(no owner)'); $map = $map + array('' => 'Any', '-1' => '(no owner)');
$params->push(new DropdownField("OwnerID", 'Page owner', $map)); $params->push(new DropdownField("ContentReviewOwnerID", 'Page owner', $map));
// Restore current subsite // Restore current subsite
Subsite::changeSubsite($existingSubsite); Subsite::changeSubsite($existingSubsite);
@ -49,7 +49,7 @@ class PagesDueForReviewReport extends SS_Report {
$map = $cmsUsers->map('ID', 'Title', '(no owner)')->toArray(); $map = $cmsUsers->map('ID', 'Title', '(no owner)')->toArray();
unset($map['']); unset($map['']);
$map = array('' => 'Any', '-1' => '(no owner)') + $map; $map = array('' => 'Any', '-1' => '(no owner)') + $map;
$params->push(new DropdownField("OwnerID", 'Page owner', $map)); $params->push(new DropdownField("ContentReviewOwnerID", 'Page owner', $map));
} }
$params->push( $params->push(
@ -135,11 +135,11 @@ class PagesDueForReviewReport extends SS_Report {
} }
// Owner dropdown // Owner dropdown
if(!empty($params['OwnerID'])) { if(!empty($params['ContentReviewOwnerID'])) {
$ownerID = (int)$params['OwnerID']; $ownerID = (int)$params['ContentReviewOwnerID'];
// We use -1 here to distinguish between No Owner and Any // We use -1 here to distinguish between No Owner and Any
if($ownerID == -1) $ownerID = 0; if($ownerID == -1) $ownerID = 0;
$records->addFilter(array('OwnerID' => $ownerID)); $records->addFilter(array('ContentReviewOwnerID' => $ownerID));
} }
// Turn a query into records // Turn a query into records

View File

@ -16,11 +16,11 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
); );
static $has_one = array( static $has_one = array(
'Owner' => 'Member', 'ContentReviewOwner' => 'Member',
); );
function getOwnerName() { function getOwnerName() {
if($this->owner->OwnerID && $this->owner->Owner()) return $this->owner->Owner()->FirstName . ' ' . $this->owner->Owner()->Surname; if($this->owner->ContentReviewOwnerID && $this->owner->ContentReviewOwner()) return $this->owner->ContentReviewOwner()->FirstName . ' ' . $this->owner->ContentReviewOwner()->Surname;
} }
function getEditorName() { function getEditorName() {
@ -37,7 +37,7 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
$fields->addFieldsToTab("Root.Review", array( $fields->addFieldsToTab("Root.Review", array(
new HeaderField(_t('SiteTreeCMSWorkflow.REVIEWHEADER', "Content review"), 2), new HeaderField(_t('SiteTreeCMSWorkflow.REVIEWHEADER', "Content review"), 2),
new DropdownField("OwnerID", _t("SiteTreeCMSWorkflow.PAGEOWNER", new DropdownField("ContentReviewOwnerID", _t("SiteTreeCMSWorkflow.PAGEOWNER",
"Page owner (will be responsible for reviews)"), $cmsUsers->map('ID', 'Title', '(no owner)')), "Page owner (will be responsible for reviews)"), $cmsUsers->map('ID', 'Title', '(no owner)')),
DateField::create( DateField::create(
"NextReviewDate", "NextReviewDate",

View File

@ -2,7 +2,7 @@
// Hide all owner dropdowns except the one for the current subsite // Hide all owner dropdowns except the one for the current subsite
function showCorrectSubsiteIDDropdown(value) { function showCorrectSubsiteIDDropdown(value) {
var domid = 'OwnerID' + value; var domid = 'ContentReviewOwnerID' + value;
var ownerIDDropdowns = $('div.subsiteSpecificOwnerID'); var ownerIDDropdowns = $('div.subsiteSpecificOwnerID');
for(var i = 0; i < ownerIDDropdowns.length; i++) { for(var i = 0; i < ownerIDDropdowns.length; i++) {

View File

@ -84,14 +84,14 @@ class ContentReviewTest extends FunctionalTest {
$page = new Page(); $page = new Page();
$page->ReviewPeriodDays = 10; $page->ReviewPeriodDays = 10;
$page->OwnerID = $editor->ID; $page->ContentReviewOwnerID = $editor->ID;
$page->write(); $page->write();
$this->assertTrue($page->doPublish()); $this->assertTrue($page->doPublish());
$this->assertEquals($page->OwnerName, "Test Editor"); $this->assertEquals($page->OwnerName, "Test Editor");
$page = $this->objFromFixture('Page', 'about'); $page = $this->objFromFixture('Page', 'about');
$page->OwnerID = 0; $page->ContentReviewOwnerID = 0;
$page->write(); $page->write();
$this->assertTrue($page->doPublish()); $this->assertTrue($page->doPublish());

View File

@ -42,7 +42,7 @@ Page:
staff: staff:
Title: Staff Title: Staff
NextReviewDate: 2010-02-14 NextReviewDate: 2010-02-14
Owner: =>Member.author ContentReviewOwner: =>Member.author
contact: contact:
Title: Contact Us Title: Contact Us
NextReviewDate: 2010-02-21 NextReviewDate: 2010-02-21