INFRA-132 - s/(else|try){/(else|try) {/
[civicrm-core.git] / CRM / Upgrade / Incremental / php / FourThree.php
index 30daff27d2011d51fec20fee885f3dbe724d39f5..39e046d4f525d75910de979b61c0bb69b812cc61 100644 (file)
@@ -2,7 +2,7 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -40,7 +40,7 @@ class CRM_Upgrade_Incremental_php_FourThree {
    *
    * @return bool
    */
-  function verifyPreDBstate(&$errors) {
+  public function verifyPreDBstate(&$errors) {
     return TRUE;
   }
 
@@ -51,12 +51,13 @@ class CRM_Upgrade_Incremental_php_FourThree {
    * revision to the database.
    *
    * @param $preUpgradeMessage
-   * @param $rev string, a version number, e.g. '4.3.alpha1', '4.3.beta3', '4.3.0'
+   * @param $rev
+   *   String, a version number, e.g. '4.3.alpha1', '4.3.beta3', '4.3.0'.
    * @param null $currentVer
    *
    * @return void|bool
    */
-  function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
+  public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
     if ($rev == '4.3.beta3') {
       //CRM-12084
       //sql for checking orphaned contribution records
@@ -114,11 +115,13 @@ WHERE {$key}.id IS NULL";
   /**
    * Compute any messages which should be displayed after upgrade
    *
-   * @param $postUpgradeMessage string, alterable
-   * @param $rev string, an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs
+   * @param $postUpgradeMessage
+   *   String, alterable.
+   * @param $rev
+   *   String, an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
    * @return void
    */
-  function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
+  public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
     if ($rev == '4.3.alpha1') {
       // check if CiviMember component is enabled
       $config = CRM_Core_Config::singleton();
@@ -130,7 +133,7 @@ WHERE {$key}.id IS NULL";
       //CRM-11636
       //here we do the financial type check and migration
       $isDefaultsModified = self::_checkAndMigrateDefaultFinancialTypes();
-      if($isDefaultsModified) {
+      if ($isDefaultsModified) {
         $postUpgradeMessage .= '<br />' . ts('Please review all price set financial type assignments.');
       }
       list($context, $orgName) = self::createDomainContacts();
@@ -163,7 +166,7 @@ WHERE    entity_value = '' OR entity_value IS NULL
       }
       if (!empty($reminder)) {
         $list = "<br /><ul>" . $list . "</ul>";
-        $postUpgradeMessage .=  '<br />' .ts("Scheduled Reminders must be linked to one or more 'entities' (Events, Event Templates, Activity Types, Membership Types). The following reminders are not configured properly and will not be run. Please review them and update or delete them: %1", array(1 => $list));
+        $postUpgradeMessage .=  '<br />'  . ts("Scheduled Reminders must be linked to one or more 'entities' (Events, Event Templates, Activity Types, Membership Types). The following reminders are not configured properly and will not be run. Please review them and update or delete them: %1", array(1 => $list));
       }
     }
     if ($rev == '4.3.beta2') {
@@ -219,12 +222,12 @@ WHERE     ceft.entity_id IS NULL;
 
       if ($isOrphanData) {
         $postUpgradeMessage .= "</br> <strong>" . ts('Your database contains extraneous financial records related to deleted contacts and contributions. These records should not affect the site and will not appear in reports, search results or exports. However you may wish to clean them up. Refer to <a href="%1" target="_blank">this wiki page for details</a>.
-        ', array( 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Clean+up+extraneous+financial+data+-+4.3+upgrades')) . "</strong>";
+        ', array(1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Clean+up+extraneous+financial+data+-+4.3+upgrades')) . "</strong>";
       }
     }
     if ($rev == '4.3.4') {
       $postUpgradeMessage .= '<br />' . ts('System Administrator Alert: If you are running scheduled jobs using CLI.php, you will need to reconfigure cron tasks to include a password. Scheduled jobs will no longer run if the password is not provided (<a href="%1" target="_blank">learn more</a>).',
-      array( 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Managing+Scheduled+Jobs'));
+      array(1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Managing+Scheduled+Jobs'));
     }
     if ($rev == '4.3.5') {
       $postUpgradeMessage .= '<br />' . ts('Default versions of the following System Workflow Message Templates have been modified to handle new functionality: <ul><li>Events - Registration Confirmation and Receipt (on-line)</li><li>Events - Registration Confirmation and Receipt (off-line)</li></ul> If you have modified these templates, please review the new default versions and implement updates as needed to your copies (Administer > Communications > Message Templates > System Workflow Messages).');
@@ -235,7 +238,7 @@ INNER JOIN civicrm_product cp ON ccp.product_id = cp.id
 WHERE ccp.financial_type_id IS NULL and cp.cost > 0');
       if ($flag) {
         $postUpgradeMessage .= '<br />' . ts('Your database contains one or more premiums which have a cost but are not linked to a financial type. If you are exporting transations to an accounting package, this will result in unbalanced transactions. <a href="%1" target="_blank">You can review steps to correct this situation on the wiki.</a>',
-        array( 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Fixing+Issues+Caused+by+Missing+Cost+of+Goods+Account+-+4.3+Upgrades'));
+        array(1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Fixing+Issues+Caused+by+Missing+Cost+of+Goods+Account+-+4.3+Upgrades'));
       }
     }
   }
@@ -245,7 +248,7 @@ WHERE ccp.financial_type_id IS NULL and cp.cost > 0');
    *
    * @return bool
    */
-  function upgrade_4_3_alpha1($rev) {
+  public function upgrade_4_3_alpha1($rev) {
     self::task_4_3_alpha1_checkDBConstraints();
 
     // add indexes for civicrm_entity_financial_trxn
@@ -269,9 +272,9 @@ WHERE ccp.financial_type_id IS NULL and cp.cost > 0');
 
     // CRM-10893
     // fix WP access control
-    $config = CRM_Core_Config::singleton( );
+    $config = CRM_Core_Config::singleton();
     if ($config->userFramework == 'WordPress') {
-      civicrm_wp_set_capabilities( );
+      civicrm_wp_set_capabilities();
     }
 
     // Update phones CRM-11292.
@@ -283,7 +286,7 @@ WHERE ccp.financial_type_id IS NULL and cp.cost > 0');
   /**
    * @param $rev
    */
-  function upgrade_4_3_alpha2($rev) {
+  public function upgrade_4_3_alpha2($rev) {
     //CRM-11847
     $isColumnPresent = CRM_Core_DAO::checkFieldExists('civicrm_dedupe_rule_group', 'is_default');
     if ($isColumnPresent) {
@@ -295,14 +298,14 @@ WHERE ccp.financial_type_id IS NULL and cp.cost > 0');
   /**
    * @param $rev
    */
-  function upgrade_4_3_alpha3($rev) {
+  public function upgrade_4_3_alpha3($rev) {
     $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.alpha3')), 'task_4_3_x_runSql', $rev);
   }
 
   /**
    * @param $rev
    */
-  function upgrade_4_3_beta2($rev) {
+  public function upgrade_4_3_beta2($rev) {
     $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta2')), 'task_4_3_x_runSql', $rev);
 
     // CRM-12002
@@ -317,7 +320,7 @@ WHERE ccp.financial_type_id IS NULL and cp.cost > 0');
   /**
    * @param $rev
    */
-  function upgrade_4_3_beta3($rev) {
+  public function upgrade_4_3_beta3($rev) {
     $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta3')), 'task_4_3_x_runSql', $rev);
     // CRM-12065
     $query = "SELECT id, form_values FROM civicrm_report_instance WHERE form_values LIKE '%contribution_type%'";
@@ -329,7 +332,7 @@ WHERE ccp.financial_type_id IS NULL and cp.cost > 0');
   /**
    * @param $rev
    */
-  function upgrade_4_3_beta4($rev) {
+  public function upgrade_4_3_beta4($rev) {
     $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.beta4')), 'task_4_3_x_runSql', $rev);
     // add indexes for civicrm_entity_financial_trxn
     // CRM-12141
@@ -339,7 +342,7 @@ WHERE ccp.financial_type_id IS NULL and cp.cost > 0');
   /**
    * @param $rev
    */
-  function upgrade_4_3_beta5($rev) {
+  public function upgrade_4_3_beta5($rev) {
     // CRM-12205
     if (
       CRM_Core_DAO::checkTableExists('log_civicrm_financial_trxn') &&
@@ -366,14 +369,14 @@ ADD COLUMN   premiums_nothankyou_label varchar(255) COLLATE utf8_unicode_ci DEFA
   /**
    * @param $rev
    */
-  function upgrade_4_3_4($rev) {
+  public function upgrade_4_3_4($rev) {
     $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.3.4')), 'task_4_3_x_runSql', $rev);
   }
 
   /**
    * @param $rev
    */
-  function upgrade_4_3_5($rev) {
+  public function upgrade_4_3_5($rev) {
     // CRM-12156
     $config = CRM_Core_Config::singleton();
     $dbname  = DB::parseDSN($config->dsn);
@@ -401,7 +404,7 @@ ADD CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`)
   /**
    * @param $rev
    */
-  function upgrade_4_3_6($rev) {
+  public function upgrade_4_3_6($rev) {
     //CRM-13094
     $this->addTask(ts('Add missing constraints'), 'addMissingConstraints', $rev);
     //CRM-13088
@@ -417,7 +420,7 @@ ADD CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`)
   /**
    * @return bool
    */
-  function assignFinancialTypeToPriceRecords() {
+  public function assignFinancialTypeToPriceRecords() {
     $upgrade = new CRM_Upgrade_Form();
     //here we update price set entries
     $sqlFinancialIds = "
@@ -426,7 +429,7 @@ FROM   civicrm_financial_type
 WHERE name IN ('Donation', 'Event Fee', 'Member Dues');
 ";
     $daoFinancialIds = CRM_Core_DAO::executeQuery($sqlFinancialIds);
-    while($daoFinancialIds->fetch()) {
+    while ($daoFinancialIds->fetch()) {
       $financialIds[$daoFinancialIds->name] = $daoFinancialIds->id;
     }
     $sqlPriceSetUpdate = "
@@ -461,7 +464,7 @@ INNER JOIN civicrm_price_set ps ON (pf.price_set_id = ps.id)
   /**
    * @return bool
    */
-  static function _checkAndMigrateDefaultFinancialTypes() {
+  public static function _checkAndMigrateDefaultFinancialTypes() {
     $modifiedDefaults = FALSE;
     //insert types if not exists
     $sqlFetchTypes = "
@@ -473,7 +476,7 @@ WHERE  name IN ('Donation', 'Event Fee', 'Member Dues') AND is_active =1
 
     if ($daoFetchTypes->N < 3) {
       $modifiedDefaults = TRUE;
-      $insertStatments = array (
+      $insertStatments = array(
         'Donation' => "('Donation', 0, 1, 1)",
         'Member' => "('Member Dues', 0, 1, 1)",
         'Event Fee' => "('Event Fee', 0, 1, 0)",
@@ -493,7 +496,7 @@ ON DUPLICATE KEY UPDATE  is_active = 1
   /**
    * @return bool
    */
-  function createFinancialRecords() {
+  public function createFinancialRecords() {
     $upgrade = new CRM_Upgrade_Form();
 
     // update civicrm_entity_financial_trxn.amount = civicrm_financial_trxn.total_amount
@@ -542,7 +545,7 @@ AND    financial_account_type_id = {$accountType}
     $validCurrencyCodes = implode("','", $validCurrencyCodes);
     $config = CRM_Core_Config::singleton();
     $defaultCurrency = $config->defaultCurrency;
-    $now = date( 'YmdHis' );
+    $now = date('YmdHis');
 
     //adding financial_trxn records and entity_financial_trxn records related to contribution
     //Add temp column for easy entry in entity_financial_trxn
@@ -837,7 +840,7 @@ FROM   civicrm_financial_item fi";
   /**
    * @return array
    */
-  function createDomainContacts() {
+  public function createDomainContacts() {
     $domainParams = $context = array();
     $query = "
 ALTER TABLE civicrm_domain ADD contact_id INT( 10 ) UNSIGNED NULL DEFAULT NULL COMMENT 'FK to Contact ID. This is specifically not an FK to avoid circular constraints',
@@ -850,7 +853,7 @@ LEFT JOIN civicrm_loc_block clb ON clb.id = cd. loc_block_id
 LEFT JOIN civicrm_email ce ON ce.id = clb.email_id ;
 ' ;
     $dao = CRM_Core_DAO::executeQuery($query);
-    while($dao->fetch()) {
+    while ($dao->fetch()) {
       $query = "
 SELECT    cc.id FROM civicrm_contact cc
 LEFT JOIN civicrm_email ce ON ce.contact_id = cc.id
@@ -884,7 +887,7 @@ WHERE     cc.contact_type = 'Organization' AND cc.organization_name = %1
     return $context;
   }
 
-  function task_4_3_alpha1_checkDBConstraints() {
+  public function task_4_3_alpha1_checkDBConstraints() {
     //checking whether the foreign key exists before dropping it CRM-11260
     $config = CRM_Core_Config::singleton();
     $dbUf = DB::parseDSN($config->dsn);
@@ -902,11 +905,12 @@ AND TABLE_SCHEMA = %1
 ";
     $params = array(1 => array($dbUf['database'], 'String'));
     $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, NULL, FALSE, FALSE);
-    foreach($tables as $columnName => $value){
+    foreach ($tables as $columnName => $value) {
       if ($value['tableName'] == 'civicrm_membership_type' || $value['tableName'] == 'civicrm_contribution_recur') {
         $foreignKeyExists = CRM_Core_DAO::checkConstraintExists($value['tableName'], $value['fkey']);
         $fKey = $value['fkey'];
-      } else {
+      }
+      else {
         $foreignKeyExists = CRM_Core_DAO::checkFKConstraintInFormat($value['tableName'], $columnName);
         $fKey = "`FK_{$value['tableName']}_{$columnName}`";
       }
@@ -936,7 +940,7 @@ ALTER TABLE civicrm_financial_account
    * Read creation and modification times from civicrm_log; add
    * them to civicrm_contact.
    */
-  function convertTimestamps(CRM_Queue_TaskContext $ctx, $startId, $endId) {
+  public function convertTimestamps(CRM_Queue_TaskContext $ctx, $startId, $endId) {
     $sql = "
       SELECT entity_id, min(modified_date) AS created, max(modified_date) AS modified
       FROM civicrm_log
@@ -967,7 +971,7 @@ ALTER TABLE civicrm_financial_account
   /**
    * Change index and add missing constraints for civicrm_contribution_recur
    */
-  function addMissingConstraints(CRM_Queue_TaskContext $ctx) {
+  public function addMissingConstraints(CRM_Queue_TaskContext $ctx) {
     $query = "SHOW KEYS FROM `civicrm_contribution_recur` WHERE key_name = 'UI_contrib_payment_instrument_id'";
     $dao = CRM_Core_DAO::executeQuery($query);
     if ($dao->N) {
@@ -999,7 +1003,7 @@ ALTER TABLE civicrm_financial_account
    * CRM-12844
    *
    */
-  function updateFinancialTrxnData(CRM_Queue_TaskContext $ctx) {
+  public function updateFinancialTrxnData(CRM_Queue_TaskContext $ctx) {
     $upgrade = new CRM_Upgrade_Form();
     $sql = "SELECT cc.id contribution_id, cc.contribution_recur_id, cft.payment_processor_id,
 cft.id financial_trxn_id, cfi.entity_table, cft.from_financial_account_id, cft.to_financial_account_id
@@ -1061,7 +1065,7 @@ id IN (' . implode(',', $val) . ')';
    * CRM-12844
    *
    */
-  function updateLineItemData(CRM_Queue_TaskContext $ctx) {
+  public function updateLineItemData(CRM_Queue_TaskContext $ctx) {
     $sql = "SELECT cc.id contribution_id, cc.contribution_recur_id,
 cc.financial_type_id contribution_financial_type,
 cli.financial_type_id line_financial_type_id,
@@ -1107,7 +1111,7 @@ cfi.financial_account_id = %4,
 cfi.description = %5,
 cli.financial_type_id = %6
 WHERE cfi.entity_table = 'civicrm_line_item'
-AND cli.entity_table = 'civicrm_contribution' AND cli.id IN (" . implode(',', $value). ');';
+AND cli.entity_table = 'civicrm_contribution' AND cli.id IN (" . implode(',', $value) . ');';
       $params =  array(
         1 => array($financialTrxn[$key]['label'], 'String'),
         2 => array($financialTrxn[$key]['price_field_id'], 'Integer'),
@@ -1125,7 +1129,7 @@ AND cli.entity_table = 'civicrm_contribution' AND cli.id IN (" . implode(',', $v
    * Replace contribution_type to financial_type in table
    * civicrm_saved_search and Structure civicrm_report_instance
    */
-  function replaceContributionTypeId(CRM_Queue_TaskContext $ctx, $query, $table) {
+  public function replaceContributionTypeId(CRM_Queue_TaskContext $ctx, $query, $table) {
     $dao = CRM_Core_DAO::executeQuery($query);
     while ($dao->fetch()) {
       $formValues = unserialize($dao->form_values);
@@ -1143,7 +1147,7 @@ AND cli.entity_table = 'civicrm_contribution' AND cli.id IN (" . implode(',', $v
               $formValues[$value]['financial_type_id'] = $formValues[$value]['contribution_type_id'];
               unset($formValues[$value]['contribution_type_id']);
             }
-            else if (array_key_exists('contribution_type', $formValues[$value])) {
+            elseif (array_key_exists('contribution_type', $formValues[$value])) {
               $formValues[$value]['financial_type'] = $formValues[$value]['contribution_type'];
               unset($formValues[$value]['contribution_type']);
             }
@@ -1205,7 +1209,7 @@ AND cli.entity_table = 'civicrm_contribution' AND cli.id IN (" . implode(',', $v
    *
    * @return bool TRUE for success
    */
-  function task_4_3_x_checkConstraints(CRM_Queue_TaskContext $ctx) {
+  public function task_4_3_x_checkConstraints(CRM_Queue_TaskContext $ctx) {
     CRM_Core_DAO::executeQuery('ALTER TABLE `civicrm_financial_account` CHANGE `contact_id` `contact_id` INT( 10 ) UNSIGNED NULL DEFAULT NULL');
     $config = CRM_Core_Config::singleton();
     $dbname  = DB::parseDSN($config->dsn);
@@ -1264,7 +1268,7 @@ AND CONSTRAINT_SCHEMA = %1";
    *
    * @return bool TRUE for success
    */
-  function task_4_3_x_checkIndexes(CRM_Queue_TaskContext $ctx) {
+  public function task_4_3_x_checkIndexes(CRM_Queue_TaskContext $ctx) {
     $query = "
 SHOW KEYS
 FROM civicrm_entity_financial_trxn
@@ -1289,7 +1293,7 @@ ADD INDEX UI_entity_financial_trxn_entity_id (entity_id);
    *
    * @return bool TRUE for success
    */
-  static function phoneNumeric(CRM_Queue_TaskContext $ctx) {
+  public static function phoneNumeric(CRM_Queue_TaskContext $ctx) {
     CRM_Core_DAO::executeQuery(CRM_Contact_BAO_Contact::DROP_STRIP_FUNCTION_43);
     CRM_Core_DAO::executeQuery(CRM_Contact_BAO_Contact::CREATE_STRIP_FUNCTION_43);
     CRM_Core_DAO::executeQuery("UPDATE civicrm_phone SET phone_numeric = civicrm_strip_non_numeric(phone)");
@@ -1299,7 +1303,7 @@ ADD INDEX UI_entity_financial_trxn_entity_id (entity_id);
   /**
    * (Queue Task Callback)
    */
-  static function task_4_3_x_runSql(CRM_Queue_TaskContext $ctx, $rev) {
+  public static function task_4_3_x_runSql(CRM_Queue_TaskContext $ctx, $rev) {
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);