Merge pull request #12855 from colemanw/dev/core#391
[civicrm-core.git] / CRM / Upgrade / Incremental / php / FiveThree.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 FiveThree */
29 class CRM_Upgrade_Incremental_php_FiveThree extends CRM_Upgrade_Incremental_Base {
30
31 /**
32 * Compute any messages which should be displayed beforeupgrade.
33 *
34 * Note: This function is called iteratively for each upcoming
35 * revision to the database.
36 *
37 * @param string $preUpgradeMessage
38 * @param string $rev
39 * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'.
40 * @param null $currentVer
41 */
42 public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
43 if ($rev == '5.3.0') {
44 $params = array(
45 1 => 'edit user-driven message templates',
46 2 => 'edit system workflow message templates',
47 3 => 'edit message templates',
48 );
49 $preUpgradeMessage .= '<p>' . ts('New granular permissions called %1 and %2 have been added for %3 permission. These permissions help to limit user access per template', $params) . '</p>';
50 }
51 // Example: Generate a pre-upgrade message.
52 // if ($rev == '5.12.34') {
53 // $preUpgradeMessage .= '<p>' . ts('A new permission, "%1", has been added. This permission is now used to control access to the Manage Tags screen.', array(1 => ts('manage tags'))) . '</p>';
54 // }
55 }
56
57 /**
58 * Compute any messages which should be displayed after upgrade.
59 *
60 * @param string $postUpgradeMessage
61 * alterable.
62 * @param string $rev
63 * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
64 */
65 public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
66 // Example: Generate a post-upgrade message.
67 // if ($rev == '5.12.34') {
68 // $postUpgradeMessage .= '<br /><br />' . ts("By default, CiviCRM now disables the ability to import directly from SQL. To use this feature, you must explicitly grant permission 'import SQL datasource'.");
69 // }
70 }
71
72 /**
73 * Upgrade function.
74 *
75 * @param string $rev
76 */
77 public function upgrade_5_3_alpha1($rev) {
78 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
79 $this->addTask('CRM-19948 - Add created_id column to civicrm_file', 'addFileCreatedIdColumn');
80 }
81
82 public static function addFileCreatedIdColumn(CRM_Queue_TaskContext $ctx) {
83 self::addColumn($ctx, 'civicrm_file', 'created_id', "int unsigned COMMENT 'FK to civicrm_contact, who uploaded this file'");
84
85 CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_file', 'FK_civicrm_file_created_id');
86
87 CRM_Core_DAO::executeQuery("
88 ALTER TABLE `civicrm_file`
89 ADD CONSTRAINT `FK_civicrm_file_created_id`
90 FOREIGN KEY (`created_id`)
91 REFERENCES `civicrm_contact`(`id`)
92 ON DELETE SET NULL
93 ON UPDATE CASCADE;
94 ");
95
96 return TRUE;
97 }
98
99 /*
100 * Important! All upgrade functions MUST add a 'runSql' task.
101 * Uncomment and use the following template for a new upgrade version
102 * (change the x in the function name):
103 */
104
105 // /**
106 // * Upgrade function.
107 // *
108 // * @param string $rev
109 // */
110 // public function upgrade_5_0_x($rev) {
111 // $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
112 // $this->addTask('Do the foo change', 'taskFoo', ...);
113 // // Additional tasks here...
114 // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
115 // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
116 // }
117
118 // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
119 // return TRUE;
120 // }
121
122 }