Odyssey
2019072500_updateTrustedMasterRDC.php
1 <?php
2 
3 /**
4  * Notes:
5  * 1. Anything complicated needs to be done with SQL.
6  * 2. Always have a check to know if the migration needs to occur (up or down).
7  * 3. Use up() and down(), not change(), because of the SQL
8  */
9 use Phinx\Migration\AbstractMigration;
10 
11 class UpdateTrustedMasterRDC extends AbstractMigration {
12 
13  public function up() {
14 
15  $hcuFwdList = ['Type' => 'string', 'Default' => '', 'Message' => '-1 to forward all OR csv list of member numbers to forward OR 0-empty-undefined no forwarding'];
16  $hcuFwdToVen = ['Type' => 'string', 'Default' => '', 'Message' => 'trustedID of forward-to vendor. Case and spelling matter'];
17 
18  $tableName = "cutrustedmaster";
19  $exists = $this->hasTable($tableName);
20 
21  if ($exists) {
22  $sql = "select trustedid, trustedfields from ${tableName} where trustedid like 'RDC%'";
23  $trustedMasterList = $this->fetchAll($sql);
24 
25  for ($i = 0; $i < count($trustedMasterList); $i++) {
26 
27  $trustedid = trim($trustedMasterList[$i]["trustedid"]);
28  $trustedfields = trim($trustedMasterList[$i]["trustedfields"]);
29  $trustedarr = json_decode($trustedfields, true);
30  $trustedarr['hcuFwdToVen'] = $hcuFwdToVen;
31  $trustedarr['hcuFwdList'] = $hcuFwdList;
32  $unpreppedDetailString = json_encode($trustedarr);
33  $detailsString = pg_escape_string($unpreppedDetailString);
34 
35  $sql = "update ${tableName} set trustedfields = '${detailsString}' where trustedid='${trustedid}'";
36  $this->query($sql);
37  }
38  }
39  }
40 
41  /* To execute this you need to run the following command:
42  * php vendor/bin/phinx rollback (using correct path to phinx)
43  */
44 
45  public function down() {
46 
47  }
48 
49 }
50 
51 ?>