コード例 #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.3.alpha1', '4.3.beta3', '4.3.0'.
  * @param null $currentVer
  *
  * @return void|bool
  */
 public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL)
 {
     if ($rev == '4.3.beta3') {
         //CRM-12084
         //sql for checking orphaned contribution records
         $sql = "SELECT COUNT(ct.id) FROM civicrm_contribution ct LEFT JOIN civicrm_contact c ON ct.contact_id = c.id WHERE c.id IS NULL";
         $count = CRM_Core_DAO::singleValueQuery($sql, array(), TRUE, FALSE);
         if ($count > 0) {
             $error = ts("There is a data integrity issue with this CiviCRM database. It contains %1 contribution records which are linked to contact records that have been deleted. You will need to correct this manually before you can run the upgrade. Use the following MySQL query to identify the problem records: %2 These records will need to be deleted or linked to an existing contact record.", array(1 => $count, 2 => '<em>SELECT ct.* FROM civicrm_contribution ct LEFT JOIN civicrm_contact c ON ct.contact_id = c.id WHERE c.id IS NULL;</em>'));
             CRM_Core_Error::fatal($error);
             return FALSE;
         }
     }
     if ($rev == '4.3.beta4' && CRM_Utils_Constant::value('CIVICRM_UF', FALSE) == 'Drupal6') {
         // CRM-11823 - Make sure the D6 HTML HEAD technique will work on
         // upgrade pages ... except when we're in Drush.
         if (!function_exists('drush_main')) {
             theme('item_list', array());
             // force-load theme registry
             $theme_registry = theme_get_registry();
             if (!isset($theme_registry['page']['preprocess functions']) || FALSE === array_search('civicrm_preprocess_page_inject', $theme_registry['page']['preprocess functions'])) {
                 CRM_Core_Error::fatal('Please reset the Drupal cache (Administer => Site Configuration => Performance => Clear cached data))');
             }
         }
     }
     if ($rev == '4.3.6') {
         $constraintArray = array('civicrm_contact' => 'contact_id', 'civicrm_payment_processor' => 'payment_processor_id');
         if (version_compare('4.1alpha1', $currentVer) <= 0) {
             $constraintArray['civicrm_campaign'] = 'campaign_id';
         }
         if (version_compare('4.3alpha1', $currentVer) <= 0) {
             $constraintArray['civicrm_financial_type'] = 'financial_type_id';
         }
         foreach ($constraintArray as $key => $value) {
             $query = "SELECT contri_recur.id FROM civicrm_contribution_recur contri_recur LEFT JOIN {$key} ON contri_recur.{$value} = {$key}.id\nWHERE {$key}.id IS NULL";
             if ($value != 'contact_id') {
                 $query .= " AND contri_recur.{$value} IS NOT NULL ";
             }
             $dao = CRM_Core_DAO::executeQuery($query);
             if ($dao->N) {
                 $invalidDataMessage = '<strong>Oops, it looks like you have orphaned recurring contribution records in your database. Before this upgrade can complete they will need to be fixed or deleted. <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Fixing+Orphaned+Contribution+Recur+Records" target="_blank">You can review steps to correct this situation on the documentation wiki.</a></strong>';
                 CRM_Core_Error::fatal($invalidDataMessage);
                 return FALSE;
             }
         }
     }
 }
コード例 #2
0
ファイル: DAO.php プロジェクト: konadave/civicrm-core
 /**
  * Initialize the DAO object.
  *
  * @param string $dsn
  *   The database connection string.
  */
 public static function init($dsn)
 {
     Civi::$statics[__CLASS__]['init'] = 1;
     $options =& PEAR::getStaticProperty('DB_DataObject', 'options');
     $options['database'] = $dsn;
     if (defined('CIVICRM_DAO_DEBUG')) {
         self::DebugLevel(CIVICRM_DAO_DEBUG);
     }
     CRM_Core_DAO::setFactory(new CRM_Contact_DAO_Factory());
     if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) {
         CRM_Core_DAO::executeQuery('SET SESSION sql_mode = STRICT_TRANS_TABLES');
     }
     CRM_Core_DAO::executeQuery('SET NAMES utf8');
 }
コード例 #3
0
ファイル: File.php プロジェクト: routinet/civicrm-core
 /**
  * @param $dsn
  * @param string $fileName
  * @param null $prefix
  * @param bool $isQueryString
  * @param bool $dieOnErrors
  */
 public static function sourceSQLFile($dsn, $fileName, $prefix = NULL, $isQueryString = FALSE, $dieOnErrors = TRUE)
 {
     require_once 'DB.php';
     $db = DB::connect($dsn);
     if (PEAR::isError($db)) {
         die("Cannot open {$dsn}: " . $db->getMessage());
     }
     if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) {
         $db->query('SET SESSION sql_mode = STRICT_TRANS_TABLES');
     }
     if (!$isQueryString) {
         $string = $prefix . file_get_contents($fileName);
     } else {
         // use filename as query string
         $string = $prefix . $fileName;
     }
     // get rid of comments starting with # and --
     $string = preg_replace("/^#[^\n]*\$/m", "\n", $string);
     $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
     $queries = preg_split('/;\\s*$/m', $string);
     foreach ($queries as $query) {
         $query = trim($query);
         if (!empty($query)) {
             CRM_Core_Error::debug_query($query);
             $res =& $db->query($query);
             if (PEAR::isError($res)) {
                 if ($dieOnErrors) {
                     die("Cannot execute {$query}: " . $res->getMessage());
                 } else {
                     echo "Cannot execute {$query}: " . $res->getMessage() . "<p>";
                 }
             }
         }
     }
 }
コード例 #4
0
 /**
  * Initialize the DataObject framework.
  *
  * @return void
  */
 private function _initDAO()
 {
     CRM_Core_DAO::init($this->dsn);
     $factoryClass = $this->DAOFactoryClass;
     require_once str_replace('_', DIRECTORY_SEPARATOR, $factoryClass) . '.php';
     CRM_Core_DAO::setFactory(new $factoryClass());
     if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) {
         CRM_Core_DAO::executeQuery('SET SESSION sql_mode = STRICT_TRANS_TABLES');
     }
 }