 #
 # This file is part of the Anotatornia suite.
 # 
 # Copyright © 2007, 2008, 2009, 2010 by Instytut Podstaw Informatyki
 # Polskiej Akademii Nauk (IPI PAN; Institute of Computer Science, Polish
 # Academy of Sciences; cf. www.ipipan.waw.pl).  All rights reserved.
 # 
 # This file may be distributed and/or modified under the terms of the
 # GNU General Public License version 3 as published by the Free Software
 # Foundation and appearing in the file COPYING included in the packaging
 # of this file.  (See http://www.gnu.org/licenses/translations.html for
 # unofficial translations.)
 # 
 # A commercial license is available from IPI PAN (contact
 # Michal.Ciesiolka.waw.pl or ipi.waw.pl for more
 # information).  Licensees holding a valid commercial license from IPI
 # PAN may use this file in accordance with that license.
 # 
 # This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
 # THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 # PURPOSE.
 #

class RevertAutowsd < ActiveRecord::Migration

  extend MigrationHelper

  def self.up
# 2009/10/12 odkryłem potworną katastrofę, polegającą na tym, że po ms\dy zatwierdzeniu akapitu wsd zawsze zatwierdzały się same (bez anotacji). Dotknęło to prawie 2000 akatów.
    kill_anotatorniæ_if_8003_nobackup

    puts "\n" + Statusy.find_by_sql(  "select count(*) as ile from statusy where word_senses=16 and  exists (select interpretacja_id from interpretacja i inner join token tok using( token_id ) where i.cz_m_leksem_id is not null and  i.disamb='t' and  tok.akapit_id=statusy.akapit_id ) and not exists (select * from sens_anot where akapit_transzy_id=statusy.akapit_transzy_id);" )[0].ile + " trefnych.\n"

    execute "update statusy set word_senses=0, word_senses_uzid=null, updated_at=current_timestamp where word_senses=16 and  exists (select interpretacja_id from interpretacja i inner join token tok using( token_id ) where i.cz_m_leksem_id is not null and  i.disamb='t' and  tok.akapit_id=statusy.akapit_id ) and not exists (select * from sens_anot where akapit_transzy_id=statusy.akapit_transzy_id);"

    AkapitTranszy.find_by_sql( 
                              "select at.* from akapit_transzy at inner join statusy s using(akapit_transzy_id) where status>=16 and word_senses=0" ).
      each { |akat205| akat205.update_Status }

  end

  def self.down
  end
end
