Пример #1
0
 public function preProcess()
 {
     $version = CRM_Core_BAO_Domain::version();
     if (version_compare($version, '4.5', '<')) {
         $this->use_old_contact_ref_fields = true;
     }
     parent::preProcess();
     // TODO: Change the autogenerated stub
 }
 public static function formRule($params)
 {
     $currentVer = CRM_Core_BAO_Domain::version(TRUE);
     $errors = array();
     if (version_compare($currentVer, '4.4') < 0) {
         $errors['version_error'] = " You need to upgrade to version 4.4 or above to work with extension Mailchimp";
     }
     return empty($errors) ? TRUE : $errors;
 }
 private function invoke($fnSuffix, $numParams, &$arg1 = null, &$arg2 = null, &$arg3 = null, &$arg4 = null, &$arg5 = null)
 {
     $hook = CRM_Utils_Hook::singleton();
     $civiVersion = CRM_Core_BAO_Domain::version();
     if (version_compare('4.4', $civiVersion, '<=')) {
         //in CiviCRM 4.4 the invoke function has 5 arguments maximum
         return $hook->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $fnSuffix);
     }
     //in CiviCRM 4.5 and later the invoke function has 6 arguments
     return $hook->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, null, $fnSuffix);
 }
Пример #4
0
 function run()
 {
     // lets get around the time limit issue if possible for upgrades
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
     $latestVer = CRM_Utils_System::version();
     $currentVer = CRM_Core_BAO_Domain::version();
     if (!$currentVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm database.'));
     } else {
         if (stripos($currentVer, 'upgrade')) {
             CRM_Core_Error::fatal(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.'));
         }
     }
     if (!$latestVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm codebase.'));
     }
     // hack to make past ver compatible /w new incremental upgrade process
     $convertVer = array('2.1' => '2.1.0', '2.2' => '2.2.alpha1', '2.2.alph' => '2.2.alpha3', '3.1.0' => '3.1.1');
     if (isset($convertVer[$currentVer])) {
         $currentVer = $convertVer[$currentVer];
     }
     // since version is suppose to be in valid format at this point, especially after conversion ($convertVer),
     // lets do a pattern check -
     if (!CRM_Utils_System::isVersionFormatValid($currentVer)) {
         CRM_Core_Error::fatal(ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.'));
     }
     // This could be removed in later rev
     if ($currentVer == '2.1.6') {
         $config =& CRM_Core_Config::singleton();
         // also cleanup the templates_c directory
         $config->cleanup(1, false);
         if ($config->userFramework !== 'Standalone') {
             // clean the session
             $session =& CRM_Core_Session::singleton();
             $session->reset(2);
         }
     }
     // end of hack
     CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $upgrade =& new CRM_Upgrade_Form();
     $template =& CRM_Core_Smarty::singleton();
     $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $template->assign('menuRebuildURL', CRM_Utils_System::url('civicrm/menu/rebuild', 'reset=1'));
     $template->assign('cancelURL', CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
     if (version_compare($currentVer, $latestVer) > 0) {
         // DB version number is higher than codebase being upgraded to. This is unexpected condition-fatal error.
         $dbToolsLink = CRM_Utils_System::docURL2("Database Troubleshooting Tools", true);
         $error = ts('Your database is marked with an unexpected version number: %1. The automated upgrade to version %2 can not be run - and the %2 codebase may not be compatible with your database state. You will need to determine the correct version corresponding to your current database state. The database tools utility at %3 may be helpful. You may want to revert to the codebase you were using prior to beginning this upgrade until you resolve this problem.', array(1 => $currentVer, 2 => $latestVer, 3 => $dbToolsLink));
         CRM_Core_Error::fatal($error);
     } else {
         if (version_compare($currentVer, $latestVer) == 0) {
             $message = ts('Your database has already been upgraded to CiviCRM %1', array(1 => $latestVer));
             $template->assign('upgraded', true);
         } else {
             $message = ts('CiviCRM upgrade was successful.');
             $template->assign('currentVersion', $currentVer);
             $template->assign('newVersion', $latestVer);
             $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2', array(1 => $currentVer, 2 => $latestVer)));
             $template->assign('upgraded', false);
             if (CRM_Utils_Array::value('upgrade', $_POST)) {
                 $revisions = $upgrade->getRevisionSequence();
                 foreach ($revisions as $rev) {
                     // proceed only if $currentVer < $rev
                     if (version_compare($currentVer, $rev) < 0) {
                         // as soon as we start doing anything we append ".upgrade" to version.
                         // this also helps detect any partial upgrade issues
                         $upgrade->setVersion($rev . '.upgrade');
                         $phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev);
                         if (is_callable(array($this, $phpFunctionName))) {
                             eval("\$this->{$phpFunctionName}('{$rev}');");
                         } else {
                             $upgrade->processSQL($rev);
                         }
                         // after an successful intermediate upgrade, set the complete version
                         $upgrade->setVersion($rev);
                     }
                 }
                 $upgrade->setVersion($latestVer);
                 $template->assign('upgraded', true);
                 // also cleanup the templates_c directory
                 $config =& CRM_Core_Config::singleton();
                 $config->cleanup(1, false);
                 // clear db caching
                 $config->clearDBCache();
                 // clean the session. Note: In case of standalone this makes the user logout.
                 // So skip this step for standalone.
                 if ($config->userFramework !== 'Standalone') {
                     $session =& CRM_Core_Session::singleton();
                     $session->reset(2);
                 }
             }
         }
     }
     $template->assign('message', $message);
     $content = $template->fetch('CRM/common/success.tpl');
     echo CRM_Utils_System::theme('page', $content, true, $this->_print, false, true);
 }
 /**
  * Process the form submission.
  */
 function postProcess()
 {
     $formValues = $this->exportValues();
     $buttonName = $this->controller->getButtonName();
     if ($buttonName == $this->_testButtonName) {
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
         list($toDisplayName, $toEmail, $toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID);
         //get the default domain email address.CRM-4250
         list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
         if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
             $fixUrl = CRM_Utils_System::url("civicrm/admin/domain", 'action=update&reset=1');
             CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl)));
         }
         if (!$toEmail) {
             CRM_Core_Error::statusBounce(ts('Cannot send a test email because your user record does not have a valid email address.'));
         }
         if (!trim($toDisplayName)) {
             $toDisplayName = $toEmail;
         }
         $testMailStatusMsg = ts('Sending test email. FROM: %1 TO: %2.<br />', array(1 => $domainEmailAddress, 2 => $toEmail));
         $params = array();
         $message = "SMTP settings are correct.";
         $params['host'] = $formValues['smtpServer'];
         $params['port'] = $formValues['smtpPort'];
         if ($formValues['smtpAuth']) {
             $params['username'] = $formValues['smtpUsername'];
             $params['password'] = $formValues['smtpPassword'];
             $params['auth'] = TRUE;
         } else {
             $params['auth'] = FALSE;
         }
         // set the localhost value, CRM-3153, CRM-9332
         $params['localhost'] = $_SERVER['SERVER_NAME'];
         // also set the timeout value, lets set it to 30 seconds
         // CRM-7510, CRM-9332
         $params['timeout'] = 30;
         $mailerName = 'smtp';
         $headers = array('From' => '"' . $domainEmailName . '" <' . $domainEmailAddress . '>', 'To' => '"' . $toDisplayName . '"' . "<{$toEmail}>", 'Subject' => "Test for SMTP settings");
         $mailer = Mail::factory($mailerName, $params);
         $config = CRM_Core_Config::singleton();
         if (property_exists($config, 'civiVersion')) {
             $civiVersion = $config->civiVersion;
         } else {
             $civiVersion = CRM_Core_BAO_Domain::version();
         }
         if (version_compare('4.5alpha1', $civiVersion) > 0) {
             CRM_Core_Error::ignoreException();
         } else {
             $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
         }
         $result = $mailer->send($toEmail, $headers, $message);
         if (version_compare('4.5alpha1', $civiVersion) > 0) {
             CRM_Core_Error::setCallback();
         } else {
             unset($errorScope);
         }
         if (!is_a($result, 'PEAR_Error')) {
             CRM_Core_Session::setStatus($testMailStatusMsg . ts('Your %1 settings are correct. A test email has been sent to your email address.', array(1 => strtoupper($mailerName))), ts("Mail Sent"), "success");
         } else {
             $message = CRM_Utils_Mail::errorMessage($mailer, $result);
             CRM_Core_Session::setStatus($testMailStatusMsg . ts('Oops. Your %1 settings are incorrect. No test mail has been sent.', array(1 => strtoupper($mailerName))) . $message, ts("Mail Not Sent"), "error");
         }
     }
     // if password is present, encrypt it
     if (!empty($formValues['smtpPassword'])) {
         $formValues['smtpPassword'] = CRM_Utils_Crypt::encrypt($formValues['smtpPassword']);
     }
     CRM_Core_BAO_Setting::setItem($formValues, CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mandrill_smtp_settings');
 }
