Odyssey
2019050100_AddBankingMenuCache.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 class AddBankingMenuCache extends AbstractMigration {
11  public function up() {
12  // get the list of credit unions
13  $cuList = $this->fetchAll('SELECT cu FROM cuadmin');
14  $columnName = "cachedmenu";
15 
16  foreach ($cuList as $cuRow) {
17  $cu = strtolower(trim($cuRow["cu"]));
18 
19  // check if we already made the change
20  $tableName = "{$cu}user";
21 
22  if ($this->hasTable($tableName)) {
23  $table = $this->table( $tableName );
24 
25  $hasColumn = $table->hasColumn($columnName);
26 
27  // test to see if change has already happened
28  if ( !$hasColumn ) {
29  // announce it
30  print "Upgrade {$tableName}.\n";
31 
32  // Add column
33  $this->query("alter table $tableName add column $columnName varchar");
34  }
35  }
36 
37  }
38  }
39 
40  public function down() {
41 
42  }
43 }