Skip to content

Commit

Permalink
API renaming SiteTree->OwnerID column because it conflicts with the b…
Browse files Browse the repository at this point in the history
…log module
  • Loading branch information
Julian Seidenberg committed Mar 18, 2013
1 parent 26ba97a commit 72c3fac
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 14 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ new to have the DailyTask cron job set up. See ScheduledTask.php
## Usage

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

4 changes: 2 additions & 2 deletions code/ContentReviewEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ function process() {
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()) {
foreach($pages as $page) {
$owner = $page->Owner();
$owner = $page->ContentReviewOwner();
if ($owner) {
$sender = Security::findAnAdministrator();
$recipient = $owner;
Expand Down
20 changes: 20 additions & 0 deletions code/ContentReviewOwnerMigrationTask.php
Original file line number Diff line number Diff line change
@@ -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>";
}
}
}
10 changes: 5 additions & 5 deletions code/PagesDueForReviewReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function parameterFields() {

$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
Subsite::changeSubsite($existingSubsite);
Expand All @@ -49,7 +49,7 @@ function parameterFields() {
$map = $cmsUsers->map('ID', 'Title', '(no owner)')->toArray();
unset($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(
Expand Down Expand Up @@ -135,11 +135,11 @@ function sourceRecords($params, $sort, $limit) {
}

// Owner dropdown
if(!empty($params['OwnerID'])) {
$ownerID = (int)$params['OwnerID'];
if(!empty($params['ContentReviewOwnerID'])) {
$ownerID = (int)$params['ContentReviewOwnerID'];
// We use -1 here to distinguish between No Owner and Any
if($ownerID == -1) $ownerID = 0;
$records->addFilter(array('OwnerID' => $ownerID));
$records->addFilter(array('ContentReviewOwnerID' => $ownerID));
}

// Turn a query into records
Expand Down
6 changes: 3 additions & 3 deletions code/SiteTreeContentReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
);

static $has_one = array(
'Owner' => 'Member',
'ContentReviewOwner' => 'Member',
);

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() {
Expand All @@ -37,7 +37,7 @@ public function updateCMSFields(FieldList $fields) {

$fields->addFieldsToTab("Root.Review", array(
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)')),
DateField::create(
"NextReviewDate",
Expand Down
2 changes: 1 addition & 1 deletion javascript/PagesDueForReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Hide all owner dropdowns except the one for the current subsite
function showCorrectSubsiteIDDropdown(value) {
var domid = 'OwnerID' + value;
var domid = 'ContentReviewOwnerID' + value;

var ownerIDDropdowns = $('div.subsiteSpecificOwnerID');
for(var i = 0; i < ownerIDDropdowns.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions tests/ContentReviewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ function testOwnerName() {

$page = new Page();
$page->ReviewPeriodDays = 10;
$page->OwnerID = $editor->ID;
$page->ContentReviewOwnerID = $editor->ID;
$page->write();

$this->assertTrue($page->doPublish());
$this->assertEquals($page->OwnerName, "Test Editor");

$page = $this->objFromFixture('Page', 'about');
$page->OwnerID = 0;
$page->ContentReviewOwnerID = 0;
$page->write();

$this->assertTrue($page->doPublish());
Expand Down
2 changes: 1 addition & 1 deletion tests/ContentReviewTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Page:
staff:
Title: Staff
NextReviewDate: 2010-02-14
Owner: =>Member.author
ContentReviewOwner: =>Member.author
contact:
Title: Contact Us
NextReviewDate: 2010-02-21

0 comments on commit 72c3fac

Please sign in to comment.