function constructClasses()
 {
     App::import('Lib', 'Newsletter.NewsletterUpgrade');
     if (!empty($this->params['admin']) && $this->params['controller'] != 'newsletter_upgrade' && $this->params['action'] == 'admin_index' && NewsletterUpgrade::check()) {
         $this->redirect(array('plugin' => 'newsletter', 'controller' => 'newsletter_upgrade', 'action' => 'upgrade', 'admin' => true));
     }
     return parent::constructClasses();
 }
 function admin_upgrade()
 {
     clearCache(null, 'models');
     $sErrors = NewsletterUpgrade::check();
     if (!$sErrors) {
         $this->Session->setFlash(__d('newsletter', 'The database is valid', true));
         $this->redirect(array('plugin' => 'newsletter', 'controller' => 'newsletter', 'action' => 'index'));
     }
     //debug($sErrors);
     if (!empty($this->params['named']['start'])) {
         $error = array();
         $step = empty($this->params['named']['step']) ? 1 : $this->params['named']['step'];
         $res = NewsletterUpgrade::run($error);
         if ($res === 'break') {
             $this->redirect(array('start' => '1', 'step' => $step++));
         }
         if ($res === true) {
             $this->Session->setFlash(__d('newsletter', 'The database has been fixed', true));
             $this->redirect(array('plugin' => 'newsletter', 'controller' => 'newsletter', 'action' => 'index'));
         } else {
             $this->Session->setFlash(__d('newsletter', 'An error occurred', true) . ' :<ul><li>' . implode('</li><li>', $error) . '</li></ul>');
         }
         /*
         App::import('Lib', 'Newsletter.QueryUtil'); 
         if(!empty($sErrors['missing_table'])){
         	$this->_fix_missing_tables($sErrors,$error);
         }elseif(!empty($sErrors['field_mismatch'])){
         	if(in_array('NewsletterEmail.sendlist_id',$sErrors['field_mismatch']['fields'])){
         		$this->_fix_email_list_relation($sErrors,$error);
         	}
         	if(in_array('NewsletterSended.sendlist_id',$sErrors['field_mismatch']['fields'])){
         		$this->_fix_sended_tabled($sErrors,$error);
         	}
         	if(in_array('NewsletterSended.newsletter_variant_id',$sErrors['field_mismatch']['fields'])){
         		$this->_fix_sended_variant($sErrors,$error);
         	}
         	if(in_array('NewsletterSended.name',$sErrors['field_mismatch']['fields'])){
         		$this->_fix_sended_name($sErrors,$error);
         	}
         	clearCache(null, 'models');
         }
         if(!empty($error)){
         	$this->Session->setFlash(
         		__d('newsletter','An error occurred', true)
         		.' :<ul><li>'
         		.implode('</li><li>',$error)
         		.'</li></ul>'
         	);
         }else{
         	$this->Session->setFlash(__d('newsletter','The database has been fixed', true));
         	$this->redirect(array('plugin'=>'newsletter','controller'=>'newsletter','action'=>'index'));
         }
         */
     }
 }