CRM-16354 - Improve wysiwyg upgrade & add message to user
[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>';
94 }
6cc25669
CW
95 }
96
97
98 /**
99 * (Queue Task Callback)
100 */
101 public static function task_4_7_x_runSql(CRM_Queue_TaskContext $ctx, $rev) {
102 $upgrade = new CRM_Upgrade_Form();
103 $upgrade->processSQL($rev);
104
105 return TRUE;
106 }
107
108 /**
109 * Syntactic sugar for adding a task which (a) is in this class and (b) has
110 * a high priority.
111 *
112 * After passing the $funcName, you can also pass parameters that will go to
113 * the function. Note that all params must be serializable.
114 */
115 protected function addTask($title, $funcName) {
116 $queue = CRM_Queue_Service::singleton()->load(array(
117 'type' => 'Sql',
118 'name' => CRM_Upgrade_Form::QUEUE_NAME,
119 ));
120
121 $args = func_get_args();
122 $title = array_shift($args);
123 $funcName = array_shift($args);
124 $task = new CRM_Queue_Task(
125 array(get_class($this), $funcName),
126 $args,
127 $title
128 );
129 $queue->createItem($task, array('weight' => -1));
130 }
131
132 /**
133 * Upgrade function.
134 *
135 * @param string $rev
136 */
137 public function upgrade_4_7_alpha1($rev) {
6dbe2c23 138 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'task_4_7_x_runSql', $rev);
6cc25669
CW
139 }
140
141 /**
142 * CRM-16354
143 *
6dbe2c23 144 * @return int
6cc25669 145 */
6dbe2c23 146 public static function updateWysiwyg() {
6cc25669 147 $editorID = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id');
6dbe2c23
CW
148 // Previously a numeric value indicated one of 4 wysiwyg editors shipped in core, and no value indicated 'Textarea'
149 // Now the options are "Textarea", "CKEditor", and the rest have been dropped from core.
150 $newEditor = $editorID ? "CKEditor" : "Textarea";
151 CRM_Core_BAO_Setting::setItem($newEditor, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id');
6cc25669 152
6dbe2c23 153 return $editorID;
6cc25669
CW
154 }
155
156}