We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Terminate extension activation

Development and Programming

eurotrash's avatar
eurotrash
7 posts
14 years ago
eurotrash's avatar eurotrash

The extension I am writing requires at least one channel to exist before it will function properly. I want to prevent it from installing if this condition is not met.

I wrote the following code:

public function activate_extension()
 {
  // Setup custom settings in this array.
  $this->settings = array();
  
  $data = array(
   'class'  => __CLASS__,
   'method' => 'test',
   'settings' => serialize($this->settings),
   'version' => $this->version,
   'enabled' => 'y'
  );
  
  if($this->terminate_extension() ==TRUE)
  {

   $this->EE->db->insert('extensions', $data);
  
  }
  else
  {
   $this->EE->session->set_flashdata('message_failure','Extension not Installed. At least one layout view needs to be created.');
   
   return FALSE;  
  }
  
 }

It works correctly but the problem is with the extension page. Both the success and a failure message are displayed when only the failure message should be displayed.

Is there a way to turn off the success message, or do I need to figure out another way to handle this case? It would be easy to add this error message in the view file, but that seems kind of kludgy.

Thanks

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
14 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Did you try by setting a flag into constructor and checking it in IF condition instead of checking $this->terminate_extension()? Because constructor will set the flag whenever extension is being called.

       
eurotrash's avatar
eurotrash
7 posts
14 years ago
eurotrash's avatar eurotrash

Tried your idea, figure it would work but it still displays both the success and the error message. I think the notification might be “baked” in JS somewhere. Not really sure. Might need to poke around the code to figure this one out.

public function activate_extension()
 {
  // Setup custom settings in this array.
  $this->settings = array();
  
  $data = array(
   'class'  => __CLASS__,
   'method' => 'test',
   'settings' => serialize($this->settings),
   'version' => $this->version,
   'enabled' => $this->terminate_extension()  // retunrs 'y' or 'n'
  );
  
  //var_dump($data);
  
  if($this->terminate_extension() == 'y')
  {

   $this->EE->db->insert('extensions', $data);
  
  }
  else
  {
   $this->EE->session->set_flashdata('message_failure','Extension not Installed. At least one Publish Page Layout needs to be created.');
   
    
  } 
  
 }
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.