Example #1
0
 public static function reviseEStables()
 {
     global $ES_fields, $core_tables;
     $MDES = $core_tables['match_data_es'];
     $status = true;
     $dropped = $added = array();
     // Create tables if not existing:
     # This will create all the ES MV (and regular, though not needed) tables with the correct up-to-date fields.
     self::installMVs();
     # Create, if not exists, the match_data_es table.
     Table::createTableIfNotExists('match_data_es', $MDES);
     // Remove non-existing fields.
     $result = mysql_query("DESCRIBE match_data_es");
     $existingFields = array();
     while ($r = mysql_fetch_assoc($result)) {
         // Ignore relational fields.
         if (preg_match('/^f\\_/', $r['Field'])) {
             continue;
         }
         $existingFields[] = $r['Field'];
         if (!in_array($r['Field'], array_keys($ES_fields))) {
             $dropped[] = $r['Field'];
             $status &= mysql_query("ALTER TABLE match_data_es DROP {$r['Field']}");
         }
     }
     // Add new fields.
     foreach (array_diff(array_keys($ES_fields), $existingFields) as $newField) {
         $added[] = $newField;
         $status &= mysql_query("ALTER TABLE match_data_es ADD COLUMN {$newField} " . $ES_fields[$newField]['type']);
     }
     return array($status, $added, $dropped);
 }