Пример #6
0
 static function isDBVersionValid(&$errorMessage)
 {
     require_once 'CRM/Core/BAO/Domain.php';
     $dbVersion = CRM_Core_BAO_Domain::version();
     if (!$dbVersion) {
         // if db.ver missing
         $errorMessage = ts('Version information found to be missing in database. You will need to determine the correct version corresponding to your current database state.');
         return false;
     } else {
         if (!CRM_Utils_System::isVersionFormatValid($dbVersion)) {
             $errorMessage = ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.');
             return false;
         } else {
             if (stripos($dbVersion, 'upgrade')) {
                 // if db.ver indicates a partially upgraded db
                 $upgradeUrl = CRM_Utils_System::url("civicrm/upgrade", "reset=1");
                 $errorMessage = ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the <a href=\'%1\'>upgrade process</a> again.', array(1 => $upgradeUrl));
                 return false;
             } else {
                 $codeVersion = CRM_Utils_System::version();
                 // if db.ver < code.ver, time to upgrade
                 if (version_compare($dbVersion, $codeVersion) < 0) {
                     $upgradeUrl = CRM_Utils_System::url("civicrm/upgrade", "reset=1");
                     $errorMessage = ts('New codebase version detected. You might want to visit <a href=\'%1\'>upgrade screen</a> to upgrade the database.', array(1 => $upgradeUrl));
                     return false;
                 }
                 // if db.ver > code.ver, sth really wrong
                 if (version_compare($dbVersion, $codeVersion) > 0) {
                     $errorMessage = ts('Your database is marked with an unexpected version number: %1. The v%2 codebase may not be compatible with your database state. You will need to determine the correct version corresponding to your current database state. You may want to revert to the codebase you were using until you resolve this problem.', array(1 => $dbVersion, 2 => $codeVersion));
                     $errorMessage .= "<p>" . ts('OR if this is an svn install, you might want to fix version.txt file.') . "</p>";
                     return false;
                 }
             }
         }
     }
     // FIXME: there should be another check to make sure version is in valid format - X.Y.alpha_num
     return true;
 }
