-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2 add backups option and database logging, adjust menu bar
- Loading branch information
Chris Dart
committed
Mar 8, 2020
1 parent
c16b821
commit 573c1d2
Showing
8 changed files
with
206 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php defined('BASEPATH') OR exit('No direct script access allowed'); | ||
class Backup extends MY_Controller{ | ||
|
||
|
||
function __construct(){ | ||
parent::__construct(); | ||
$this->load->model('logging_model','logging'); | ||
} | ||
|
||
function index(){ | ||
// Load the DB utility class | ||
$this->load->dbutil(); | ||
$dbs = $this->dbutil->list_databases(); | ||
// Backup your entire database and assign it to a variable | ||
$backup = $this->dbutil->backup(); | ||
$filename = sprintf('backup-%s.sql.gz',date('Y-m-d-H-i-s')); | ||
$path = sprintf('/tmp/'); | ||
$temp_file = $path . $filename; | ||
// Load the file helper and write the file to your server | ||
$this->load->helper('file'); | ||
write_file($temp_file, $backup); | ||
$this->logging->log('backup','success'); | ||
$this->session->set_flashdata('notice','Move the file backup file from your downloads folder to your backups folder.'); | ||
|
||
// Load the download helper and send the file to your desktop | ||
$this->load->helper('download'); | ||
force_download($filename, $backup); | ||
redirect('home'); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
class Update extends My_Controller { | ||
|
||
|
||
function __construct() { | ||
parent::__construct(); | ||
$this->load->model('Update_model', 'update'); | ||
} | ||
|
||
function index() { | ||
/*$updates = [ | ||
[ | ||
'id' => 1, | ||
'query' => 'CREATE TABLE `logging` CHANGE `id` `id` varchar(128) NOT NULL;', | ||
'description' => 'CI upgrade from 3.1.1 to 3.1.2', | ||
], | ||
]; | ||
$this->update->run_updates($updates);*/ | ||
redirect('home'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php defined('BASEPATH') OR exit('No direct script access allowed'); | ||
|
||
class Logging_Model extends MY_Model { | ||
|
||
var $event_type; | ||
|
||
var $event; | ||
|
||
var $timestamp; | ||
|
||
function __construct() { | ||
parent::__construct(); | ||
$this->install_table(); | ||
} | ||
|
||
function install_table() { | ||
$this->load->dbforge(); | ||
$fields = [ | ||
'id' => [ | ||
'type' => 'INT', | ||
'constraint' => 3, | ||
'unsigned' => TRUE, | ||
'auto_increment' => TRUE, | ||
], | ||
'event_type' => [ | ||
'type' => 'VARCHAR', | ||
'constraint' => 255, | ||
], | ||
'event' => [ | ||
'type' => 'text', | ||
'unsigned' => TRUE, | ||
], | ||
'timestamp' => [ | ||
'type' => 'timestamp', | ||
], | ||
]; | ||
$attr = ['engine' => 'InnoDB']; | ||
$this->dbforge->add_field($fields); | ||
$this->dbforge->add_key('id', TRUE); | ||
$this->dbforge->create_table('log', TRUE, $attr); | ||
} | ||
|
||
function get_latest($event_type) { | ||
$this->db->where("event_type", $event_type); | ||
$this->db->order_by("timestamp", "DESC"); | ||
$this->db->limit(1); | ||
$this->db->select("UNIX_TIMESTAMP(`timestamp`) as `unix_time`", FALSE); | ||
$this->db->select("log.*"); | ||
$this->db->from("log"); | ||
$result = $this->db->get()->row(); | ||
|
||
return $result; | ||
} | ||
|
||
|
||
function log($event_type, $event) { | ||
$tables = $this->db->list_tables(); | ||
var_dump($tables); | ||
/* $this->event_type = $event_type; | ||
$this->event = $event; | ||
$this->timestamp = date("Y-m-d H:i:s"); | ||
$this->db->insert("log", $this);*/ | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
|
||
class Update_model extends My_Model { | ||
|
||
|
||
function __construct() { | ||
parent::__construct(); | ||
$this->install_table(); | ||
} | ||
|
||
function install_table() { | ||
$this->load->dbforge(); | ||
$fields = [ | ||
'id' => [ | ||
'type' => 'INT', | ||
'constraint' => 9, | ||
'unsigned' => TRUE, | ||
], | ||
'description' => [ | ||
'type' => 'VARCHAR', | ||
'constraint' => 255, | ||
], | ||
'rec_modified' => [ | ||
'type' => 'timestamp', | ||
], | ||
]; | ||
$attr = ['engine' => 'InnoDB']; | ||
$this->dbforge->add_field($fields); | ||
$this->dbforge->add_key('id', TRUE); | ||
$this->dbforge->create_table('updates', TRUE, $attr); | ||
} | ||
|
||
/** | ||
* @param array $updates | ||
*/ | ||
function run_updates(array $updates) { | ||
foreach ($updates as $update) { | ||
$update = (object) $update; | ||
if ($this->update_exists($update->id) === 0) { | ||
$result = $this->db->query($update->query); | ||
if ($result) { | ||
$this->db->insert('updates', [ | ||
'id' => $update->id, | ||
'description' => $update->description, | ||
]); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
function update_exists($id) { | ||
$this->db->from('updates'); | ||
$this->db->where('id', $id); | ||
return $this->db->get()->num_rows(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
<?php defined('BASEPATH') OR exit('No direct script access allowed'); | ||
$userID = $this->session->userdata("userID"); | ||
echo "<div class='button-bar'><span class='button new menu_item_add'>Add Menu Item</span></div>"; | ||
$current_menu = ""; | ||
foreach($menus as $menu){ | ||
|
||
if($current_menu != $menu->kMenu){ | ||
$current_menu = $menu->kMenu; | ||
|
||
echo "<h3>Menu: $menu->name</h3>"; | ||
} //endif | ||
echo "<div class='button-bar'><ul class='menu'>"; | ||
$button = create_button_object($menu,$userID); | ||
call_user_func('form_dropdown',eval("\$button = \"$button\";")); | ||
echo "<li>$button</li>"; | ||
echo "<li><span class='button edit menu_item_edit' id='mie_$menu->kItem'>Edit</span></li>"; | ||
echo "</ul></div>"; | ||
|
||
|
||
} //end foreach | ||
$userID = $this->session->userdata("userID");?> | ||
<div class='button-bar'><span class='button new menu_item_add'>Add Menu Item</span></div> | ||
<?php $current_menu = "";?> | ||
<?php foreach($menus as $menu):?> | ||
|
||
<?php if($current_menu != $menu->kMenu):?> | ||
<?php $current_menu = $menu->kMenu; ?> | ||
<h3>Menu: <?php print $menu->name;?></h3> | ||
<?php endif; ?> | ||
<div class='button-bar'><ul class='menu'> | ||
<?php $button = create_button_object($menu,$userID);?> | ||
<li><?php print $button;?></li> | ||
<li><a class="button edit" href="<?php print base_url('/menu/edit_item/' . $menu->kItem);?>" id='mie_$menu->kItem'>Edit</a></li> | ||
</ul></div> | ||
<?php endforeach; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters