Skip to content

Instantly share code, notes, and snippets.

@anzenehansen
Last active January 4, 2016 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anzenehansen/7d9b2121c1bdde36ae01 to your computer and use it in GitHub Desktop.
Save anzenehansen/7d9b2121c1bdde36ae01 to your computer and use it in GitHub Desktop.
<?php
class AdminManagePlugin extends AppController {
public function preAction(){
parent::preAction();
// Require login
$this->requireLogin();
$this->uses(array("Backup"));
$this->view->view = "default";
$this->orig_structure_view = $this->structure->view;
$this->structure->view = "default";
}
private function init(){
$this->view->setView(null, "DatabaseManager.default");
Loader::loadComponents($this, array("Record", "Input"));
$this->plugin_id = (isset($this->get[0]) ? $this->get[0] : null);
$this->vars = array('plugin_id' => $this->plugin_id);
}
public function index(){
$this->init();
$tables = $this->Record->query("SHOW TABLES")->fetchAll();
$this->vars['res'] = $tables;
return $this->partial("admin_manage_plugin", $this->vars);
}
public function backup(){
$this->init();
if(!isset($this->Backup)){
$this->vars['errors'] = $this->setMessage("error", "Backup component not loaded!", true, null, false);
return $this->partial("admin_manage_plugin", $this->vars);
}
$this->Backup->download();
if($errors = $this->Backup->errors()){
$this->vars['errors'] = $this->setMessage("error", $errors, true, null, false);
return $this->partial("admin_manage_plugin", $this->vars);
}
}
public function test(){
$this->init();
return $this->partial("admin_test");
}
public function purge(){
$this->init();
$tables = $this->Record->query("SHOW TABLES")->fetchAll();
foreach($tables as $index=>$tbl){
$this->Record->drop($tbl->tables_in_blesta);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment