Odyssey
2019040401_userHubPermissions.php
1 <?php
2 /* Notes:
3  * 1. Anything complicated needs to be done with SQL.
4  * 2. Always have a check to know if the migration needs to occur (up or down).
5  * 3. Use up() and down(), not change(), because of the SQL
6  */
7 use Phinx\Migration\AbstractMigration;
8 
9 /*
10  * Expanding checknumber column to 15 characters
11  */
12 class UserHubPermissions extends AbstractMigration {
13  public function up() {
14 
15  // Part 1: Change one User Hub permission into two: basic and advanced.
16  $tableName = "cuadminprogs";
17  if ($this->hasTable($tableName)) {
18  $sql = "update $tableName set description = 'Change or unlock user accounts and login authority.' where program = 'userSupport'";
19  $this->query($sql);
20 
21  $sql = "insert into $tableName (program, displaytext, description, sort_order, def_set)
22  values ('userSupportAdv', 'User Advanced Controls', 'Add/delete users, change account access, or financial limits.', 23, 1)";
23  $this->query($sql);
24  }
25 
26  // Part 2: Add advanced permissions to admin users that have the original permission.
27  $tableName = "cuadminallow";
28  if ($this->hasTable($tableName)) {
29  $sql = "insert into $tableName (cu, user_name, program)
30  select aa.cu, aa.user_name, 'userSupportAdv'
31  from $tableName aa
32  where aa.program = 'userSupport'";
33  $this->query($sql);
34  }
35 
36  }
37 
38  public function down() {
39 
40  // Part 1: Change User Hub permissions back
41  $tableName = "cuadminprogs";
42  if ($this->hasTable($tableName)) {
43  $sql = "update $tableName set description = 'Add, change, unlock, or delete user accounts and login authority.' where program = 'userSupport'";
44  $this->query($sql);
45 
46  $sql = "delete from $tableName where program = 'userSupportAdv'";
47  $this->query($sql);
48  }
49 
50  // Part 2: Remove advanced permissions
51  $tableName = "cuadminallow";
52  if ($this->hasTable($tableName)) {
53  $sql = "delete from $tableName where program = 'userSupportAdv'";
54  $this->query($sql);
55  }
56  }
57 }