Пример #7
0
 static function triggerInfo(&$info, $tableName = NULL)
 {
     // get the current supported locales
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     if (empty($domain->locales)) {
         return;
     }
     $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
     $locale = array_pop($locales);
     // CRM-10027
     if (count($locales) == 0) {
         return;
     }
     $currentVer = CRM_Core_BAO_Domain::version(TRUE);
     if ($currentVer && CRM_Core_Config::isUpgradeMode()) {
         // take exact version so that proper schema structure file in invoked
         $latest = self::getLatestSchema($currentVer);
         require_once "CRM/Core/I18n/SchemaStructure_{$latest}.php";
         $class = "CRM_Core_I18n_SchemaStructure_{$latest}";
     } else {
         $class = 'CRM_Core_I18n_SchemaStructure';
     }
     $columns =& $class::columns();
     foreach ($columns as $table => $hash) {
         if ($tableName && $tableName != $table) {
             continue;
         }
         $trigger = array();
         foreach ($hash as $column => $_) {
             $trigger[] = "IF NEW.{$column}_{$locale} IS NOT NULL THEN";
             foreach ($locales as $old) {
                 $trigger[] = "IF NEW.{$column}_{$old} IS NULL THEN SET NEW.{$column}_{$old} = NEW.{$column}_{$locale}; END IF;";
             }
             foreach ($locales as $old) {
                 $trigger[] = "ELSEIF NEW.{$column}_{$old} IS NOT NULL THEN";
                 foreach (array_merge($locales, array($locale)) as $loc) {
                     if ($loc == $old) {
                         continue;
                     }
                     $trigger[] = "IF NEW.{$column}_{$loc} IS NULL THEN SET NEW.{$column}_{$loc} = NEW.{$column}_{$old}; END IF;";
                 }
             }
             $trigger[] = 'END IF;';
         }
         $sql = implode(' ', $trigger);
         $info[] = array('table' => array($table), 'when' => 'BEFORE', 'event' => array('UPDATE'), 'sql' => $sql);
     }
     // take care of the ON INSERT triggers
     foreach ($columns as $table => $hash) {
         $trigger = array();
         foreach ($hash as $column => $_) {
             $trigger[] = "IF NEW.{$column}_{$locale} IS NOT NULL THEN";
             foreach ($locales as $old) {
                 $trigger[] = "SET NEW.{$column}_{$old} = NEW.{$column}_{$locale};";
             }
             foreach ($locales as $old) {
                 $trigger[] = "ELSEIF NEW.{$column}_{$old} IS NOT NULL THEN";
                 foreach (array_merge($locales, array($locale)) as $loc) {
                     if ($loc == $old) {
                         continue;
                     }
                     $trigger[] = "SET NEW.{$column}_{$loc} = NEW.{$column}_{$old};";
                 }
             }
             $trigger[] = 'END IF;';
         }
         $sql = implode(' ', $trigger);
         $info[] = array('table' => array($table), 'when' => 'BEFORE', 'event' => array('INSERT'), 'sql' => $sql);
     }
 }
Пример #8
0
 /**
  * Checks if CiviCRM database version is up-to-date
  * @return array
  */
 public function checkDbVersion()
 {
     $messages = array();
     $dbVersion = CRM_Core_BAO_Domain::version();
     $upgradeUrl = CRM_Utils_System::url("civicrm/upgrade", "reset=1");
     if (!$dbVersion) {
         // if db.ver missing
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Version information found to be missing in database. You will need to determine the correct version corresponding to your current database state.'), ts('Database Version Missing'), \Psr\Log\LogLevel::ERROR, 'fa-database');
     } elseif (!CRM_Utils_System::isVersionFormatValid($dbVersion)) {
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.'), ts('Database Version Invalid'), \Psr\Log\LogLevel::ERROR, 'fa-database');
     } elseif (stripos($dbVersion, 'upgrade')) {
         // if db.ver indicates a partially upgraded db
         $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Database check failed - the database looks to have been partially upgraded. You must reload the database with the backup and try the <a href=\'%1\'>upgrade process</a> again.', array(1 => $upgradeUrl)), ts('Database Partially Upgraded'), \Psr\Log\LogLevel::ALERT, 'fa-database');
     } else {
         $codeVersion = CRM_Utils_System::version();
         // if db.ver < code.ver, time to upgrade
         if (version_compare($dbVersion, $codeVersion) < 0) {
             $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('New codebase version detected. You must visit <a href=\'%1\'>upgrade screen</a> to upgrade the database.', array(1 => $upgradeUrl)), ts('Database Upgrade Required'), \Psr\Log\LogLevel::ALERT, 'fa-database');
         }
         // if db.ver > code.ver, sth really wrong
         if (version_compare($dbVersion, $codeVersion) > 0) {
             $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('Your database is marked with an unexpected version number: %1. The v%2 codebase may not be compatible with your database state.
         You will need to determine the correct version corresponding to your current database state. You may want to revert to the codebase
         you were using until you resolve this problem.<br/>OR if this is a manual install from git, you might want to fix civicrm-version.php file.', array(1 => $dbVersion, 2 => $codeVersion)), ts('Database In Unexpected Version'), \Psr\Log\LogLevel::ERROR, 'fa-database');
         }
     }
     return $messages;
 }
 static function retrieveDirectoryAndURLPreferences(&$params, $setInConfig = FALSE)
 {
     if ($setInConfig) {
         $config = CRM_Core_Config::singleton();
     }
     $isJoomla = defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla' ? TRUE : FALSE;
     if (CRM_Core_Config::isUpgradeMode() && !$isJoomla) {
         $currentVer = CRM_Core_BAO_Domain::version();
         if (version_compare($currentVer, '4.1.alpha1') < 0) {
             return;
         }
     }
     $sql = "\nSELECT name, group_name, value\nFROM   civicrm_setting\nWHERE  ( group_name = %1\nOR       group_name = %2 )\nAND domain_id = %3\n";
     $sqlParams = array(1 => array(self::DIRECTORY_PREFERENCES_NAME, 'String'), 2 => array(self::URL_PREFERENCES_NAME, 'String'), 3 => array(CRM_Core_Config::domainID(), 'Integer'));
     $dao = CRM_Core_DAO::executeQuery($sql, $sqlParams, TRUE, NULL, FALSE, TRUE, TRUE);
     if (is_a($dao, 'DB_Error')) {
         if (CRM_Core_Config::isUpgradeMode()) {
             // seems like this is a 4.0 -> 4.1 upgrade, so we suppress this error and continue
             // hack to set the resource base url so that js/ css etc is loaded correctly
             if ($isJoomla) {
                 $params['userFrameworkResourceURL'] = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/') . str_replace('administrator', '', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'userFrameworkResourceURL', 'value', 'name'));
             }
             return;
         } else {
             echo "Fatal DB error, exiting, seems like your schema does not have civicrm_setting table\n";
             exit;
         }
     }
     while ($dao->fetch()) {
         $value = self::getOverride($dao->group_name, $dao->name, NULL);
         if ($value === NULL && $dao->value) {
             $value = unserialize($dao->value);
             if ($dao->group_name == self::DIRECTORY_PREFERENCES_NAME) {
                 $value = CRM_Utils_File::absoluteDirectory($value);
             } else {
                 // CRM-7622: we need to remove the language part
                 $value = CRM_Utils_System::absoluteURL($value, TRUE);
             }
         }
         // CRM-10931, If DB doesn't have any value, carry on with any default value thats already available
         if (!isset($value) && CRM_Utils_Array::value($dao->name, $params)) {
             $value = $params[$dao->name];
         }
         $params[$dao->name] = $value;
         if ($setInConfig) {
             $config->{$dao->name} = $value;
         }
     }
 }
