Odyssey
2017113000_combineusersupport.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 class CombineUserSupport extends AbstractMigration {
10 
11  /*
12  * remove the column "stale" from account and loan balance tables
13  */
14  public function up() {
15 
16  $hasTableCUA = $this->hasTable("cuadminallow");
17  $hasTableCUP = $this->hasTable("cuadminprogs");
18 
19  if ($hasTableCUA) {
20  // update cuadmin allow: any users with access to addchange and not usersupport
21  // set access to user support.
22  $sqlSub = "
23  SELECT sua.cu, sua.user_name, sua.program FROM cuadminallow sua
24  WHERE LOWER(program)='usersupport'
25  AND sua.user_name=cua.user_name";
26  $sql = "
27  INSERT INTO cuadminallow (
28  SELECT DISTINCT ON (cua.user_name) cua.cu, cua.user_name, 'userSupport'
29  FROM cuadminallow cua
30  WHERE LOWER(program) IN ('addchange', 'usermfa')
31  AND NOT EXISTS ($sqlSub))";
32  $this->query($sql);
33 
34  // delete usermfa, addchange from cuadminallow
35  $sql = "
36  DELETE FROM cuadminallow
37  WHERE LOWER(program) IN ('addchange', 'usermfa')";
38  $this->query($sql);
39  }
40 
41  if ($hasTableCUP) {
42  // update cuadminprogs, change displaytext of usersupport
43  // change displaytext to User Management Screens
44  $sql = "
45  UPDATE cuadminprogs SET displaytext='User Management Screens'
46  WHERE LOWER(program)='usersupport'";
47  $this->query($sql);
48 
49  // delete usermfa, addchange from cuadminprogs
50  $sql = "
51  DELETE FROM cuadminprogs
52  WHERE LOWER(program) IN ('addchange', 'usermfa')";
53  $this->query($sql);
54  }
55  }
56 
57  /* To execute this you need to run the following command:
58  * php vendor/bin/phinx rollback (using correct path to phinx)
59  * Or, to roll back to a specific time:
60  * php vendor/bin/phinx rollback -t 20151123211207
61  */
62  public function down() {
63 
64  }
65 }
66 
67 ?>