Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-02-16-17-51-20
[civicrm-core.git] / CRM / Upgrade / Incremental / php / FourFour.php
index 4bd43d2ef0c4060d2c9bb8e78198f67de783c712..34f5085ec85480f3bde025e636b0736dc4fedac0 100644 (file)
@@ -22,7 +22,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -46,14 +46,14 @@ class CRM_Upgrade_Incremental_php_FourFour {
   }
 
   /**
-   * Compute any messages which should be displayed beforeupgrade
+   * Compute any messages which should be displayed beforeupgrade.
    *
    * Note: This function is called iteratively for each upcoming
    * revision to the database.
    *
    * @param $preUpgradeMessage
-   * @param $rev
-   *   String, a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'.
+   * @param string $rev
+   *   a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'.
    * @param null $currentVer
    *
    * @return void
@@ -69,19 +69,19 @@ class CRM_Upgrade_Incremental_php_FourFour {
       }
       if ($oversizedEntries > 0) {
         $preUpgradeMessage .= '<br/>' . ts("WARNING: There are %1 word-replacement entries which will not be valid in v4.4+ (eg with over 255 characters). They will be dropped during upgrade. For details, consult the CiviCRM log.", array(
-          1 => $oversizedEntries
-        ));
+            1 => $oversizedEntries,
+          ));
       }
     }
   }
 
   /**
-   * Compute any messages which should be displayed after upgrade
+   * 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 string $postUpgradeMessage
+   *   alterable.
+   * @param string $rev
+   *   an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
    * @return void
    */
   public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
@@ -102,11 +102,14 @@ LEFT JOIN civicrm_contribution cc ON ceft.entity_id = cc.id
 WHERE ceft.entity_table = 'civicrm_contribution' AND cft.payment_instrument_id IS NULL;";
       $dao = CRM_Core_DAO::executeQuery($query);
       if ($dao->N) {
-        $postUpgradeMessage .= '<br /><br /><strong>' . ts('Your database contains %1 financial transaction records with no payment instrument (Paid By is empty). If you use the Accounting Batches feature this may result in unbalanced transactions. If you do not use this feature, you can ignore the condition (although you will be required to select a Paid By value for new transactions). <a href="%2" target="_blank">You can review steps to correct transactions with missing payment instruments on the wiki.</a>', array(1 => $dao->N, 2 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Fixing+Transactions+Missing+a+Payment+Instrument+-+4.4.3+Upgrades')) . '</strong>';
+        $postUpgradeMessage .= '<br /><br /><strong>' . ts('Your database contains %1 financial transaction records with no payment instrument (Paid By is empty). If you use the Accounting Batches feature this may result in unbalanced transactions. If you do not use this feature, you can ignore the condition (although you will be required to select a Paid By value for new transactions). <a href="%2" target="_blank">You can review steps to correct transactions with missing payment instruments on the wiki.</a>', array(
+              1 => $dao->N,
+              2 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Fixing+Transactions+Missing+a+Payment+Instrument+-+4.4.3+Upgrades',
+            )) . '</strong>';
       }
     }
-    if ($rev == '4.4.6'){
-      $postUpgradeMessage .= '<br /><br /><strong>'. ts('Your contact image urls have been upgraded. If your contact image urls did not follow the standard format for image Urls they have not been upgraded. Please check the log to see image urls that were not upgraded.');
+    if ($rev == '4.4.6') {
+      $postUpgradeMessage .= '<br /><br /><strong>' . ts('Your contact image urls have been upgraded. If your contact image urls did not follow the standard format for image Urls they have not been upgraded. Please check the log to see image urls that were not upgraded.');
     }
   }
 
@@ -311,7 +314,7 @@ ALTER TABLE civicrm_dashboard
       }
       elseif ($urlElements[1] == 'report') {
         $url = explode('&', $urlElements[3]);
-        $name = 'report/' .$url[0];
+        $name = 'report/' . $url[0];
       }
       $values .= "
       WHEN {$dashboard->id} THEN '{$name}'
@@ -335,8 +338,8 @@ ALTER TABLE civicrm_dashboard
   /**
    * @param $rev
    */
-  public function upgrade_4_4_6($rev){
-    $sql = "SELECT count(*) AS count FROM INFORMATION_SCHEMA.STATISTICS where ".
+  public function upgrade_4_4_6($rev) {
+    $sql = "SELECT count(*) AS count FROM INFORMATION_SCHEMA.STATISTICS where " .
       "TABLE_SCHEMA = database() AND INDEX_NAME = 'index_image_url' AND TABLE_NAME = 'civicrm_contact';";
     $dao = CRM_Core_DAO::executeQuery($sql);
     $dao->fetch();
@@ -354,11 +357,11 @@ ALTER TABLE civicrm_dashboard
   }
 
   /**
-   * @param CRM_Queue_TaskContext $ctx
-   * @param int $startId
-   * @param int $endId
+   * @param $rev
+   * @param $originalVer
+   * @param $latestVer
    *
-   * @return bool
+   * @return void
    */
   public function upgrade_4_4_7($rev, $originalVer, $latestVer) {
     // For WordPress/Joomla(?), cleanup broken image_URL from 4.4.6 upgrades - https://issues.civicrm.org/jira/browse/CRM-14971
@@ -376,28 +379,41 @@ ALTER TABLE civicrm_dashboard
     $this->addTask(ts('Update saved search information'), 'changeSavedSearch');
   }
 
-  public static function upgradeImageUrls(CRM_Queue_TaskContext $ctx, $startId, $endId){
+  /**
+   * Upgrade image URLs.
+   *
+   * @param \CRM_Queue_TaskContext $ctx
+   * @param $startId
+   * @param $endId
+   *
+   * @return bool
+   */
+  public static function upgradeImageUrls(CRM_Queue_TaskContext $ctx, $startId, $endId) {
     $dao = self::findContactImageUrls($startId, $endId);
     $failures = array();
-    while ($dao->fetch()){
+    $config = CRM_Core_Config::singleton();
+    while ($dao->fetch()) {
       $imageURL = $dao->image_url;
       $baseurl = CIVICRM_UF_BASEURL;
+      //CRM-15897 - gross hack for joomla to remove the administrator/
+      if ($config->userFramework == 'Joomla') {
+        $baseurl = str_replace("/administrator/", "/", $baseurl);
+      }
       $baselen = strlen($baseurl);
-      if (substr($imageURL, 0, $baselen) == $baseurl){
+      if (substr($imageURL, 0, $baselen) == $baseurl) {
         $photo = basename($dao->image_url);
-        $config = CRM_Core_Config::singleton();
-        $fullpath = $config->customFileUploadDir.$photo;
-        if (file_exists($fullpath)){
+        $fullpath = $config->customFileUploadDir . $photo;
+        if (file_exists($fullpath)) {
           // For anyone who upgraded 4.4.6 release (eg 4.4.0=>4.4.6), the $newImageUrl incorrectly used backend URLs.
           // For anyone who skipped 4.4.6 (eg 4.4.0=>4.4.7), the $newImageUrl correctly uses frontend URLs
           self::setContactImageUrl($dao->id,
-              CRM_Utils_System::url('civicrm/contact/imagefile', 'photo='.$photo, TRUE, NULL, TRUE, TRUE));
+            CRM_Utils_System::url('civicrm/contact/imagefile', 'photo=' . $photo, TRUE, NULL, TRUE, TRUE));
         }
-        else{
+        else {
           $failures[$dao->id] = $dao->image_url;
         }
       }
-      else{
+      else {
         $failures[$dao->id] = $dao->image_url;
       }
     }
@@ -405,6 +421,13 @@ ALTER TABLE civicrm_dashboard
     return TRUE;
   }
 
+  /**
+   * Change saved search.
+   *
+   * @param \CRM_Queue_TaskContext $ctx
+   *
+   * @return bool
+   */
   public static function changeSavedSearch(CRM_Queue_TaskContext $ctx) {
     $membershipStatuses = array_flip(CRM_Member_PseudoConstant::membershipStatus());
 
@@ -470,7 +493,7 @@ ALTER TABLE civicrm_dashboard
         $imageUrlParts = parse_url($imageUrl);
         parse_str($imageUrlParts['query'], $imageUrlQuery);
         self::setContactImageUrl($dao->id,
-          CRM_Utils_System::url('civicrm/contact/imagefile', 'photo='.$imageUrlQuery['photo'], TRUE, NULL, TRUE, TRUE));
+          CRM_Utils_System::url('civicrm/contact/imagefile', 'photo=' . $imageUrlQuery['photo'], TRUE, NULL, TRUE, TRUE));
       }
     }
     return TRUE;
@@ -479,7 +502,8 @@ ALTER TABLE civicrm_dashboard
   /**
    * @param int $startId
    * @param int $endId
-   * @return CRM_Core_DAO columns include "id" and "image_URL"
+   * @return CRM_Core_DAO
+   *   columns include "id" and "image_URL"
    */
   public static function findContactImageUrls($startId, $endId) {
     $sql = "
@@ -516,7 +540,8 @@ AND image_URL IS NOT NULL
    *
    * @param CRM_Queue_TaskContext $ctx
    *
-   * @return bool TRUE for success
+   * @return bool
+   *   TRUE for success
    */
   public static function activityContacts(CRM_Queue_TaskContext $ctx) {
     $upgrade = new CRM_Upgrade_Form();
@@ -550,7 +575,7 @@ WHERE  option_group_id = {$optionGroupID} AND value IN ($ovValues)";
       $value[] = "({$optionGroupID}, 'Activity Targets', 3, 'Activity Targets', 3, 1, 1)";
     }
 
-    if (!$assigneeID || !$sourceID || !$targetID ) {
+    if (!$assigneeID || !$sourceID || !$targetID) {
       $insert = "
 INSERT INTO civicrm_option_value
 (option_group_id, label, value, name, weight, is_reserved, is_active)
@@ -624,7 +649,8 @@ WHERE       source_contact_id IS NOT NULL";
    *
    * @param CRM_Queue_TaskContext $ctx
    *
-   * @return bool TRUE for success
+   * @return bool
+   *   TRUE for success
    * @see http://issues.civicrm.org/jira/browse/CRM-13187
    */
   public static function wordReplacements(CRM_Queue_TaskContext $ctx) {
@@ -656,7 +682,8 @@ CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` (
    * @param CRM_Queue_TaskContext $ctx
    * @param $rev
    *
-   * @return bool TRUE for success
+   * @return bool
+   *   TRUE for success
    * @see http://issues.civicrm.org/jira/browse/CRM-13655
    */
   public static function wordReplacements_patch(CRM_Queue_TaskContext $ctx, $rev) {
@@ -718,7 +745,8 @@ CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` (
    *
    * @param bool $rebuildEach
    *   Whether to perform rebuild after each individual API call.
-   * @return array Each item is $params for WordReplacement.create
+   * @return array
+   *   Each item is $params for WordReplacement.create
    * @see CRM_Core_BAO_WordReplacement::convertConfigArraysToAPIParams
    */
   public static function getConfigArraysAsAPIParams($rebuildEach) {
@@ -780,9 +808,9 @@ CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` (
   }
 
 
-  /***
+  /**
    * CRM-13998 missing alter statements for civicrm_report_instance
-   ***/
+   */
   public function updateReportInstanceTable() {
 
     // add civicrm_report_instance.name
@@ -792,7 +820,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` (
 
     $res = CRM_Core_DAO::singleValueQuery($sql);
 
-    if ($res <= 0 ) {
+    if ($res <= 0) {
       $sql = "ALTER TABLE civicrm_report_instance ADD `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'when combined with report_id/template uniquely identifies the instance'";
       $res = CRM_Core_DAO::executeQuery($sql);
     }
@@ -803,7 +831,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` (
 
     $res = CRM_Core_DAO::singleValueQuery($sql);
 
-    if ($res <= 0 ) {
+    if ($res <= 0) {
       $sql = "ALTER TABLE civicrm_report_instance ADD `args` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'arguments that are passed in the url when invoking the instance'";
 
       $res = CRM_Core_DAO::executeQuery($sql);
@@ -814,7 +842,8 @@ CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` (
 
   /**
    * @param array $params
-   * @return bool TRUE if $params is valid
+   * @return bool
+   *   TRUE if $params is valid
    */
   public static function isValidWordReplacement($params) {
     $result = strlen($params['find_word']) <= self::MAX_WORD_REPLACEMENT_SIZE && strlen($params['replace_word']) <= self::MAX_WORD_REPLACEMENT_SIZE;
@@ -823,4 +852,5 @@ CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` (
     }
     return $result;
   }
+
 }