CRM-16860 - Enforce minimum upgradable version
[civicrm-core.git] / CRM / Upgrade / Incremental / php / FourSeven.php
CommitLineData
6cc25669
CW
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 *
29 * @package CRM
30 * @copyright CiviCRM LLC (c) 2004-2015
31 * $Id$
32 */
33class CRM_Upgrade_Incremental_php_FourSeven {
34 const BATCH_SIZE = 5000;
35
36 /**
37 * Verify DB state.
38 *
39 * @param $errors
40 *
41 * @return bool
42 */
43 public function verifyPreDBstate(&$errors) {
44 return TRUE;
45 }
46
47 /**
48 * Compute any messages which should be displayed before upgrade.
49 *
50 * Note: This function is called iteratively for each upcoming
51 * revision to the database.
52 *
53 * @param $preUpgradeMessage
54 * @param string $rev
55 * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'.
56 * @param null $currentVer
57 */
58 public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
59 }
60
61 /**
62 * Compute any messages which should be displayed after upgrade.
63 *
64 * @param string $postUpgradeMessage
65 * alterable.
66 * @param string $rev
67 * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
68 * @return void
69 */
70 public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
6dbe2c23
CW
71 if ($rev == '4.7.alpha1') {
72 $config = CRM_Core_Config::singleton();
73 $editor_id = self::updateWysiwyg();
74 $msg = NULL;
75 $ext_href = 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1') . '"';
76 $dsp_href = 'href="' . CRM_Utils_System::url('civicrm/admin/setting/preferences/display', 'reset=1') . '"';
77 $blog_href = 'href="https://civicrm.org/blogs/colemanw/big-changes-wysiwyg-editing-47"';
78 switch ($editor_id) {
79 // TinyMCE
80 case 1:
81 $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));
82 break;
83
84 // Drupal/Joomla editor
85 case 3:
86 case 4:
87 $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));
88 break;
89 }
90 if ($msg) {
91 $postUpgradeMessage .= '<p>' . $msg . '</p>';
92 }
93 $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>';
dd55005c 94
95 $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).');
6dbe2c23 96 }
6cc25669
CW
97 }
98
99
100 /**
101 * (Queue Task Callback)
102 */
103 public static function task_4_7_x_runSql(CRM_Queue_TaskContext $ctx, $rev) {
104 $upgrade = new CRM_Upgrade_Form();
105 $upgrade->processSQL($rev);
106
107 return TRUE;
108 }
109
110 /**
111 * Syntactic sugar for adding a task which (a) is in this class and (b) has
112 * a high priority.
113 *
114 * After passing the $funcName, you can also pass parameters that will go to
115 * the function. Note that all params must be serializable.
116 */
117 protected function addTask($title, $funcName) {
118 $queue = CRM_Queue_Service::singleton()->load(array(
119 'type' => 'Sql',
120 'name' => CRM_Upgrade_Form::QUEUE_NAME,
121 ));
122
123 $args = func_get_args();
124 $title = array_shift($args);
125 $funcName = array_shift($args);
126 $task = new CRM_Queue_Task(
127 array(get_class($this), $funcName),
128 $args,
129 $title
130 );
131 $queue->createItem($task, array('weight' => -1));
132 }
133
134 /**
135 * Upgrade function.
136 *
137 * @param string $rev
138 */
139 public function upgrade_4_7_alpha1($rev) {
6dbe2c23 140 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'task_4_7_x_runSql', $rev);
6cc25669
CW
141 }
142
143 /**
144 * CRM-16354
145 *
6dbe2c23 146 * @return int
6cc25669 147 */
6dbe2c23 148 public static function updateWysiwyg() {
6cc25669 149 $editorID = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id');
6dbe2c23
CW
150 // Previously a numeric value indicated one of 4 wysiwyg editors shipped in core, and no value indicated 'Textarea'
151 // Now the options are "Textarea", "CKEditor", and the rest have been dropped from core.
152 $newEditor = $editorID ? "CKEditor" : "Textarea";
153 CRM_Core_BAO_Setting::setItem($newEditor, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id');
6cc25669 154
6dbe2c23 155 return $editorID;
6cc25669
CW
156 }
157
158}