Пример #10
0
 /**
  * Get a list of triggers for the contact table.
  *
  * @see hook_civicrm_triggerInfo
  * @see CRM_Core_DAO::triggerRebuild
  * @see http://issues.civicrm.org/jira/browse/CRM-10554
  *
  * @param $info
  * @param null $tableName
  */
 public static function triggerInfo(&$info, $tableName = NULL)
 {
     //during upgrade, first check for valid version and then create triggers
     //i.e the columns created_date and modified_date are introduced in 4.3.alpha1 so dont create triggers for older version
     if (CRM_Core_Config::isUpgradeMode()) {
         $currentVer = CRM_Core_BAO_Domain::version(TRUE);
         //if current version is less than 4.3.alpha1 dont create below triggers
         if (version_compare($currentVer, '4.3.alpha1') < 0) {
             return;
         }
     }
     // Update timestamp for civicrm_contact itself
     if ($tableName == NULL || $tableName == self::getTableName()) {
         $info[] = array('table' => array(self::getTableName()), 'when' => 'BEFORE', 'event' => array('INSERT'), 'sql' => "\nSET NEW.created_date = CURRENT_TIMESTAMP;\n");
     }
     // Update timestamp when modifying closely related core tables
     $relatedTables = array('civicrm_address', 'civicrm_email', 'civicrm_im', 'civicrm_phone', 'civicrm_website');
     self::generateTimestampTriggers($info, $tableName, $relatedTables, 'contact_id');
     // Update timestamp when modifying related custom-data tables
     $customGroupTables = array();
     $customGroupDAO = CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity('Contact');
     $customGroupDAO->is_multiple = 0;
     $customGroupDAO->find();
     while ($customGroupDAO->fetch()) {
         $customGroupTables[] = $customGroupDAO->table_name;
     }
     if (!empty($customGroupTables)) {
         self::generateTimestampTriggers($info, $tableName, $customGroupTables, 'entity_id');
     }
     // Update phone table to populate phone_numeric field
     if (!$tableName || $tableName == 'civicrm_phone') {
         // Define stored sql function needed for phones
         CRM_Core_DAO::executeQuery(self::DROP_STRIP_FUNCTION_43);
         CRM_Core_DAO::executeQuery(self::CREATE_STRIP_FUNCTION_43);
         $info[] = array('table' => array('civicrm_phone'), 'when' => 'BEFORE', 'event' => array('INSERT', 'UPDATE'), 'sql' => "\nSET NEW.phone_numeric = civicrm_strip_non_numeric(NEW.phone);\n");
     }
 }
Пример #11
0
 /**
  * This function acts as a listener to dao->delete, and deletes an entry from recurring_entity table
  *
  * @param object $event
  *   An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just deleted .
  *
  *
  * @return void
  */
 public static function triggerDelete($event)
 {
     $obj =& $event->object;
     // if DB version is earlier than 4.6 skip any processing
     static $currentVer = NULL;
     if (!$currentVer) {
         $currentVer = CRM_Core_BAO_Domain::version();
     }
     if (version_compare($currentVer, '4.6.alpha1') < 0) {
         return;
     }
     static $processedEntities = array();
     if (empty($obj->id) || empty($obj->__table) || !$event->result) {
         return FALSE;
     }
     $key = "{$obj->__table}_{$obj->id}";
     if (array_key_exists($key, $processedEntities)) {
         // already processed
         return NULL;
     }
     // mark being processed
     $processedEntities[$key] = 1;
     $parentID = self::getParentFor($obj->id, $obj->__table);
     if ($parentID) {
         CRM_Core_BAO_RecurringEntity::delEntity($obj->id, $obj->__table, TRUE);
     }
 }
