Exemplo n.º 1
0
 /**
  * Compute any messages which should be displayed beforeupgrade.
  *
  * Note: This function is called iteratively for each upcoming
  * revision to the database.
  *
  * @param $preUpgradeMessage
  * @param string $rev
  *   a version number, e.g. '4.2.alpha1', '4.2.beta3', '4.2.0'.
  * @param null $currentVer
  *
  * @return void
  */
 public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL)
 {
     if ($rev == '4.2.alpha1') {
         $tables = array('civicrm_contribution_page', 'civicrm_event', 'civicrm_group', 'civicrm_contact');
         if (!CRM_Core_DAO::schemaRequiresRebuilding($tables)) {
             $errors = ts("The upgrade has identified some schema integrity issues in the database. It seems some of your constraints are missing. You will have to rebuild your schema before re-trying the upgrade. Please refer to %1.", array(1 => CRM_Utils_System::docURL2("Ensuring Schema Integrity on Upgrades", FALSE, "Ensuring Schema Integrity on Upgrades", NULL, NULL, "wiki")));
             CRM_Core_Error::fatal($errors);
             return FALSE;
         }
         // CRM-10613, CRM-11120
         $query = "\nSELECT mp.contribution_id, mp.membership_id, mem.membership_type_id, mem.start_date, mem.end_date, mem.status_id, mem.contact_id\nFROM civicrm_membership_payment mp\nINNER JOIN ( SELECT cmp.contribution_id\n              FROM civicrm_membership_payment cmp\n              LEFT JOIN civicrm_line_item cli ON cmp.contribution_id=cli.entity_id and cli.entity_table = 'civicrm_contribution'\n              WHERE cli.entity_id IS NULL\n              GROUP BY cmp.contribution_id\n              HAVING COUNT(cmp.membership_id) > 1) submp ON submp.contribution_id = mp.contribution_id\nINNER JOIN civicrm_membership mem ON mem.id = mp.membership_id\nORDER BY mp.contribution_id, mp.membership_id";
         $invalidData = CRM_Core_DAO::executeQuery($query);
         if ($invalidData->N) {
             $invalidDataMessage = "<br /><strong>" . ts('The upgrade is being aborted due to data integrity issues in your database. There are multiple membership records linked to the same contribution record. This is unexpected, and some of the membership records may be duplicates. The problem record sets are listed below. Refer to <a href="%1">this wiki page for instructions on repairing your database</a> so that you can run the upgrade successfully.
     ', array(1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC42/Repair+database+script+for+4.2+upgrades')) . "</strong>";
             $membershipType = CRM_Member_PseudoConstant::membershipType();
             $membershipStatus = CRM_Member_PseudoConstant::membershipStatus();
             $invalidDataMessage .= "<table border=1><tr><th>Contact-ID</th><th>Contribution-ID</th><th>Membership-ID</th><th>Membership Type</th><th>Start Date</th><th>End Date</th><th>Membership Status</th></tr>";
             while ($invalidData->fetch()) {
                 $invalidDataMessage .= "<tr>";
                 $invalidDataMessage .= "<td>{$invalidData->contact_id}</td>";
                 $invalidDataMessage .= "<td>{$invalidData->contribution_id}</td>";
                 $invalidDataMessage .= "<td>{$invalidData->membership_id}</td>";
                 $invalidDataMessage .= "<td>" . CRM_Utils_Array::value($invalidData->membership_type_id, $membershipType) . "</td>";
                 $invalidDataMessage .= "<td>{$invalidData->start_date}</td>";
                 $invalidDataMessage .= "<td>{$invalidData->end_date}</td>";
                 $invalidDataMessage .= "<td>" . CRM_Utils_Array::value($invalidData->status_id, $membershipStatus) . "</td>";
                 $invalidDataMessage .= "</tr>";
             }
             $invalidDataMessage .= "</table><p>" . ts('If you have reviewed the cleanup script documentation on the wiki and you are ready to run the cleanup now - <a href="%1">click here</a>.', array(1 => CRM_Utils_System::url('civicrm/upgrade/cleanup425', 'reset=1'))) . "</p>";
             CRM_Core_Error::fatal($invalidDataMessage);
             return FALSE;
         }
     }
     if ($rev == '4.2.beta2') {
         // note: error conditions are also checked in upgrade_4_2_beta2()
         if (!defined('CIVICRM_SETTINGS_PATH')) {
             $preUpgradeMessage .= '<br />' . ts('Could not determine path to civicrm.settings.php. Please manually locate it and add these lines at the bottom: <pre>%1</pre>', array(1 => self::SETTINGS_SNIPPET));
         } elseif (preg_match(self::SETTINGS_SNIPPET_PATTERN, file_get_contents(CIVICRM_SETTINGS_PATH))) {
             // OK, nothing to do
         } elseif (!is_writable(CIVICRM_SETTINGS_PATH)) {
             $preUpgradeMessage .= '<br />' . ts('The settings file (%1) must be updated. Please make it writable or manually add these lines:<pre>%2</pre>', array(1 => CIVICRM_SETTINGS_PATH, 2 => self::SETTINGS_SNIPPET));
         }
     }
     if ($rev == '4.2.2' && version_compare($currentVer, '3.3.alpha1') >= 0) {
         $query = " SELECT cli.id\nFROM `civicrm_line_item` cli\nINNER JOIN civicrm_membership_payment cmp ON cmp.contribution_id = cli.entity_id AND cli.entity_table = 'civicrm_contribution'\nINNER JOIN civicrm_price_field_value cpfv ON cpfv.id = cli.price_field_value_id\nINNER JOIN civicrm_price_field cpf ON cpf.id = cpfv.price_field_id and cpf.id != cli.price_field_id\nINNER JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id AND cps.name <>'default_membership_type_amount' ";
         $dao = CRM_Core_DAO::executeQuery($query);
         if ($dao->N) {
             $preUpgradeMessage .= "<br /><strong>" . ts('We have identified extraneous data in your database that a previous upgrade likely introduced. We STRONGLY recommend making a backup of your site before continuing. We also STRONGLY suggest fixing this issue with unneeded records BEFORE you upgrade. You can find more information about this issue and the way to fix it by visiting <a href="http://forum.civicrm.org/index.php/topic,26181.0.html">http://forum.civicrm.org/index.php/topic,26181.0.html</a>.') . "</strong>";
         }
     }
     if (version_compare($rev, '4.2.9') >= 0) {
         //CRM-11980
         $sql = "SELECT id FROM civicrm_option_group WHERE name LIKE 'civicrm_price_field.amount.%' LIMIT 1";
         $dao = CRM_Core_DAO::executeQuery($sql);
         if ($dao->fetch()) {
             $errors = ts("We found unexpected data values from an older version of CiviCRM in your database. The upgrade can not be run until this condition is corrected.<br /><br />Details: One or more rows are present in the civicrm_option_group with name like 'civicrm_price_field.amount.%'. <a href='%1'>Check here for information on diagnosing and correcting this problem.</a>", array(1 => 'http://forum.civicrm.org/index.php/topic,27744.msg118748.html#msg118748'));
             CRM_Core_Error::fatal($errors);
             return FALSE;
         }
     }
 }