Skip to content

Commit

Permalink
MINOR: Use Deprecation class to indicate deprecated methods in core.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Minnee committed Oct 29, 2011
1 parent ad9bc59 commit e5afa25
Show file tree
Hide file tree
Showing 31 changed files with 89 additions and 62 deletions.
6 changes: 1 addition & 5 deletions admin/code/LeftAndMainDecorator.php
Expand Up @@ -7,11 +7,7 @@
abstract class LeftAndMainDecorator extends LeftAndMainExtension {

public function __construct() {
// TODO Re-enable before we release 3.0 beta, for now it "breaks" too many modules
// user_error(
// 'LeftAndMainDecorator is deprecated, please use LeftAndMainExtension instead.',
// E_USER_NOTICE
// );
Deprecation::notice('3.0', 'Use LeftAndMainExtension instead.');
parent::__construct();
}

Expand Down
3 changes: 3 additions & 0 deletions control/Director.php
Expand Up @@ -282,6 +282,7 @@ protected static function handleRequest(SS_HTTPRequest $request, Session $sessio
* @deprecated 3.0 Use SS_HTTPRequest->latestParam()
*/
static function urlParam($name) {
Deprecation::notice('3.0', 'Use SS_HTTPRequest->latestParam() instead.');
if(isset(Director::$urlParams[$name])) return Director::$urlParams[$name];
}

Expand All @@ -291,6 +292,7 @@ static function urlParam($name) {
* @deprecated 3.0 Use SS_HTTPRequest->latestParams()
*/
static function urlParams() {
Deprecation::notice('3.0', 'Use SS_HTTPRequest->latestParams() instead.');
return Director::$urlParams;
}

Expand Down Expand Up @@ -413,6 +415,7 @@ static function get_status_code() {
* @deprecated 2.5 Use Controller->redirectBack()
*/
static function redirectBack() {
Deprecation::notice('2.5', 'Use Controller->redirectBack() instead.');
Controller::curr()->redirectBack();
}

Expand Down
1 change: 1 addition & 0 deletions core/ClassInfo.php
Expand Up @@ -181,6 +181,7 @@ static function classImplements($className, $interfaceName) {
* @deprecated 3.0 Please use is_subclass_of.
*/
public static function is_subclass_of($class, $parent) {
Deprecation::notice('3.0', 'Use is_subclass_of() instead.');
return is_subclass_of($class, $parent);
}

Expand Down
1 change: 1 addition & 0 deletions core/Core.php
Expand Up @@ -318,6 +318,7 @@ function getTempFolder($base = null) {
* @deprecated 3.0 Please use {@link SS_ClassManifest::getItemPath()}.
*/
function getClassFile($className) {
Deprecation::notice('3.0', 'Use SS_ClassManifest::getItemPath() instead.');
return SS_ClassLoader::instance()->getManifest()->getItemPath($className);
}

Expand Down
4 changes: 1 addition & 3 deletions core/Object.php
Expand Up @@ -896,9 +896,7 @@ public function uninherited($name) {
* @deprecated
*/
public function set_uninherited() {
user_error (
'Object->set_uninherited() is deprecated, please use a custom static on your object', E_USER_WARNING
);
Deprecation::notice('2.4', 'Use a custom static on your object instead.');
}

// -----------------------------------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions core/PaginatedList.php
Expand Up @@ -388,6 +388,7 @@ public function PrevLink() {
* @deprecated 3.0 Use individual getter methods.
*/
public function getPageLimits() {
Deprecation::notice('3.0', 'Use getPageStart, getPageLength, or getTotalItems instead.');
return array(
'pageStart' => $this->getPageStart(),
'pageLength' => $this->pageLength,
Expand All @@ -399,6 +400,7 @@ public function getPageLimits() {
* @deprecated 3.0 Use individual setter methods.
*/
public function setPageLimits($pageStart, $pageLength, $totalSize) {
Deprecation::notice('3.0', 'Use setPageStart, setPageLength, or setTotalItems instead.');
$this->setPageStart($pageStart);
$this->setPageLength($pageLength);
$this->setTotalSize($totalSize);
Expand Down
15 changes: 9 additions & 6 deletions dev/Debug.php
Expand Up @@ -460,8 +460,7 @@ static function showLines($errfile, $errline) {
* @return boolean
*/
static function emailError($emailAddress, $errno, $errstr, $errfile, $errline, $errcontext, $errorType = "Error") {
user_error('Debug::send_errors_to() and Debug::emailError() is deprecated. Please use SS_Log instead.
See the class documentation in SS_Log.php for more information.', E_USER_NOTICE);
Deprecation::notice('2.5', 'Use SS_Log instead. See the class documentation in SS_Log.php for more information.');
$priority = ($errorType == 'Error') ? SS_Log::ERR : SS_Log::WARN;
$writer = new SS_LogEmailWriter($emailAddress);
SS_Log::add_writer($writer, $priority);
Expand Down Expand Up @@ -489,8 +488,7 @@ static function emailError($emailAddress, $errno, $errstr, $errfile, $errline, $
* @deprecated 2.5 See SS_Log on setting up error file logging
*/
protected static function log_error_if_necessary($errno, $errstr, $errfile, $errline, $errcontext, $errtype) {
user_error('Debug::log_error_if_necessary() and Debug::log_errors_to() are deprecated. Please use SS_Log instead.
See the class documentation in SS_Log.php for more information.', E_USER_NOTICE);
Deprecation::notice('2.5', 'Use SS_Log instead. See the class documentation in SS_Log.php for more information.');
$priority = ($errtype == 'Error') ? SS_Log::ERR : SS_Log::WARN;
$writer = new SS_LogFileWriter('../' . self::$log_errors_to);
SS_Log::add_writer($writer, $priority);
Expand Down Expand Up @@ -534,6 +532,7 @@ static function get_custom_smtp_server() {
* @param string $sendWarnings Set to true to send warnings as well as errors (Default: false)
*/
static function send_errors_to($emailAddress, $sendWarnings = false) {
Deprecation::notice('2.5', 'Use SS_Log instead. See SS_Log on setting up error email notification.');
self::$send_errors_to = $emailAddress;
self::$send_warnings_to = $sendWarnings ? $emailAddress : null;
}
Expand All @@ -543,6 +542,7 @@ static function send_errors_to($emailAddress, $sendWarnings = false) {
* @deprecated 2.5 See SS_Log on setting up error email notification
*/
static function get_send_errors_to() {
Deprecation::notice('2.5', 'Use SS_Log instead. See SS_Log on setting up error email notification.');
return self::$send_errors_to;
}

Expand All @@ -551,6 +551,7 @@ static function get_send_errors_to() {
* @deprecated 2.5 See SS_Log on setting up error email notification
*/
static function send_warnings_to($emailAddress) {
Deprecation::notice('2.5', 'Use SS_Log instead. See SS_Log on setting up error email notification.');
self::$send_warnings_to = $emailAddress;
}

Expand All @@ -559,6 +560,7 @@ static function send_warnings_to($emailAddress) {
* @deprecated 2.5 See SS_Log on setting up error email notification
*/
static function get_send_warnings_to() {
Deprecation::notice('2.5', 'Use SS_Log instead. See SS_Log on setting up error email notification.');
return self::$send_warnings_to;
}

Expand All @@ -567,6 +569,7 @@ static function get_send_warnings_to() {
* @deprecated 2.5 See SS_Log on setting up error file logging
*/
static function log_errors_to($logFile = ".sserrors") {
Deprecation::notice('2.5', 'Use SS_Log instead. See SS_Log on setting up error file logging.');
self::$log_errors_to = $logFile;
}

Expand All @@ -584,15 +587,15 @@ static function caller() {
* @deprecated 2.5 Please use {@link SS_Backtrace::backtrace()}
*/
static function backtrace($returnVal = false, $ignoreAjax = false) {
user_error('Debug::backtrace() is deprecated. Please use SS_Backtrace::backtrace() instead', E_USER_NOTICE);
Deprecation::notice('2.5', 'Use SS_Backtrace::backtrace instead.');
return SS_Backtrace::backtrace($returnVal, $ignoreAjax);
}

/**
* @deprecated 2.5 Please use {@link SS_Backtrace::get_rendered_backtrace()}
*/
static function get_rendered_backtrace($bt, $plainText = false) {
user_error('Debug::get_rendered_backtrace() is deprecated. Please use SS_Backtrace::get_rendered_backtrace() instead', E_USER_NOTICE);
Deprecation::notice('2.5', 'Use SS_Backtrace::get_rendered_backtrace() instead.');
return SS_Backtrace::get_rendered_backtrace($bt, $plainText);
}

Expand Down
4 changes: 4 additions & 0 deletions filesystem/File.php
Expand Up @@ -173,6 +173,7 @@ function RelativeLink(){
* @deprecated 3.0 Use getTreeTitle()
*/
function TreeTitle() {
Deprecation::notice('3.0', 'Use getTreeTitle() instead.');
return $this->getTreeTitle();
}

Expand Down Expand Up @@ -513,6 +514,7 @@ function getURL() {
* @deprecated 2.4
*/
function getLinkedURL() {
Deprecation::notice('2.4', 'Use getTreeTitle() instead.');
return "$this->Name";
}

Expand Down Expand Up @@ -689,6 +691,8 @@ function getAbsoluteSize(){
* @deprecated alternative_instance_get()
*/
public function instance_get($filter = "", $sort = "", $join = "", $limit="", $containerClass = "DataObjectSet", $having="") {
Deprecation::notice('2.5', 'Use alternative_instance_get() instead.');

$query = $this->extendedSQL($filter, $sort, $limit, $join, $having);
$baseTable = reset($query->from);

Expand Down
12 changes: 6 additions & 6 deletions filesystem/Upload.php
Expand Up @@ -227,7 +227,7 @@ public function setFile($file) {
* @return int Filesize in bytes
*/
public function getAllowedMaxFileSize($ext = null) {
user_error('Upload::getAllowedMaxFileSize() is deprecated. Please use Upload_Validator::getAllowedMaxFileSize() instead', E_USER_NOTICE);
Deprecation::notice('2.5', 'Use Upload_Validator::getAllowedMaxFileSize() instead.');
return $this->validator->getAllowedMaxFileSize($ext);
}

Expand All @@ -246,7 +246,7 @@ public function getAllowedMaxFileSize($ext = null) {
* @param array|int $rules
*/
public function setAllowedMaxFileSize($rules) {
user_error('Upload::setAllowedMaxFileSize() is deprecated. Please use Upload_Validator::setAllowedMaxFileSize() instead', E_USER_NOTICE);
Deprecation::notice('2.5', 'Use Upload_Validator::setAllowedMaxFileSize() instead.');
$this->validator->setAllowedMaxFileSize($rules);
}

Expand All @@ -255,7 +255,7 @@ public function setAllowedMaxFileSize($rules) {
* @return array
*/
public function getAllowedExtensions() {
user_error('Upload::getAllowedExtensions() is deprecated. Please use Upload_Validator::getAllowedExtensions() instead', E_USER_NOTICE);
Deprecation::notice('2.5', 'Use Upload_Validator::getAllowedExtensions() instead.');
return $this->validator->getAllowedExtensions();
}

Expand All @@ -264,7 +264,7 @@ public function getAllowedExtensions() {
* @param array $rules
*/
public function setAllowedExtensions($rules) {
user_error('Upload::setAllowedExtensions() is deprecated. Please use Upload_Validator::setAllowedExtensions() instead', E_USER_NOTICE);
Deprecation::notice('2.5', 'Use Upload_Validator::setAllowedExtensions() instead.');
$this->validator->setAllowedExtensions($rules);
}

Expand All @@ -279,7 +279,7 @@ public function setAllowedExtensions($rules) {
* @return boolean
*/
public function isValidSize($tmpFile) {
user_error('Upload::isValidSize() is deprecated. Please use Upload_Validator::isValidSize() instead', E_USER_NOTICE);
Deprecation::notice('2.5', 'Use Upload_Validator::isValidSize() instead.');
$validator = new Upload_Validator();
$validator->setTmpFile($tmpFile);
return $validator->isValidSize();
Expand All @@ -294,7 +294,7 @@ public function isValidSize($tmpFile) {
* @return boolean
*/
public function isValidExtension($tmpFile) {
user_error('Upload::isValidExtension() is deprecated. Please use Upload_Validator::isValidExtension() instead', E_USER_NOTICE);
Deprecation::notice('2.5', 'Use Upload_Validator::isValidExtension() instead.');
$validator = new Upload_Validator();
$validator->setTmpFile($tmpFile);
return $validator->isValidExtension();
Expand Down
4 changes: 2 additions & 2 deletions forms/ComplexTableField.php
Expand Up @@ -444,10 +444,10 @@ function AddForm($childID = null) {
}

/**
* @deprecated
* @deprecated 3.0
*/
function setRelationAutoSetting($value) {
user_error("ComplexTableField::setRelationAutoSetting() is deprecated; manipulate the DataList instead", E_USER_WARNING);
Deprecation::notice('3.0', 'Manipulate the DataList instead.');
}

/**
Expand Down
1 change: 1 addition & 0 deletions forms/CompositeField.php
Expand Up @@ -56,6 +56,7 @@ public function FieldList() {
* @deprecated 3.0 Please use {@link FieldList()}.
*/
public function FieldSet() {
Deprecation::notice('3.0', 'Use FieldList() instead.');
return $this->FieldList();
}

Expand Down
4 changes: 2 additions & 2 deletions forms/FieldSet.php
Expand Up @@ -8,10 +8,10 @@
class FieldSet extends FieldList {

/**
* @deprecated 3.0.0 Use FieldList instead
* @deprecated 3.0 Use FieldList instead
*/
public function __construct($items = array()) {
Deprecation::notice('3.0.0', 'Use FieldList instead');
Deprecation::notice('3.0', 'Use FieldList instead.');
parent::__construct(!is_array($items) || func_num_args() > 1 ? func_get_args(): $items);
}
}
2 changes: 2 additions & 0 deletions forms/Form.php
Expand Up @@ -1215,6 +1215,7 @@ function enableSecurityToken() {
* @deprecated 2.5 Use SecurityToken::disable()
*/
static function disable_all_security_tokens() {
Deprecation::notice('2.5', 'Use SecurityToken::disable() instead.');
SecurityToken::disable();
}

Expand All @@ -1227,6 +1228,7 @@ static function disable_all_security_tokens() {
* @return bool
*/
function securityTokenEnabled() {
Deprecation::notice('2.5', 'Use Form->getSecurityToken()->isEnabled() instead.');
return $this->securityToken->isEnabled();
}

Expand Down
1 change: 1 addition & 0 deletions forms/FormField.php
Expand Up @@ -127,6 +127,7 @@ function getName() {
* @deprecated 3.0 Use {@link getName()}.
*/
public function Name() {
Deprecation::notice('3.0', 'Use getName() instead.');
return $this->getName();
}

Expand Down
5 changes: 4 additions & 1 deletion forms/TableListField.php
Expand Up @@ -473,6 +473,7 @@ function getCsvDataList() {
* @deprecated Use getDataList() instead.
*/
function getQuery() {
Deprecation::notice('3.0', 'Use getDataList() instead.');
$list = $this->getDataList();
if(method_exists($list,'dataQuery')) {
return $this->getDataList()->dataQuery()->query();
Expand All @@ -483,6 +484,7 @@ function getQuery() {
* @deprecated Use getCsvDataList() instead.
*/
function getCsvQuery() {
Deprecation::notice('3.0', 'Use getCsvDataList() instead.');
$list = $this->getCsvDataList();
if(method_exists($list,'dataQuery')) {
return $list->dataQuery()->query();
Expand Down Expand Up @@ -745,7 +747,7 @@ function ListStart() {
* @deprecated Put the query string onto your form's link instead :-)
*/
function setExtraLinkParams($params){
user_error("TableListField::setExtraLinkParams() deprecated - put the query string onto your form's FormAction instead; it will be handed down to all field with special handlers", E_USER_NOTICE);
Deprecation::notice('2.4', 'Put the query string onto your FormAction instead().');
$this->extraLinkParams = $params;
}

Expand Down Expand Up @@ -1086,6 +1088,7 @@ function Utility() {
* @deprecated Please use the standard URL through Link() which gives you the FieldHolder as an HTML fragment.
*/
function ajax_refresh() {
Deprecation::notice('2.4', 'Please use the standard URL through Link() which gives you the FieldHolder as an HTML fragment instead.');
// compute sourceItems here instead of Items() to ensure that
// pagination and filters are respected on template accessors
//$this->sourceItems();
Expand Down
3 changes: 3 additions & 0 deletions forms/Validator.php
Expand Up @@ -127,13 +127,15 @@ function validationError($fieldName, $message, $messageType='') {
* @deprecated 2.4 Use Validator->getErrors() and custom code
*/
function showError() {
Deprecation::notice('2.4', 'Use Validator->getErrors() and custom code instead.');
Debug::show($this->errors);
}

/**
* @deprecated 2.4 Use custom code
*/
function getCombinedError(){
Deprecation::notice('2.4', 'Use custom code instead.');
if($this->errors) {
foreach($this->errors as $error){
$ret['message'] .= $error['message']."<br />";
Expand All @@ -148,6 +150,7 @@ function getCombinedError(){
* @deprecated 2.4 Use getErrors()
*/
function getError(){
Deprecation::notice('2.4', 'Use getErrors() instead.');
return $this->getErrors();
}

Expand Down
3 changes: 1 addition & 2 deletions model/ComponentSet.php
Expand Up @@ -3,8 +3,7 @@
* @deprecated 3.0 Use ManyManyList or HasManyList
*/
class ComponentSet extends DataObjectSet {

function setComponentInfo($type, $ownerObj, $ownerClass, $tableName, $childClass, $joinField = null) {
user_error("ComponentSet is deprecated; use HasManyList or ManyManyList", E_USER_WARNING);
Deprecation::notice('3.0', 'Use ManyManyList or HasManyList instead.');
}
}
2 changes: 1 addition & 1 deletion model/DataExtension.php
Expand Up @@ -53,7 +53,7 @@ public static function load_extra_statics($class, $extension) {

// @deprecated 2.4 - use extraStatics() now, not extraDBFields()
if(method_exists($extensionClass, 'extraDBFields')) {
user_error('DataExtension::extraDBFields() is deprecated. Please use extraStatics() instead.', E_USER_NOTICE);
Deprecation::notice('2.4', 'DataExtension::extraDBFields() is deprecated. Please use extraStatics() instead.');
$extraStaticsMethod = 'extraDBFields';
} else {
$extraStaticsMethod = 'extraStatics';
Expand Down

0 comments on commit e5afa25

Please sign in to comment.