Influence of phase transitions on the second harmonic generation in metal nanoparticles