dev/core#128 Add deprecated warning helper function
authorMatthew Wire <devel@mrwire.co.uk>
Sun, 27 May 2018 12:13:33 +0000 (13:13 +0100)
committerMatthew Wire <devel@mrwire.co.uk>
Sun, 27 May 2018 12:14:45 +0000 (13:14 +0100)
CRM/Contact/BAO/Contact/Location.php
CRM/Contact/Form/Task/EmailCommon.php
CRM/Contribute/BAO/ContributionRecur.php
CRM/Core/Error.php
CRM/Core/OptionGroup.php
CRM/Core/PseudoConstant.php
CRM/Member/BAO/MembershipType.php
CRM/Report/Form.php
CRM/Utils/Hook.php

index a25cad27f89c7b9c69fa8ac7c375a139652b4580..a13fcb1c38bb9ee16ac5a523fd6145ae6754405f 100644 (file)
@@ -75,7 +75,7 @@ class CRM_Contact_BAO_Contact_Location {
    *   tuple of display_name and sms if found, or (null,null)
    */
   public static function getPhoneDetails($id, $type = NULL) {
-    Civi::log()->warning('Deprecated function CRM_Contact_BAO_Contact_Location::getPhoneDetails, use Phone.get API instead', array('civi.tag' => 'deprecated'));
+    CRM_Core_Error::deprecatedFunctionWarning('Phone.get API instead');
     if (!$id) {
       return array(NULL, NULL);
     }
index 73a71d7e763d0bbd247a7c5640d676e06b0b1e11..3f12ee333a4d11a9239ff9eb8255c803978c2b7a 100644 (file)
@@ -48,7 +48,7 @@ class CRM_Contact_Form_Task_EmailCommon {
    * @return array $domainEmails;
    */
   public static function domainEmails() {
-    Civi::log()->warning('Deprecated function, use CRM_Core_BAO_Email::domainEmails()', array('civi.tag' => 'deprecated'));
+    CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_BAO_Email::domainEmails()');
     return CRM_Core_BAO_Email::domainEmails();
   }
 
index 95d99c2bef626bfda3b0f54c32e8b7618bea6b6d..7700d856e8cd1c6aaab059a186b82122341ba964 100644 (file)
@@ -333,7 +333,7 @@ SELECT r.payment_processor_id
    *
    */
   public static function getRecurContributions($contactId) {
-    Civi::log()->warning('Deprecated function, use ContributionRecur.get API instead', array('civi.tag' => 'deprecated'));
+    CRM_Core_Error::deprecatedFunctionWarning('ContributionRecur.get API instead');
     $params = array();
     $recurDAO = new CRM_Contribute_DAO_ContributionRecur();
     $recurDAO->contact_id = $contactId;
index c009a7ffa17e0c862b10e73806012e73db12d4a5..ab491e8b81a2fe6daa0c2481881c0ba789478543 100644 (file)
@@ -1030,6 +1030,19 @@ class CRM_Core_Error extends PEAR_ErrorStack {
     return FALSE;
   }
 
+  /**
+   * Output a deprecated function warning to log file.  Deprecated class:function is automatically generated from calling function.
+   *
+   * @param $newMethod
+   *   description of new method (eg. "buildOptions() method in the appropriate BAO object").
+   */
+  public static function deprecatedFunctionWarning($newMethod) {
+    $dbt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
+    $callerFunction = isset($dbt[1]['function']) ? $dbt[1]['function'] : NULL;
+    $callerClass = isset($dbt[1]['class']) ? $dbt[1]['class'] : NULL;
+    Civi::log()->warning("Deprecated function $callerClass::$callerFunction, use $newMethod.", array('civi.tag' => 'deprecated'));
+  }
+
 }
 
 $e = new PEAR_ErrorStack('CRM');
index db946e6ca62546275e03d10052fafc3165fc3c20..bc1f7ad2ac8124e538fa01d5e940ed0392c58945 100644 (file)
@@ -342,7 +342,7 @@ WHERE  v.option_group_id = g.id
    * @return null
    */
   public static function getLabel($groupName, $value, $onlyActiveValue = TRUE) {
-    Civi::log()->warning('Deprecated function CRM_Core_OptionGroup::getLabel, use CRM_Core_PseudoConstant::getLabel', array('civi.tag' => 'deprecated'));
+    CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_PseudoConstant::getLabel');
     if (empty($groupName) ||
       empty($value)
     ) {
@@ -396,7 +396,7 @@ WHERE  v.option_group_id = g.id
       return NULL;
     }
 
-    Civi::log()->warning('Deprecated function CRM_Core_OptionGroup::getValue, use CRM_Core_PseudoConstant::getKey', array('civi.tag' => 'deprecated'));
+    CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_PseudoConstant::getKey');
 
     $query = "
 SELECT  v.label as label ,v.{$valueField} as value
index fa4234ad1a882ef787973c231eec578be26cf1e3..e69aaf048da1f5c6f3a6f531f80e1d55e92f4eb4 100644 (file)
@@ -579,7 +579,6 @@ class CRM_Core_PseudoConstant {
    * Flush given pseudoconstant so it can be reread from db.
    * nex time it's requested.
    *
-   *
    * @param bool|string $name pseudoconstant to be flushed
    */
   public static function flush($name = 'cache') {
index 64fb342d47c713a9cee81acac8922ed497c180ea..66c9cd2a8e9787d72096d645889e70fef5e22df0 100644 (file)
@@ -636,7 +636,7 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType {
    *   array of the details of membership types
    */
   public static function getMembershipTypesByOrg($orgID) {
-    Civi::log()->warning('Deprecated function getMembershipTypesByOrg, please user membership_type api', array('civi.tag' => 'deprecated'));
+    CRM_Core_Error::deprecatedFunctionWarning('membership_type api');
     $memberTypesSameParentOrg = civicrm_api3('MembershipType', 'get', array(
       'member_of_contact_id' => $orgID,
       'options' => array(
index 8ae05d9d082e1b70c9908ddd83518df067b893a6..367408a339af74bbc40ee1ac7566a9cbbcb045c9 100644 (file)
@@ -4526,7 +4526,7 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a
    * (left here in case extensions use it).
    */
   public function addAddressFromClause() {
-    Civi::log()->warning('Deprecated function addAddressFromClause. Use joinAddressFromContact.', array('civi.tag' => 'deprecated'));
+    CRM_Core_Error::deprecatedFunctionWarning('CRM_Report_Form::joinAddressFromContact');
     // include address field if address column is to be included
     if ((isset($this->_addressField) &&
         $this->_addressField
@@ -4548,8 +4548,7 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a
    *  (left here in case extensions use it).
    */
   public function addPhoneFromClause() {
-
-    Civi::log()->warning('Deprecated function addPhoneFromClause. Use joinPhoneFromContact.', array('civi.tag' => 'deprecated'));
+    CRM_Core_Error::deprecatedFunctionWarning('CRM_Report_Form::joinPhoneFromContact');
     // include address field if address column is to be included
     if ($this->isTableSelected('civicrm_phone')) {
       $this->_from .= "
index 3f36511e47362ccb9faf96db7ccf77bc39daf2bb..0ad0debd39cd6052042c6e767ad0a2bb4bdae8f2 100644 (file)
@@ -2009,7 +2009,7 @@ abstract class CRM_Utils_Hook {
     // are expected to be called externally.
     // It's really really unlikely anyone uses this - but let's add deprecations for a couple
     // of releases first.
-    Civi::log()->warning('Deprecated function CRM_Utils_Hook::alterMail, use CRM_Utils_Hook::alterMailer', array('civi.tag' => 'deprecated'));
+    CRM_Core_Error::deprecatedFunctionWarning('CRM_Utils_Hook::alterMailer');
     return CRM_Utils_Hook::alterMailer($mailer, $driver, $params);
   }