Skip to content

Commit

Permalink
Merge pull request #16 from dnadesign/master
Browse files Browse the repository at this point in the history
Misc fixes.
  • Loading branch information
icecaster committed Jul 21, 2014
2 parents 2dd9e21 + bd2141e commit 85e3496
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
1 change: 0 additions & 1 deletion _config.php

This file was deleted.

27 changes: 18 additions & 9 deletions code/VersionedGridFieldDetailForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ function isPublished() {
return false;

$record = $this->record;
return (DB::query("SELECT \"ID\" FROM \"{$this->baseTable()}_Live\" WHERE \"ID\" = $record->ID")->value())

return Versioned::get_by_stage($this->baseTable(), 'Live')->byID($record->ID)
? true
: false;
}
Expand Down Expand Up @@ -175,7 +175,9 @@ function getCMSActions() {
);
}
}


$this->extend('updateCMSActions', $actions);

return $actions;
}

Expand All @@ -198,12 +200,19 @@ public function doPublish($data, $form) {
$form->saveInto($record);
$record->write();
$this->gridField->getList()->add($record);
$record->publish("Stage", "Live");

// use doPublish if it's defined on the object (like SiteTree) which
// includes extension calls.
if($record->hasMethod('doPublish')) {
$record->doPublish();
} else {
$record->publish('Stage', 'Live');
}

$message = sprintf(
_t('GridFieldDetailForm.Published', 'Published %s %s'),
$this->record->singular_name(),
'"'.htmlspecialchars($this->record->Title, ENT_QUOTES).'"'
'"'.Convert::raw2xml($this->record->Title).'"'
);

$form->sessionMessage($message, 'good');
Expand All @@ -226,7 +235,7 @@ public function doUnpublish($data, $form) {
$message = sprintf(
'Unpublished %s %s',
$this->record->singular_name(),
'"'.htmlspecialchars($this->record->Title, ENT_QUOTES).'"'
'"'.Convert::raw2xml($this->record->Title).'"'
);
$form->sessionMessage($message, 'good');
return $this->edit(Controller::curr()->getRequest());
Expand All @@ -239,7 +248,7 @@ function doRollback($data, $form) {
//$clone = clone $record;
$record->publish("Live", "Stage", false);
//$record->writeWithoutVersion();
$message = "Cancelled Draft changes for \"".htmlspecialchars($record->Title, ENT_QUOTES)."\"";
$message = "Cancelled Draft changes for \"".Convert::raw2xml($record->Title)."\"";

$form->sessionMessage($message, 'good');
return Controller::curr()->redirect($this->Link('edit'));
Expand All @@ -262,7 +271,7 @@ public function doDelete($data, $form) {
$message = sprintf(
_t('GridFieldDetailForm.Deleted', 'Deleted %s %s'),
$this->record->singular_name(),
'"'.htmlspecialchars($this->record->Title, ENT_QUOTES).'"'
'"'.Convert::raw2xml($this->record->Title).'"'
);

$form->sessionMessage($message, 'good');
Expand All @@ -289,7 +298,7 @@ function doRestoreToStage() {
$record = $this->record;
// if no record can be found on draft stage (meaning it has been "deleted from draft" before),
// create an empty record
if(!DB::query("SELECT \"ID\" FROM \"{$this->baseTable()}\" WHERE \"ID\" = $record->ID")->value()) {
if(!Versioned::get_by_stage($this->baseTable(), 'Stage')->byID($record->ID)) {
$conn = DB::getConn();
if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing($record->class, true);
DB::query("INSERT INTO \"{$this->baseTable()}\" (\"ID\") VALUES ($this->ID)");
Expand Down

0 comments on commit 85e3496

Please sign in to comment.