Пример #12
0
 /**
  * Determine the start and end version of the upgrade process.
  *
  * @return array(0=>$currentVer, 1=>$latestVer)
  */
 public function getUpgradeVersions()
 {
     $latestVer = CRM_Utils_System::version();
     $currentVer = CRM_Core_BAO_Domain::version(TRUE);
     if (!$currentVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm database.'));
     } elseif (stripos($currentVer, 'upgrade')) {
         CRM_Core_Error::fatal(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.'));
     }
     if (!$latestVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm codebase.'));
     }
     return array($currentVer, $latestVer);
 }
Пример #13
0
 /**
  * Determine the start and end version of the upgrade process
  *
  * @return array(0=>$currentVer, 1=>$latestVer)
  */
 function getUpgradeVersions()
 {
     $latestVer = CRM_Utils_System::version();
     $currentVer = CRM_Core_BAO_Domain::version(true);
     if (!$currentVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm database.'));
     } elseif (stripos($currentVer, 'upgrade')) {
         CRM_Core_Error::fatal(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.'));
     }
     if (!$latestVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm codebase.'));
     }
     // hack to make past ver compatible /w new incremental upgrade process
     $convertVer = array('2.1' => '2.1.0', '2.2' => '2.2.alpha1', '2.2.alph' => '2.2.alpha3', '3.1.0' => '3.1.1');
     if (isset($convertVer[$currentVer])) {
         $currentVer = $convertVer[$currentVer];
     }
     return array($currentVer, $latestVer);
 }
function mosaico_civicrm_pageRun(&$page)
{
    $pageName = $page->getVar('_name');
    if ($pageName == 'Civi\\Angular\\Page\\Main') {
        CRM_Core_Resources::singleton()->addScriptFile('uk.co.vedaconsulting.mosaico', 'js/crmMailingCustom.js', 800);
    }
    if ($pageName == 'CRM_Admin_Page_MessageTemplates') {
        $activeTab = CRM_Utils_Request::retrieve('activeTab', 'String', $form, false, null, 'REQUEST');
        $resultArray = array();
        $smarty = CRM_Core_Smarty::singleton();
        $tableName = MOSAICO_TABLE_NAME;
        $dao = CRM_Core_DAO::executeQuery("SELECT mosaico.*, cmt.msg_title, cmt.msg_subject, cmt.is_active \n      FROM {$tableName} mosaico \n      JOIN civicrm_msg_template cmt ON (cmt.id = mosaico.msg_tpl_id)\n    ");
        while ($dao->fetch()) {
            $resultArray[$dao->id] = $dao->toArray();
            $editURL = CRM_Utils_System::url('civicrm/mosaico/editor', 'snippet=2', FALSE, $dao->hash_key);
            $delURL = CRM_Utils_System::url('civicrm/admin/messageTemplates', 'action=delete&id=' . $dao->msg_tpl_id);
            $enableDisableText = $dao->is_active ? 'Disable' : 'Enable';
            $action = sprintf('<span>
      <a href="%s" class="action-item crm-hover-button" title="Edit this message template" >Edit</a>
      <a href="#" class="action-item crm-hover-button crm-enable-disable" title="Disable this message template" >%s</a>
      <a href="%s" class="action-item crm-hover-button small-popup" title="Delete this message template" >Delete</a>
      <a href="#" class="action-item crm-hover-button copy-template" value = "%s" title="Copy this message template">Copy</a>
      </span>', $editURL, $enableDisableText, $delURL, $dao->msg_tpl_id);
            $resultArray[$dao->id]['action'] = $action;
        }
        $smarty->assign('mosaicoTemplates', $resultArray);
        $smarty->assign('selectedChild', $activeTab);
        // From civi 4.7, no more tinymce, so if only civi version is less than 4.7 show tinymce.
        //https://civicrm.org/blog/colemanw/big-changes-to-wysiwyg-editing-in-47
        $showTinymceTpl = FALSE;
        $currentVer = CRM_Core_BAO_Domain::version(TRUE);
        if (version_compare($currentVer, '4.7') < 0) {
            $showTinymceTpl = TRUE;
        }
        $smarty->assign('showTinymceTpl', $showTinymceTpl);
    }
}
Пример #15
0
/**
 * Implementation of hook_civicrm_uninstall
 */
function mte_civicrm_uninstall()
{
    mte_enableDisableNavigationMenu(2);
    // Change enum for name in civicrm_mailing_bounce_type to remove all Mandrill bounce types
    $config = CRM_Core_Config::singleton();
    if (property_exists($config, 'civiVersion')) {
        $civiVersion = $config->civiVersion;
    } else {
        $civiVersion = CRM_Core_BAO_Domain::version();
    }
    if (version_compare('4.5alpha1', $civiVersion) > 0) {
        CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_mailing_bounce_type` \n  CHANGE `name` `name` ENUM( 'AOL', 'Away', 'DNS', 'Host', 'Inactive', 'Invalid', 'Loop', 'Quota', 'Relay', 'Spam', 'Syntax', 'Unknown' ) \n    CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'Type of bounce';");
    }
    return _mte_civix_civicrm_uninstall();
}
Пример #16
0
 public static function processMandrillCalls($reponse)
 {
     $events = array('open', 'click', 'hard_bounce', 'soft_bounce', 'spam', 'reject');
     $bounceType = array();
     //MTE-17
     $config = CRM_Core_Config::singleton();
     if (property_exists($config, 'civiVersion')) {
         $civiVersion = $config->civiVersion;
     } else {
         $civiVersion = CRM_Core_BAO_Domain::version();
     }
     if (version_compare('4.4alpha1', $civiVersion) > 0) {
         $jobCLassName = 'CRM_Mailing_DAO_Job';
     } else {
         $jobCLassName = 'CRM_Mailing_DAO_MailingJob';
     }
     foreach ($reponse as $value) {
         //changes done to check if email exists in response array
         if (in_array($value['event'], $events) && CRM_Utils_Array::value('email', $value['msg'])) {
             $metaData = CRM_Utils_Array::value('metadata', $value['msg']) ? CRM_Utils_Array::value('CiviCRM_Mandrill_id', $value['msg']['metadata']) : NULL;
             $header = self::extractHeader($metaData);
             $mail = self::getMailing($header, $jobCLassName);
             $contacts = array();
             if ($mail->find(TRUE)) {
                 if ($value['event'] == 'click' && $mail->url_tracking === FALSE || $value['event'] == 'open' && $mail->open_tracking === FALSE) {
                     continue;
                 }
                 $emails = self::retrieveEmailContactId($value['msg']['email']);
                 if (!CRM_Utils_Array::value('contact_id', $emails['email'])) {
                     continue;
                 }
                 $value['mailing_id'] = $mail->id;
                 // IF no activity id in header then create new activity
                 if (empty($header[0])) {
                     self::createActivity($value, NULL, $header);
                 }
                 if (empty($header[2])) {
                     $params = array('job_id' => CRM_Core_DAO::getFieldValue($jobCLassName, $mail->id, 'id', 'mailing_id'), 'contact_id' => $emails['email']['contact_id'], 'email_id' => $emails['email']['id']);
                     $eventQueue = CRM_Mailing_Event_BAO_Queue::create($params);
                     $eventQueueID = $eventQueue->id;
                     $hash = $eventQueue->hash;
                     $jobId = $params['job_id'];
                 } else {
                     $eventQueueID = $header[3];
                     $hash = explode('@', $header[4]);
                     $hash = $hash[0];
                     $jobId = $header[2];
                 }
                 if ($eventQueueID) {
                     $mandrillActivtyParams = array('mailing_queue_id' => $eventQueueID, 'activity_id' => $header[0]);
                     CRM_Mte_BAO_MandrillActivity::create($mandrillActivtyParams);
                 }
                 $msgBody = '';
                 if (!empty($header[0])) {
                     $msgBody = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $header[0], 'details');
                 }
                 $value['mail_body'] = $msgBody;
                 $bType = ucfirst(preg_replace('/_\\w+/', '', $value['event']));
                 $assignedContacts = array();
                 switch ($value['event']) {
                     case 'open':
                         $oe = new CRM_Mailing_Event_BAO_Opened();
                         $oe->event_queue_id = $eventQueueID;
                         $oe->time_stamp = date('YmdHis', $value['ts']);
                         $oe->save();
                         break;
                     case 'click':
                         if (CRM_Utils_Array::value(1, $header) == 'b') {
                             break;
                         }
                         $tracker = new CRM_Mailing_BAO_TrackableURL();
                         $tracker->url = $value['url'];
                         $tracker->mailing_id = $mail->id;
                         if (!$tracker->find(TRUE)) {
                             $tracker->save();
                         }
                         $open = new CRM_Mailing_Event_BAO_TrackableURLOpen();
                         $open->event_queue_id = $eventQueueID;
                         $open->trackable_url_id = $tracker->id;
                         $open->time_stamp = date('YmdHis', $value['ts']);
                         $open->save();
                         break;
                     case 'hard_bounce':
                     case 'soft_bounce':
                     case 'spam':
                     case 'reject':
                         if (empty($bounceType)) {
                             CRM_Core_PseudoConstant::populate($bounceType, 'CRM_Mailing_DAO_BounceType', TRUE, 'id', NULL, NULL, NULL, 'name');
                         }
                         //Delete queue in delivered since this email is not successfull
                         $delivered = new CRM_Mailing_Event_BAO_Delivered();
                         $delivered->event_queue_id = $eventQueueID;
                         if ($delivered->find(TRUE)) {
                             $delivered->delete();
                         }
                         $bounceParams = array('time_stamp' => date('YmdHis', $value['ts']), 'event_queue_id' => $eventQueueID, 'bounce_type_id' => $bounceType["Mandrill {$bType}"], 'job_id' => $jobId, 'hash' => $hash);
                         $bounceParams['bounce_reason'] = CRM_Utils_Array::value('bounce_description', $value['msg']);
                         if (empty($bounceParams['bounce_reason'])) {
                             $bounceParams['bounce_reason'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_BounceType', $bounceType["Mandrill {$bType}"], 'description');
                         }
                         CRM_Mailing_Event_BAO_Bounce::create($bounceParams);
                         if (substr($value['event'], -7) == '_bounce') {
                             $mailingBackend = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mandrill_smtp_settings');
                             if (CRM_Utils_Array::value('group_id', $mailingBackend)) {
                                 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
                                 $mailBody = ts('The following email failed to be delivered due to a') . " {$bType} Bounce :</br>\nTo: {$value['msg']['email']} </br>\nFrom: {$value['msg']['sender']} </br>\nSubject: {$value['msg']['subject']}</br>\nMessage Body: {$msgBody}";
                                 $mailParams = array('groupName' => 'Mandrill bounce notification', 'from' => '"' . $domainEmailName . '" <' . $domainEmailAddress . '>', 'subject' => ts('Mandrill Bounce Notification'), 'text' => $mailBody, 'html' => $mailBody);
                                 $query = "SELECT ce.email, cc.sort_name, cgc.contact_id FROM civicrm_contact cc\nINNER JOIN civicrm_group_contact cgc ON cgc.contact_id = cc.id\nINNER JOIN civicrm_email ce ON ce.contact_id = cc.id\nWHERE cc.is_deleted = 0 AND cc.is_deceased = 0 AND cgc.group_id = {$mailingBackend['group_id']} AND ce.is_primary = 1 AND ce.email <> %1";
                                 $queryParam = array(1 => array($value['msg']['email'], 'String'));
                                 $dao = CRM_Core_DAO::executeQuery($query, $queryParam);
                                 while ($dao->fetch()) {
                                     $mailParams['toName'] = $dao->sort_name;
                                     $mailParams['toEmail'] = $dao->email;
                                     CRM_Utils_Mail::send($mailParams);
                                     $value['assignee_contact_id'][] = $dao->contact_id;
                                 }
                             }
                         }
                         $bType = 'Bounce';
                         break;
                 }
                 // create activity for click and open event
                 if ($value['event'] == 'open' || $value['event'] == 'click' || $bType == 'Bounce') {
                     self::createActivity($value, $bType, $header);
                 }
             }
         }
     }
 }
Пример #17
0
 function logVersion($version = null)
 {
     if (!$version) {
         $version = CRM_Core_BAO_Domain::version();
     }
     if ($version) {
         require_once 'CRM/Core/BAO/Log.php';
         $session =& CRM_Core_Session::singleton();
         $logParams = array('entity_table' => 'civicrm_domain', 'entity_id' => 1, 'data' => "version,{$version}", 'modified_date' => date('YmdHis'));
         CRM_Core_BAO_Log::add($logParams);
         return true;
     }
     return false;
 }
Пример #18
0
 function run()
 {
     // lets get around the time limit issue if possible for upgrades
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
     $latestVer = CRM_Utils_System::version();
     $currentVer = CRM_Core_BAO_Domain::version();
     if (!$currentVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm database.'));
     } else {
         if (stripos($currentVer, 'upgrade')) {
             CRM_Core_Error::fatal(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.'));
         }
     }
     if (!$latestVer) {
         CRM_Core_Error::fatal(ts('Version information missing in civicrm codebase.'));
     }
     // hack to make past ver compatible /w new incremental upgrade process
     $convertVer = array('2.1' => '2.1.0', '2.2' => '2.2.alpha1', '2.2.alph' => '2.2.alpha3', '3.1.0' => '3.1.1');
     if (isset($convertVer[$currentVer])) {
         $currentVer = $convertVer[$currentVer];
     }
     // since version is suppose to be in valid format at this point, especially after conversion ($convertVer),
     // lets do a pattern check -
     if (!CRM_Utils_System::isVersionFormatValid($currentVer)) {
         CRM_Core_Error::fatal(ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.'));
     }
     // This could be removed in later rev
     if ($currentVer == '2.1.6') {
         $config = CRM_Core_Config::singleton();
         // also cleanup the templates_c directory
         $config->cleanup(1, false);
         if ($config->userFramework !== 'Standalone') {
             // clean the session
             $session = CRM_Core_Session::singleton();
             $session->reset(2);
         }
     }
     // end of hack
     CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $upgrade = new CRM_Upgrade_Form();
     $template = CRM_Core_Smarty::singleton();
     $template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
     $template->assign('menuRebuildURL', CRM_Utils_System::url('civicrm/menu/rebuild', 'reset=1'));
     $template->assign('cancelURL', CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
     if (version_compare($currentVer, $latestVer) > 0) {
         // DB version number is higher than codebase being upgraded to. This is unexpected condition-fatal error.
         $dbToolsLink = CRM_Utils_System::docURL2("Database Troubleshooting Tools", true);
         $error = ts('Your database is marked with an unexpected version number: %1. The automated upgrade to version %2 can not be run - and the %2 codebase may not be compatible with your database state. You will need to determine the correct version corresponding to your current database state. The database tools utility at %3 may be helpful. You may want to revert to the codebase you were using prior to beginning this upgrade until you resolve this problem.', array(1 => $currentVer, 2 => $latestVer, 3 => $dbToolsLink));
         CRM_Core_Error::fatal($error);
     } else {
         if (version_compare($currentVer, $latestVer) == 0) {
             $message = ts('Your database has already been upgraded to CiviCRM %1', array(1 => $latestVer));
             $template->assign('upgraded', true);
         } else {
             $message = ts('CiviCRM upgrade was successful.');
             if ($latestVer == '3.2.alpha1') {
                 $message .= '<br />' . ts("We have reset the COUNTED flag to false for the event participant status 'Pending from incomplete transaction'. This change ensures that people who have a problem during registration can try again.");
             } else {
                 if ($latestVer == '3.2.beta3' && version_compare($currentVer, '3.1.alpha1') >= 0) {
                     require_once 'CRM/Contact/BAO/ContactType.php';
                     $subTypes = CRM_Contact_BAO_ContactType::subTypes();
                     if (is_array($subTypes) && !empty($subTypes)) {
                         $config = CRM_Core_Config::singleton();
                         $subTypeTemplates = array();
                         if (isset($config->customTemplateDir)) {
                             foreach ($subTypes as $key => $subTypeName) {
                                 $customContactSubTypeEdit = $config->customTemplateDir . "CRM/Contact/Form/Edit/" . $subTypeName . ".tpl";
                                 $customContactSubTypeView = $config->customTemplateDir . "CRM/Contact/Page/View/" . $subTypeName . ".tpl";
                                 if (file_exists($customContactSubTypeEdit) || file_exists($customContactSubTypeView)) {
                                     $subTypeTemplates[$subTypeName] = $subTypeName;
                                 }
                             }
                         }
                         foreach ($subTypes as $key => $subTypeName) {
                             $customContactSubTypeEdit = $config->templateDir . "CRM/Contact/Form/Edit/" . $subTypeName . ".tpl";
                             $customContactSubTypeView = $config->templateDir . "CRM/Contact/Page/View/" . $subTypeName . ".tpl";
                             if (file_exists($customContactSubTypeEdit) || file_exists($customContactSubTypeView)) {
                                 $subTypeTemplates[$subTypeName] = $subTypeName;
                             }
                         }
                         if (!empty($subTypeTemplates)) {
                             $subTypeTemplates = implode(',', $subTypeTemplates);
                             $message .= '<br />' . ts('You are using custom template for contact subtypes: %1.', array(1 => $subTypeTemplates)) . '<br />' . ts('You need to move these subtype templates to the SubType directory in %1 and %2 respectively.', array(1 => 'CRM/Contact/Form/Edit', 2 => 'CRM/Contact/Page/View'));
                         }
                     }
                 } else {
                     if ($latestVer == '3.2.beta4') {
                         $statuses = array('New', 'Current', 'Grace', 'Expired', 'Pending', 'Cancelled', 'Deceased');
                         $sql = "\nSELECT  count( id ) as statusCount \n  FROM  civicrm_membership_status \n WHERE  name IN ( '" . implode("' , '", $statuses) . "' ) ";
                         $count = CRM_Core_DAO::singleValueQuery($sql);
                         if ($count < count($statuses)) {
                             $message .= '<br />' . ts("One or more Membership Status Rules was disabled during the upgrade because it did not match a recognized status name. if custom membership status rules were added to this site - review the disabled statuses and re-enable any that are still needed (Administer > CiviMember > Membership Status Rules).");
                         }
                     }
                 }
             }
             $template->assign('currentVersion', $currentVer);
             $template->assign('newVersion', $latestVer);
             $template->assign('upgradeTitle', ts('Upgrade CiviCRM from v %1 To v %2', array(1 => $currentVer, 2 => $latestVer)));
             $template->assign('upgraded', false);
             if (CRM_Utils_Array::value('upgrade', $_POST)) {
                 $revisions = $upgrade->getRevisionSequence();
                 foreach ($revisions as $rev) {
                     // proceed only if $currentVer < $rev
                     if (version_compare($currentVer, $rev) < 0) {
                         // as soon as we start doing anything we append ".upgrade" to version.
                         // this also helps detect any partial upgrade issues
                         $upgrade->setVersion($rev . '.upgrade');
                         $phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev);
                         // follow old upgrade process for all version
                         // below 3.2.alpha1
                         if (version_compare($rev, '3.2.alpha1') < 0) {
                             if (is_callable(array($this, $phpFunctionName))) {
                                 eval("\$this->{$phpFunctionName}('{$rev}');");
                             } else {
                                 $upgrade->processSQL($rev);
                             }
                         } else {
                             // new upgrade process from version
                             // 3.2.alpha1
                             $versionObject = $upgrade->incrementalPhpObject($rev);
                             // predb check for major release.
                             if ($upgrade->checkVersionRelease($rev, 'alpha1')) {
                                 if (!is_callable(array($versionObject, 'verifyPreDBstate'))) {
                                     CRM_Core_Error::fatal("verifyPreDBstate method was not found for {$rev}");
                                 }
                                 $error = null;
                                 if (!$versionObject->verifyPreDBstate($error)) {
                                     if (!isset($error)) {
                                         $error = "post-condition failed for current upgrade for {$rev}";
                                     }
                                     CRM_Core_Error::fatal($error);
                                 }
                             }
                             if (is_callable(array($versionObject, $phpFunctionName))) {
                                 $versionObject->{$phpFunctionName}($rev);
                             } else {
                                 $upgrade->processSQL($rev);
                             }
                         }
                         // after an successful intermediate upgrade, set the complete version
                         $upgrade->setVersion($rev);
                     }
                 }
                 $upgrade->setVersion($latestVer);
                 $template->assign('upgraded', true);
                 // also cleanup the templates_c directory
                 $config = CRM_Core_Config::singleton();
                 $config->cleanup(1, false);
                 // clear db caching
                 $config->clearDBCache();
                 // clear temporary tables
                 $config->clearTempTables();
                 // clean the session. Note: In case of standalone this makes the user logout.
                 // So skip this step for standalone.
                 if ($config->userFramework !== 'Standalone') {
                     $session = CRM_Core_Session::singleton();
                     $session->reset(2);
                 }
             }
         }
     }
     $template->assign('message', $message);
     $content = $template->fetch('CRM/common/success.tpl');
     echo CRM_Utils_System::theme('page', $content, true, $this->_print, false, true);
 }
Пример #19
0
 /**
  * Civicrm_setting didn't exist before 4.1.alpha1 and this function helps taking decisions during upgrade
  *
  * @return bool
  */
 public static function isUpgradeFromPreFourOneAlpha1()
 {
     if (CRM_Core_Config::isUpgradeMode()) {
         $currentVer = CRM_Core_BAO_Domain::version();
         if (version_compare($currentVer, '4.1.alpha1') < 0) {
             return TRUE;
         }
     }
     return FALSE;
 }
Пример #20
0
 /**
  * Example: Run an external SQL script
  *
  * @return TRUE on success
  * @throws Exception
  */
 public function upgrade_4514()
 {
     $this->ctx->log->info('Applying update for version 1.5');
     $config = CRM_Core_Config::singleton();
     if (property_exists($config, 'civiVersion')) {
         $civiVersion = $config->civiVersion;
     } else {
         $civiVersion = CRM_Core_BAO_Domain::version();
     }
     if (!(version_compare('4.5alpha1', $civiVersion) > 0)) {
         CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_mailing_bounce_type` CHANGE `name` `name` VARCHAR( 24 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'Type of bounce'");
         $mandrillBounceType = array('Mandrill Har' => 'Mandrill Hard', 'Mandrill Sof' => 'Mandrill Soft', 'Mandrill Spa' => 'Mandrill Spam', 'Mandrill Rej' => 'Mandrill Reject');
         foreach ($mandrillBounceType as $errorType => $bounceType) {
             CRM_Core_DAO::executeQuery('UPDATE civicrm_mailing_bounce_type SET name = %2 WHERE name = %1', array(1 => array($errorType, 'String'), 2 => array($bounceType, 'String')));
         }
     }
     return TRUE;
 }