Odyssey
2019050600_update_loan_permissions.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  * Updating loan account permissions to not allow external withdraws
11  */
12 class UpdateLoanPermissions extends AbstractMigration {
13  public function up() {
14 
15  /*
16  * Updating ext_withdraw
17  */
18  $cuList = $this->fetchAll('SELECT cu FROM cuadmin');
19  foreach ($cuList as $cuListItem) {
20  $cu = strtolower(trim($cuListItem['cu']));
21  $userAccountsTable = "{$cu}useraccounts";
22  if ($this->hasTable($userAccountsTable)) {
23  $sql = "update $userAccountsTable set ext_withdraw = 'false' where recordtype = 'L'";
24  $this->query($sql);
25  }
26  }
27 
28  }
29 
30  public function down() {
31 
32  /*
33  * Updating ext_withdraw
34  */
35  $cuList = $this->fetchAll('SELECT cu FROM cuadmin');
36  foreach ($cuList as $cuListItem) {
37  $cu = strtolower(trim($cuListItem['cu']));
38  $userAccountsTable = "{$cu}useraccounts";
39  if ($this->hasTable($userAccountsTable)) {
40  $sql = "update $userAccountsTable set ext_withdraw = 'true' where recordtype = 'L'";
41  $this->query($sql);
42  }
43  }
44  }
45 }