Esempio n. 1
0
 private function sync_table($alias)
 {
     $table = Cms_Structure::factory($alias);
     if (!$table) {
         throw new Exception('Таблица ' . $alias . ' не найдена');
     }
     $old_columns = $table->get_columns();
     $default_column_config = Cms::get_default_column();
     $matching_rules = Cms::get_columns_matching_rules();
     $columns_data = Cms::get_dal_instance()->get_columns($table->get_table_name());
     $new_columns = $table->create_columns($columns_data, $matching_rules, $default_column_config)->get_columns();
     $result_columns = array();
     foreach ($columns_data as $col_name => $col_data) {
         if (array_key_exists($col_name, $old_columns)) {
             $result_columns[$col_name] = $old_columns[$col_name];
         } else {
             $result_columns[$col_name] = $new_columns[$col_name];
         }
     }
     $table->set_columns($result_columns)->save();
 }