Odyssey
2019070300_ACHPermissions.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 ACHPermissions 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
19  set description = 'Allow the user to access the ACH screens but not do anything.', displaytext = 'ACH Basic'
20  where program = 'aACH'";
21  $this->query($sql);
22 
23  $sql = "insert into $tableName (program, displaytext, description, sort_order, def_set)
24  values ('aACHAdv', 'ACH Advanced', 'Allow the user to create/modify ACH files.', 65, 0)";
25  $this->query($sql);
26 
27  $sql = "update $tableName
28  set sort_order = 66
29  where program = 'AdmDeposits'";
30  $this->query($sql);
31  }
32 
33  // Part 2: Add advanced permissions to admin users that have the original permission.
34  $tableName = "cuadminallow";
35  if ($this->hasTable($tableName)) {
36  $sql = "insert into $tableName (cu, user_name, program)
37  select aa.cu, aa.user_name, 'aACHAdv'
38  from $tableName aa
39  where aa.program = 'aACH'";
40  $this->query($sql);
41  }
42 
43  }
44 
45  public function down() {
46 
47  // Part 1: Change User Hub permissions back
48  $tableName = "cuadminprogs";
49  if ($this->hasTable($tableName)) {
50  $sql = "update $tableName
51  set description = 'Allow the user to report and export user ACH transaction requests.', displaytext = 'ACH Export'
52  where program = 'aACH'";
53  $this->query($sql);
54 
55  $sql = "delete from $tableName where program = 'aACHAdv'";
56  $this->query($sql);
57 
58  $sql = "update $tableName
59  set sort_order = 65
60  where program = 'AdmDeposits'";
61  $this->query($sql);
62  }
63 
64  // Part 2: Remove advanced permissions
65  $tableName = "cuadminallow";
66  if ($this->hasTable($tableName)) {
67  $sql = "delete from $tableName where program = 'aACHAdv'";
68  $this->query($sql);
69  }
70  }
71 }