| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License along with this program; if not, contact CiviCRM LLC | |
| 21 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 22 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 24 | +--------------------------------------------------------------------+ |
| 25 | */ |
| 26 | |
| 27 | /** |
| 28 | * Upgrade logic for 4.7 |
| 29 | */ |
| 30 | class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base { |
| 31 | |
| 32 | /** |
| 33 | * Compute any messages which should be displayed beforeupgrade. |
| 34 | * |
| 35 | * Note: This function is called iteratively for each upcoming |
| 36 | * revision to the database. |
| 37 | * |
| 38 | * @param $preUpgradeMessage |
| 39 | * @param string $rev |
| 40 | * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'. |
| 41 | * @param null $currentVer |
| 42 | * |
| 43 | * @return void |
| 44 | */ |
| 45 | public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { |
| 46 | if ($rev == '4.7.alpha1') { |
| 47 | |
| 48 | // CRM-16478 Remove custom fatal error template path option |
| 49 | $config = CRM_Core_Config::singleton(); |
| 50 | if (!empty($config->fatalErrorTemplate) && $config->fatalErrorTemplate != 'CRM/common/fatal.tpl') { |
| 51 | $preUpgradeMessage .= '<p>' . ts('The custom fatal error template setting will be removed during the upgrade. You are currently using this custom template: %1 . Following the upgrade you will need to use the standard approach to overriding template files, as described in the documentation.', array(1 => $config->fatalErrorTemplate)) . '</p>'; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Compute any messages which should be displayed after upgrade. |
| 58 | * |
| 59 | * @param string $postUpgradeMessage |
| 60 | * alterable. |
| 61 | * @param string $rev |
| 62 | * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs. |
| 63 | * @return void |
| 64 | */ |
| 65 | public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { |
| 66 | if ($rev == '4.7.alpha1') { |
| 67 | $config = CRM_Core_Config::singleton(); |
| 68 | // FIXME: Performing an upgrade step during postUpgrade message phase is probably bad |
| 69 | $editor_id = self::updateWysiwyg(); |
| 70 | $msg = NULL; |
| 71 | $ext_href = 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1') . '"'; |
| 72 | $dsp_href = 'href="' . CRM_Utils_System::url('civicrm/admin/setting/preferences/display', 'reset=1') . '"'; |
| 73 | $blog_href = 'href="https://civicrm.org/blogs/colemanw/big-changes-wysiwyg-editing-47"'; |
| 74 | switch ($editor_id) { |
| 75 | // TinyMCE |
| 76 | case 1: |
| 77 | $msg = ts('Your configured editor "TinyMCE" is no longer part of the main CiviCRM download. To continue using it, visit the <a %1>Manage Extensions</a> page to download and install the TinyMCE extension.', array(1 => $ext_href)); |
| 78 | break; |
| 79 | |
| 80 | // Drupal/Joomla editor |
| 81 | case 3: |
| 82 | case 4: |
| 83 | $msg = ts('CiviCRM no longer integrates with the "%1 Default Editor." Your wysiwyg setting has been reset to the built-in CKEditor. <a %2>Learn more...</a>', array(1 => $config->userFramework, 2 => $blog_href)); |
| 84 | break; |
| 85 | } |
| 86 | if ($msg) { |
| 87 | $postUpgradeMessage .= '<p>' . $msg . '</p>'; |
| 88 | } |
| 89 | $postUpgradeMessage .= '<p>' . ts('CiviCRM now includes the easy-to-use CKEditor Configurator. To customize the features and display of your wysiwyg editor, visit the <a %1>Display Preferences</a> page. <a %2>Learn more...</a>', array(1 => $dsp_href, 2 => $blog_href)) . '</p>'; |
| 90 | |
| 91 | $postUpgradeMessage .= '<br /><br />' . ts('Default version of the following System Workflow Message Templates have been modified: <ul><li>Personal Campaign Pages - Owner Notification</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).'); |
| 92 | |
| 93 | $postUpgradeMessage .= '<p>' . ts('The custom fatal error template setting has been removed.') . '</p>'; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Upgrade function. |
| 99 | * |
| 100 | * @param string $rev |
| 101 | */ |
| 102 | public function upgrade_4_7_alpha1($rev) { |
| 103 | $this->addTask(ts('Migrate \'on behalf of\' information to module_data'), 'migrateOnBehalfOfInfo'); |
| 104 | $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); |
| 105 | $this->addTask(ts('Add Getting Started dashlet to %1: SQL', array(1 => $rev)), 'addGettingStartedDashlet', $rev); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * CRM-16354 |
| 110 | * |
| 111 | * @return int |
| 112 | */ |
| 113 | public static function updateWysiwyg() { |
| 114 | $editorID = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id'); |
| 115 | // Previously a numeric value indicated one of 4 wysiwyg editors shipped in core, and no value indicated 'Textarea' |
| 116 | // Now the options are "Textarea", "CKEditor", and the rest have been dropped from core. |
| 117 | $newEditor = $editorID ? "CKEditor" : "Textarea"; |
| 118 | CRM_Core_BAO_Setting::setItem($newEditor, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id'); |
| 119 | |
| 120 | return $editorID; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Add Getting Started dashlet to dashboard |
| 125 | * |
| 126 | * @param \CRM_Queue_TaskContext $ctx |
| 127 | * |
| 128 | * @return bool |
| 129 | */ |
| 130 | public function addGettingStartedDashlet(CRM_Queue_TaskContext $ctx) { |
| 131 | $sql = "SELECT count(*) FROM civicrm_dashboard WHERE name='gettingStarted'"; |
| 132 | $res = CRM_Core_DAO::singleValueQuery($sql); |
| 133 | $domainId = CRM_Core_Config::domainID(); |
| 134 | if ($res <= 0) { |
| 135 | $sql = "INSERT INTO `civicrm_dashboard` |
| 136 | ( `domain_id`, `name`, `label`, `url`, `permission`, `permission_operator`, `column_no`, `is_minimized`, `is_active`, `weight`, `fullscreen_url`, `is_fullscreen`, `is_reserved`) VALUES ( {$domainId}, 'getting-started', 'Getting Started', 'civicrm/dashlet/getting-started?reset=1&snippet=5', 'access CiviCRM', NULL, 0, 0, 1, 0, 'civicrm/dashlet/getting-started?reset=1&snippet=5&context=dashletFullscreen', 1, 1)"; |
| 137 | CRM_Core_DAO::executeQuery($sql); |
| 138 | // Add default position for Getting Started Dashlet ( left column) |
| 139 | $sql = "INSERT INTO `civicrm_dashboard_contact` (dashboard_id, contact_id, column_no, is_active) |
| 140 | SELECT (SELECT MAX(id) FROM `civicrm_dashboard`), contact_id, 0, IF (SUM(is_active) > 0, 1, 0) |
| 141 | FROM `civicrm_dashboard_contact` WHERE 1 GROUP BY contact_id"; |
| 142 | CRM_Core_DAO::executeQuery($sql); |
| 143 | } |
| 144 | return TRUE; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Migrate on-behalf information to uf_join.module_data as on-behalf columns will be dropped |
| 149 | * on DB upgrade |
| 150 | * |
| 151 | * @param CRM_Queue_TaskContext $ctx |
| 152 | * |
| 153 | * @return bool |
| 154 | * TRUE for success |
| 155 | */ |
| 156 | public static function migrateOnBehalfOfInfo(CRM_Queue_TaskContext $ctx) { |
| 157 | |
| 158 | $ufGroupDAO = new CRM_Core_DAO_UFJoin(); |
| 159 | $ufGroupDAO->module = 'OnBehalf'; |
| 160 | $ufGroupDAO->find(TRUE); |
| 161 | |
| 162 | $query = "SELECT cp.*, uj.id as join_id |
| 163 | FROM civicrm_contribution_page cp |
| 164 | INNER JOIN civicrm_uf_join uj ON uj.entity_id = cp.id AND uj.module = 'OnBehalf'"; |
| 165 | $dao = CRM_Core_DAO::executeQuery($query); |
| 166 | |
| 167 | if ($dao->N) { |
| 168 | $domain = new CRM_Core_DAO_Domain(); |
| 169 | $domain->find(TRUE); |
| 170 | while ($dao->fetch()) { |
| 171 | $onBehalfParams['on_behalf'] = array('is_for_organization' => $dao->is_for_organization); |
| 172 | if ($domain->locales) { |
| 173 | $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); |
| 174 | foreach ($locales as $locale) { |
| 175 | $for_organization = "for_organization_{$locale}"; |
| 176 | $onBehalfParams['on_behalf'] += array( |
| 177 | $locale => array( |
| 178 | 'for_organization' => $dao->$for_organization, |
| 179 | ), |
| 180 | ); |
| 181 | } |
| 182 | } |
| 183 | else { |
| 184 | $onBehalfParams['on_behalf'] += array( |
| 185 | 'default' => array( |
| 186 | 'for_organization' => $dao->for_organization, |
| 187 | ), |
| 188 | ); |
| 189 | } |
| 190 | $ufJoinParam = array( |
| 191 | 'id' => $dao->join_id, |
| 192 | 'module' => 'on_behalf', |
| 193 | 'module_data' => json_encode($onBehalfParams), |
| 194 | ); |
| 195 | CRM_Core_BAO_UFJoin::create($ufJoinParam); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | return TRUE; |
| 200 | } |
| 201 | |
| 202 | } |