Merge pull request #2589 from robbieaverill/pulls/4.7/exceptions

ENH Replace E_USER_ERROR errors with exceptions
This commit is contained in:
Guy Marriott 2020-10-04 16:57:41 -07:00 committed by GitHub
commit bbcc5de8c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View File

@ -396,11 +396,11 @@ class CMSPageHistoryController extends CMSMain
$toVersionRecord = Versioned::get_version(SiteTree::class, $id, $toVersion); $toVersionRecord = Versioned::get_version(SiteTree::class, $id, $toVersion);
if (!$fromVersionRecord) { if (!$fromVersionRecord) {
user_error("Can't find version $fromVersion of page $id", E_USER_ERROR); throw new \Exception("Can't find version $fromVersion of page $id");
} }
if (!$toVersionRecord) { if (!$toVersionRecord) {
user_error("Can't find version $toVersion of page $id", E_USER_ERROR); throw new \Exception("Can't find version $toVersion of page $id");
} }
if (!$record) { if (!$record) {

View File

@ -96,7 +96,7 @@ in the other stage:<br />
$fields->push(new HeaderField( $fields->push(new HeaderField(
'Header', 'Header',
_t('SilverStripe\\CMS\\Tasks\\RemoveOrphanedPagesTask.HEADER', 'Remove all orphaned pages task') _t(__CLASS__ . '.HEADER', 'Remove all orphaned pages task')
)); ));
$fields->push(new LiteralField( $fields->push(new LiteralField(
'Description', 'Description',
@ -134,14 +134,14 @@ in the other stage:<br />
'SelectAllLiteral', 'SelectAllLiteral',
sprintf( sprintf(
'<p><a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'checked\'); return false;">%s</a>&nbsp;', '<p><a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'checked\'); return false;">%s</a>&nbsp;',
_t('SilverStripe\\CMS\\Tasks\\RemoveOrphanedPagesTask.SELECTALL', 'select all') _t(__CLASS__ . '.SELECTALL', 'select all')
) )
)); ));
$fields->push(new LiteralField( $fields->push(new LiteralField(
'UnselectAllLiteral', 'UnselectAllLiteral',
sprintf( sprintf(
'<a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'\'); return false;">%s</a></p>', '<a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'\'); return false;">%s</a></p>',
_t('SilverStripe\\CMS\\Tasks\\RemoveOrphanedPagesTask.UNSELECTALL', 'unselect all') _t(__CLASS__ . '.UNSELECTALL', 'unselect all')
) )
)); ));
$fields->push(new OptionsetField( $fields->push(new OptionsetField(
@ -149,13 +149,13 @@ in the other stage:<br />
_t('SilverStripe\\CMS\\Tasks\\RemoveOrphanedPagesTask.CHOOSEOPERATION', 'Choose operation:'), _t('SilverStripe\\CMS\\Tasks\\RemoveOrphanedPagesTask.CHOOSEOPERATION', 'Choose operation:'),
[ [
'rebase' => _t( 'rebase' => _t(
'SilverStripe\\CMS\\Tasks\\RemoveOrphanedPagesTask.OPERATION_REBASE', __CLASS__ . '.OPERATION_REBASE',
sprintf( sprintf(
'Rebase selected to a new holder page "%s" and unpublish. None of these pages will show up for website visitors.', 'Rebase selected to a new holder page "%s" and unpublish. None of these pages will show up for website visitors.',
$this->rebaseHolderTitle() $this->rebaseHolderTitle()
) )
), ),
'remove' => _t('SilverStripe\\CMS\\Tasks\\RemoveOrphanedPagesTask.OPERATION_REMOVE', 'Remove selected from all stages (WARNING: Will destroy all selected pages from both stage and live)'), 'remove' => _t(__CLASS__ . '.OPERATION_REMOVE', 'Remove selected from all stages (WARNING: Will destroy all selected pages from both stage and live)'),
], ],
'rebase' 'rebase'
)); ));
@ -164,7 +164,7 @@ in the other stage:<br />
sprintf( sprintf(
'<p class="message">%s</p>', '<p class="message">%s</p>',
_t( _t(
'SilverStripe\\CMS\\Tasks\\RemoveOrphanedPagesTask.DELETEWARNING', __CLASS__ . '.DELETEWARNING',
'Warning: These operations are not reversible. Please handle with care.' 'Warning: These operations are not reversible. Please handle with care.'
) )
) )
@ -174,7 +174,7 @@ in the other stage:<br />
'NotFoundLabel', 'NotFoundLabel',
sprintf( sprintf(
'<p class="message">%s</p>', '<p class="message">%s</p>',
_t('SilverStripe\\CMS\\Tasks\\RemoveOrphanedPagesTask.NONEFOUND', 'No orphans found') _t(__CLASS__ . '.NONEFOUND', 'No orphans found')
) )
)); ));
} }
@ -184,7 +184,7 @@ in the other stage:<br />
'SilverStripe\\Forms\\Form', 'SilverStripe\\Forms\\Form',
$fields, $fields,
new FieldList( new FieldList(
new FormAction('doSubmit', _t('SilverStripe\\CMS\\Tasks\\RemoveOrphanedPagesTask.BUTTONRUN', 'Run')) new FormAction('doSubmit', _t(__CLASS__ . '.BUTTONRUN', 'Run'))
) )
); );
@ -217,7 +217,7 @@ in the other stage:<br />
$successIDs = $this->rebaseOrphans($data['OrphanIDs']); $successIDs = $this->rebaseOrphans($data['OrphanIDs']);
break; break;
default: default:
user_error(sprintf("Unknown operation: '%s'", $data['OrphanOperation']), E_USER_ERROR); throw new \InvalidArgumentException(sprintf("Unknown operation: '%s'", $data['OrphanOperation']));
} }
$content = ''; $content = '';
@ -228,7 +228,7 @@ in the other stage:<br />
} }
$content .= "</ul>"; $content .= "</ul>";
} else { } else {
$content = _t('SilverStripe\\CMS\\Tasks\\RemoveOrphanedPagesTask.NONEREMOVED', 'None removed'); $content = _t(__CLASS__ . '.NONEREMOVED', 'None removed');
} }
return $this->customise([ return $this->customise([