Odyssey
2019102100_updXDITrustedMaster.php
1 <?php
2 /**
3  * Notes:
4  * 1. Anything complicated needs to be done with SQL.
5  * 2. Always have a check to know if the migration needs to occur (up or down).
6  * 3. Use up() and down(), not change(), because of the SQL
7  */
8 use Phinx\Migration\AbstractMigration;
9 
10 /**
11  * Updates trusted master to include testers for DMI
12  */
13 class updXDITrustedMaster extends AbstractMigration {
14 
15  /** @var string */
16  protected $trusted_table = "cutrustedmaster";
17  /** @var array - use in part for updates, completely for insert */
18  protected $trusted_default = [
19  'trustedid' => 'XPRESS_SSO',
20  'trustedvendor' => 'Xpress Data',
21  'trustedtype' => 'E',
22  'hcuinterface' => '',
23  'trustedfields' => [
24  'testMode' => [
25  'Type' => 'digits',
26  'Default' => '1',
27  'Message' => '1=test 0=production'
28  ],
29  'testappKey' => [
30  'Type' => 'string',
31  'Default' => 'AppId',
32  'Message' => 'Issued by XDI'
33  ],
34  'testappValue' => [
35  'Type' => 'string',
36  'Default' => 'xdi',
37  'Message' => 'use xdi for SSO'
38  ],
39  'testtokenURL' => [
40  'Type' => 'string',
41  'Default' => 'https://exstokenserver.xdi.com/DISCOVERYFCUTokenServer/TokenServer.asmx',
42  'Message' => 'eXpressServices token server URL issued by XDI'
43  ],
44  'prodappKey' => [
45  'Type' => 'string',
46  'Default' => 'AppId',
47  'Message' => 'Issued by XDI'
48  ],
49  'prodappValue' => [
50  'Type' => 'string',
51  'Default' => 'xdi',
52  'Message' => 'use xdi for SSO'
53  ],
54  'prodtokenURL' => [
55  'Type' => 'string',
56  'Default' => 'https://exstokenserver.xdi.com/DISCOVERYFCUTokenServer/TokenServer.asmx',
57  'Message' => 'eXpressServices token server URL issued by XDI'
58  ],
59  'hcuLogging' => [
60  'Type' => 'string',
61  'Default' => '',
62  'Message' => '-1 to log all or csv list to log specified or blank/0 no logging'
63  ]
64  ]
65  ];
66 
67  /**
68  * See if row defined above exists in trusted master.
69  * If so, update it to force the content defined above
70  *
71  * Since trustedid is unique key to table, counting on only one entry
72  * @return void
73  */
74  public function up() {
75 
76  if ($this->hasTable($this->trusted_table)) {
77 
78  $def = $this->trusted_default;
79  $sql = "select * from {$this->trusted_table} where trustedid = '{$def['trustedid']}'";
80 
81  # note appears that fetchRow always returns count of 1, even if no row is found.
82  # using fetchAll even though I expect max 1 record (trustedid is unique key)
83 
84  $trusted_row = $this->fetchAll($sql);
85 
86  if (count($trusted_row) > 0) {
87  $sql = "update {$this->trusted_table} set trustedfields = E'"
88  . json_encode($def['trustedfields'])
89  . "' where trustedid = '{$def['trustedid']}'";
90 
91  echo " updating {$def['trustedid']} trusted master\n";
92  $this->query($sql);
93 
94  } else {
95 
96  $sql = "insert into {$this->trusted_table} (trustedid, trustedvendor, trustedtype, hcuinterface, trustedfields)"
97  . " values('{$def['trustedid']}', '{$def['trustedvendor']}', '{$def['trustedtype']}',"
98  . " E'{$def['hcuinterface']}', E'" . json_encode($def['trustedfields']) . "')";
99 
100  echo " inserting {$def['trustedid']} trusted master\n";
101  $this->query($sql);
102  }
103  }
104  }
105  /**
106  * No Down
107  * @return void
108  */
109  public function down() {
110  }
111 }
112 
113 ?>